Class: Spree::Kashflow::CustomerPayload
- Inherits:
-
Object
- Object
- Spree::Kashflow::CustomerPayload
- Defined in:
- app/presenters/spree/kashflow/customer_payload.rb
Overview
Maps a Spree order's billing details onto the shape KashFlow's Customer
complex type expects. Pure object: reads the order and its associations, performs
no network calls, and writes nothing back to Spree.
Constant Summary collapse
- EU_COUNTRY_CODES =
Returns ISO 3166-1 alpha-2 codes of EU member states, used to derive the
ECVAT-treatment flag. The United Kingdom is deliberately absent: post-Brexit it is neither EU nor "outside" for KashFlow's purposes. %w[ AT BE BG HR CY CZ DK EE FI FR DE GR HU IE IT LV LT LU MT NL PL PT RO SK SI ES SE ].freeze
- UNITED_KINGDOM_CODE =
Returns the ISO 3166-1 alpha-2 code KashFlow treats as the United Kingdom.
"GB"- VAT_NUMBER_METADATA_KEY =
Returns the order metadata key a host application must write for
VATNumberto be included in the payload. Spree has no dedicated VAT number column, so this gem reads it out oforder.metadataunder this key. "vat_number"
Instance Method Summary collapse
-
#initialize(order) ⇒ CustomerPayload
constructor
A new instance of CustomerPayload.
-
#to_h ⇒ Hash{String => Object}
Keys are emitted in the WSDL
Customer<s:sequence>'s relative order —… Address4, CountryName, CountryCode, Postcode, Website, EC, OutsideEC, … ContactFirstName, ContactLastName, … VATNumber.
Constructor Details
#initialize(order) ⇒ CustomerPayload
Returns a new instance of CustomerPayload.
29 30 31 |
# File 'app/presenters/spree/kashflow/customer_payload.rb', line 29 def initialize(order) @order = order end |
Instance Method Details
#to_h ⇒ Hash{String => Object}
Keys are emitted in the WSDL Customer <s:sequence>'s relative order —
… Address4, CountryName, CountryCode, Postcode, Website, EC, OutsideEC, … ContactFirstName, ContactLastName, … VATNumber. Savon serialises a
Hash body in insertion order, and a .NET ASMX endpoint enforcing that
sequence drops or mis-binds an out-of-order element rather than raising,
so the order of these keys is load-bearing, not cosmetic.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'app/presenters/spree/kashflow/customer_payload.rb', line 44 def to_h payload = { "Code" => order.email, "Name" => customer_name, "Email" => order.email, "Address1" => bill_address&.address1, "Address2" => bill_address&.address2, "Address3" => bill_address&.city, "Address4" => bill_address&.state_name_text, "CountryCode" => billing_country_code, "Postcode" => bill_address&.zipcode, "EC" => ec_flag, "OutsideEC" => outside_ec_flag, "ContactFirstName" => bill_address&.firstname, "ContactLastName" => bill_address&.lastname } payload["VATNumber"] = vat_number if vat_number.present? payload end |