Class: SpreeAvataxOfficial::Transactions::AmountRefundPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree_avatax_official/transactions/amount_refund_presenter.rb

Instance Method Summary collapse

Constructor Details

#initialize(order:, amount:, transaction_code:) ⇒ AmountRefundPresenter

Returns a new instance of AmountRefundPresenter.



4
5
6
7
8
# File 'app/presenters/spree_avatax_official/transactions/amount_refund_presenter.rb', line 4

def initialize(order:, amount:, transaction_code:)
  @order            = order
  @amount           = amount.to_d
  @transaction_code = transaction_code
end

Instance Method Details

#to_jsonObject

Based on: developer.avalara.com/api-reference/avatax/rest/v2/models/RefundTransactionModel/

Avalara distributes refundPercentage across every line of the original committed SalesInvoice. That preserves each line’s taxCode, addresses, and tax category in the resulting ReturnInvoice, and Avalara automatically applies the original sale’s tax date.



16
17
18
19
20
21
22
23
24
# File 'app/presenters/spree_avatax_official/transactions/amount_refund_presenter.rb', line 16

def to_json
  {
    refundTransactionCode: transaction_code,
    referenceCode:         order.number,
    refundDate:            Time.current.strftime('%Y-%m-%d'),
    refundType:            'Percentage',
    refundPercentage:      refund_percentage
  }
end