breadmachine 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -23,6 +23,7 @@ module BreadMachine
23
23
  autoload :St3dAuthResponse, 'breadmachine/secure_trading/st_3d_auth_response'
24
24
 
25
25
  autoload :AuthRequest, 'breadmachine/secure_trading/auth_request'
26
+ autoload :MotoAuthRequest, 'breadmachine/secure_trading/moto_auth_request'
26
27
 
27
28
  autoload :AuthReversalRequest, 'breadmachine/secure_trading/auth_reversal_request'
28
29
  autoload :AuthReversalResponse, 'breadmachine/secure_trading/auth_reversal_response'
@@ -0,0 +1,40 @@
1
+ module BreadMachine
2
+ module SecureTrading
3
+
4
+ class MotoAuthRequest
5
+
6
+ def initialize(amount, card, customer_info, order_info, settlement_day)
7
+ raise ArgumentError, 'Currency mismatch' unless amount.currency == BreadMachine::SecureTrading::configuration.currency
8
+
9
+ @amount = amount
10
+ @card = BreadMachine::SecureTrading::CardXml.new(card)
11
+ @customer_info = BreadMachine::SecureTrading::CustomerInfoAuthXml.new(customer_info)
12
+ @order_info = BreadMachine::SecureTrading::OrderInfoXml.new(order_info)
13
+ @settlement_day = settlement_day
14
+ end
15
+
16
+ def response(xml)
17
+ St3dAuthResponse.new(xml)
18
+ end
19
+
20
+ def to_xml
21
+ xml = Builder::XmlMarkup.new(:indent => 2)
22
+ xml.Request("Type" => "MOTOAUTH") {
23
+ xml.Operation {
24
+ xml.Amount @amount.cents
25
+ xml.Currency BreadMachine::SecureTrading::configuration.currency
26
+ xml.SiteReference BreadMachine::SecureTrading::configuration.site_reference
27
+ xml.SettlementDay @settlement_day
28
+ }
29
+ xml << @customer_info.to_xml
30
+ xml.PaymentMethod {
31
+ xml << @card.to_xml
32
+ }
33
+ xml << @order_info.to_xml
34
+ }
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+ end
@@ -9,9 +9,17 @@ module BreadMachine
9
9
  end
10
10
 
11
11
  def repeat_auth(*args)
12
- request = SecureTrading::AuthRequest.new(*args)
12
+ auth(*args)
13
+ end
14
+
15
+ def moto_auth(*args)
16
+ request = SecureTrading::MotoAuthRequest.new(*args)
13
17
  return SecureTrading::XPay.exchange(request)
14
18
  end
19
+
20
+ def repeat_moto_auth(*args)
21
+ moto_auth(*args)
22
+ end
15
23
 
16
24
  # Checks to see whether a card is enrolled in 3-D Secure. Returns a
17
25
  # ST3DCardQueryResponse which can tell us whether the card is enrolled
@@ -0,0 +1,63 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe BreadMachine::SecureTrading::MotoAuthRequest do
4
+
5
+ it "should ensure amount is Money of correct currency" do
6
+ BreadMachine::SecureTrading.configuration.currency = 'USD'
7
+ amount = Money.new(200_00, 'GBP')
8
+
9
+ lambda {
10
+ @request = described_class.new(amount, @card, @customer_info, @order_info, @settlement_day)
11
+ }.should raise_error ArgumentError, "Currency mismatch"
12
+ end
13
+
14
+ describe "XML generation" do
15
+
16
+ before(:each) do
17
+ BreadMachine::SecureTrading.configuration.currency = 'GBP'
18
+ @amount = Money.sterling(12_99)
19
+ @card = BreadMachine::Card.make
20
+ @customer_info = BreadMachine::CustomerInfo.make(:auth)
21
+ @order_info = BreadMachine::OrderInfo.make
22
+ @settlement_day = 1
23
+ @request = described_class.new(@amount, @card, @customer_info, @order_info, @settlement_day)
24
+ end
25
+
26
+ it "should set correct request type" do
27
+ request_xml.should have_tag("/Request[@Type='MOTOAUTH']")
28
+ end
29
+
30
+ it "should populate Operation element with correct data" do
31
+ BreadMachine::SecureTrading.configure do |config|
32
+ config.currency = 'GBP'
33
+ config.site_reference = 'site12345'
34
+ end
35
+ amount = Money.sterling(12_50)
36
+
37
+ @request = described_class.new(amount, @card, @customer_info, @order_info, settlement_day = 3)
38
+
39
+ request_xml.should have_tag("Operation") do |operation|
40
+ operation.document.should have_tag("Amount", "1250")
41
+ operation.document.should have_tag("Currency", "GBP")
42
+ operation.document.should have_tag("SiteReference", "site12345")
43
+ operation.document.should have_tag("SettlementDay", "3")
44
+ end
45
+ end
46
+
47
+ it "should append CustomerInfo element" do
48
+ request_xml.should have_tag("Request/CustomerInfo")
49
+ end
50
+
51
+ it "should append CreditCard element" do
52
+ request_xml.should have_tag("PaymentMethod/CreditCard")
53
+ end
54
+
55
+ it "should append Order element" do
56
+ request_xml.should have_tag("Order")
57
+ end
58
+
59
+ def request_xml
60
+ Nokogiri::XML::Document.parse(@request.to_xml)
61
+ end
62
+ end
63
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: breadmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Southerden
@@ -128,6 +128,7 @@ files:
128
128
  - lib/breadmachine/secure_trading/config.rb
129
129
  - lib/breadmachine/secure_trading/customer_info_auth_xml.rb
130
130
  - lib/breadmachine/secure_trading/customer_info_enrolment_xml.rb
131
+ - lib/breadmachine/secure_trading/moto_auth_request.rb
131
132
  - lib/breadmachine/secure_trading/order_info_xml.rb
132
133
  - lib/breadmachine/secure_trading/payment_methods.rb
133
134
  - lib/breadmachine/secure_trading/st_3d_auth_request.rb
@@ -178,6 +179,7 @@ test_files:
178
179
  - spec/secure_trading/config_spec.rb
179
180
  - spec/secure_trading/customer_info_auth_xml_spec.rb
180
181
  - spec/secure_trading/customer_info_enrolment_xml_spec.rb
182
+ - spec/secure_trading/moto_auth_request_spec.rb
181
183
  - spec/secure_trading/order_info_xml_spec.rb
182
184
  - spec/secure_trading/st_3d_auth_request_spec.rb
183
185
  - spec/secure_trading/st_3d_auth_response_spec.rb