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"- USER_CODE_FORMAT =
Returns format for a registered user's code, keyed on the Spree user id so it survives the customer changing their email address.
"SPU%d"- GUEST_CODE_FORMAT =
Returns format for a guest's code. Guests have no stable id, so the normalised email is hashed — same email in, same code out, which is what keeps the upsert an update rather than a duplicate.
"SPG%s"- GUEST_CODE_DIGEST_LENGTH =
Returns hex characters of the email digest kept in a guest code. 12 hex chars is 48 bits: collision-safe at any plausible customer count while leaving the total code short.
12- CODE_MAX_LENGTH =
Returns the longest code this presenter will emit. KashFlow does not publish the limit in the WSDL; this is a conservative ceiling that both formats stay well inside.
20
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.
65 66 67 |
# File 'app/presenters/spree/kashflow/customer_payload.rb', line 65 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.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/presenters/spree/kashflow/customer_payload.rb', line 80 def to_h payload = { "Code" => customer_code, "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 |