Class: Spree::Kashflow::CreditNotePayload

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/spree/kashflow/credit_note_payload.rb

Overview

Maps a Spree refund onto the shape KashFlow's Invoice complex type expects. KashFlow has no InsertCreditNote operation: a credit note is an invoice with negative values, posted through the same InsertInvoice_TypeDefined path and then linked to the invoice it credits via applyCreditNoteToInvoice (Task 7's job, not this class's — this class only carries the original invoice number through CustomerReference so that call can be made).

A refund equal to the order's total produces a full negative mirror of the invoice's lines, built by delegating to InvoicePayload#to_h so the credit note inherits that class's reconciliation guard rather than bypassing it. A partial refund produces a single negative line for the refunded amount: Spree carries no information tying a partial refund back to specific line items or VAT rates, so no apportionment across the original lines is attempted. Instead, VAT on that single line is approximated at the order's blended rate (order.included_tax_total / (order.total - order.included_tax_total)) — a deliberate simplification, not a derivation from the refunded item(s), since Spree does not expose which items a partial refund was for.

Pure object: reads the refund and its associations, performs no network calls, and writes nothing back to Spree.

Constant Summary collapse

INVOICE_NUMBER_METAFIELD_KEY =

Returns the order metafield key this gem reads the original KashFlow invoice number from.

Returns:

  • (String)

    the order metafield key this gem reads the original KashFlow invoice number from

Spree::Kashflow::Metafields::ORDER_INVOICE_NUMBER

Instance Method Summary collapse

Constructor Details

#initialize(refund, integration:) ⇒ CreditNotePayload

Returns a new instance of CreditNotePayload.

Parameters:

  • refund (Spree::Refund)

    the refund to post as a KashFlow credit note

  • integration (Spree::Integrations::Kashflow)

    the integration whose nominal codes decide which ledger accounts a partial-refund line posts to



38
39
40
41
# File 'app/presenters/spree/kashflow/credit_note_payload.rb', line 38

def initialize(refund, integration:)
  @refund = refund
  @integration = integration
end

Instance Method Details

#to_hHash{String => Object}

Returns a KashFlow Invoice structure with negative values, ready to hand to KashFlow's invoice-insert operation.

Returns:

  • (Hash{String => Object})

    a KashFlow Invoice structure with negative values, ready to hand to KashFlow's invoice-insert operation

Raises:



50
51
52
# File 'app/presenters/spree/kashflow/credit_note_payload.rb', line 50

def to_h
  full_refund? ? full_refund_to_h : partial_refund_to_h
end