Class: BreadMachine::SecureTrading::St3dAuthRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/breadmachine/secure_trading/st_3d_auth_request.rb

Instance Method Summary collapse

Constructor Details

#initialize(amount, card, customer_info, order_info, three_d_secure, settlement_day) ⇒ St3dAuthRequest

A 3-D Secure auth reqeust to ask XPay to reserve funds at an acquiring bank, checking whether this card has funds available to cover the given amount.

Although XPay doesn’t absolutely require all of the order information etc., BreadMachine does as it’s better for history tracking and is strongly recommended by XPay.

settlement_day allows you to tell XPay when the auth request should be queued for settlement. The default, 1 day, will automatically tell SecureTrading to settle the amount on the day after the auth request. Note that even if you pass nil to settlement_day, the standard behaviour of XPay is to queue the auth request for settlement 1 day after the auth request. Passing a settlement_day of 0 will tell XPay not to settle without manual intervention.

Raises:

  • (ArgumentError)


22
23
24
25
26
27
28
29
30
31
# File 'lib/breadmachine/secure_trading/st_3d_auth_request.rb', line 22

def initialize(amount, card, customer_info, order_info, three_d_secure, settlement_day)
  raise ArgumentError, 'Currency mismatch' unless amount.currency == BreadMachine::SecureTrading::configuration.currency

  @amount = amount
  @card = BreadMachine::SecureTrading::CardXml.new(card)
  @customer_info = BreadMachine::SecureTrading::CustomerInfoAuthXml.new(customer_info)
  @order_info = BreadMachine::SecureTrading::OrderInfoXml.new(order_info)
  @three_d_secure = BreadMachine::SecureTrading::ThreeDSecureCredentialsXml.new(three_d_secure)
  @settlement_day = settlement_day
end

Instance Method Details

#response(xml) ⇒ Object

The specific response for this request to the XPay daemon.



35
36
37
# File 'lib/breadmachine/secure_trading/st_3d_auth_request.rb', line 35

def response(xml)
  St3dAuthResponse.new(xml)
end

#to_xmlObject

Generate the expected XML for this XPay request.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/breadmachine/secure_trading/st_3d_auth_request.rb', line 41

def to_xml
  xml = Builder::XmlMarkup.new(:indent => 2)
  xml.Request("Type" => "ST3DAUTH") {
    xml.Operation {
      xml.Amount @amount.cents
      xml.Currency BreadMachine::SecureTrading::configuration.currency
      xml.SiteReference BreadMachine::SecureTrading::configuration.site_reference
      xml.SettlementDay @settlement_day
    }
    xml << @customer_info.to_xml
    xml.PaymentMethod {
      xml << @card.to_xml
      xml << @three_d_secure.to_xml
    }
    xml << @order_info.to_xml
  }
end