Class: Spree::Kashflow::CustomerPayload

Inherits:
Object
  • Object
show all
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 EC VAT-treatment flag. The United Kingdom is deliberately absent: post-Brexit it is neither EU nor "outside" for KashFlow's purposes.

Returns:

  • (Array<String>)

    ISO 3166-1 alpha-2 codes of EU member states, used to derive the EC VAT-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.

Returns:

  • (String)

    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 VATNumber to be included in the payload. Spree has no dedicated VAT number column, so this gem reads it out of order.metadata under this key.

Returns:

  • (String)

    the order metadata key a host application must write for VATNumber to be included in the payload. Spree has no dedicated VAT number column, so this gem reads it out of order.metadata under this key.

"vat_number"

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ CustomerPayload

Returns a new instance of CustomerPayload.

Parameters:

  • order (Spree::Order)

    a completed order with a billing address



29
30
31
# File 'app/presenters/spree/kashflow/customer_payload.rb', line 29

def initialize(order)
  @order = order
end

Instance Method Details

#to_hHash{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.

Returns:

  • (Hash{String => Object})

    a KashFlow Customer structure keyed by the WSDL field names, ready to hand to KashFlow's customer-upsert operation



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