breadmachine 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +18 -0
- data/lib/breadmachine/dto/card.rb +22 -0
- data/lib/breadmachine/dto/customer_info.rb +16 -0
- data/lib/breadmachine/dto/order_info.rb +13 -0
- data/lib/breadmachine/dto/three_d_secure_credentials.rb +13 -0
- data/lib/breadmachine/extensions/money.rb +9 -0
- data/lib/breadmachine/extensions.rb +1 -0
- data/lib/breadmachine/secure_trading/auth_request.rb +38 -0
- data/lib/breadmachine/secure_trading/auth_reversal_request.rb +36 -0
- data/lib/breadmachine/secure_trading/auth_reversal_response.rb +6 -0
- data/lib/breadmachine/secure_trading/card_xml.rb +23 -0
- data/lib/breadmachine/secure_trading/config.rb +21 -0
- data/lib/breadmachine/secure_trading/customer_info_auth_xml.rb +40 -0
- data/lib/breadmachine/secure_trading/customer_info_enrolment_xml.rb +21 -0
- data/lib/breadmachine/secure_trading/order_info_xml.rb +21 -0
- data/lib/breadmachine/secure_trading/payment_methods.rb +28 -0
- data/lib/breadmachine/secure_trading/st_3d_auth_request.rb +41 -0
- data/lib/breadmachine/secure_trading/st_3d_auth_response.rb +25 -0
- data/lib/breadmachine/secure_trading/st_3d_card_query_request.rb +37 -0
- data/lib/breadmachine/secure_trading/st_3d_card_query_response.rb +46 -0
- data/lib/breadmachine/secure_trading/three_d_secure_credentials_xml.rb +23 -0
- data/lib/breadmachine/secure_trading/xpay.rb +25 -0
- data/lib/breadmachine/secure_trading/xpay_socket.rb +22 -0
- data/lib/breadmachine/secure_trading.rb +32 -0
- data/lib/breadmachine.rb +27 -0
- data/spec/blueprints.rb +38 -0
- data/spec/breadmachine_spec.rb +5 -0
- data/spec/extensions/money_spec.rb +24 -0
- data/spec/secure_trading/auth_request_spec.rb +58 -0
- data/spec/secure_trading/bread_machine_spec.rb +16 -0
- data/spec/secure_trading/card_xml_spec.rb +56 -0
- data/spec/secure_trading/config_spec.rb +12 -0
- data/spec/secure_trading/customer_info_auth_xml_spec.rb +94 -0
- data/spec/secure_trading/customer_info_enrolment_xml_spec.rb +31 -0
- data/spec/secure_trading/order_info_xml_spec.rb +31 -0
- data/spec/secure_trading/st_3d_auth_request_spec.rb +63 -0
- data/spec/secure_trading/st_3d_auth_response_spec.rb +5 -0
- data/spec/secure_trading/st_3d_card_query_request_spec.rb +63 -0
- data/spec/secure_trading/st_3d_card_query_response_spec.rb +79 -0
- data/spec/secure_trading/st_auth_request_spec.rb +0 -0
- data/spec/secure_trading/st_auth_reversal_request_spec.rb +0 -0
- data/spec/secure_trading/st_refund_request_spec.rb +0 -0
- data/spec/secure_trading/st_refund_reversal_request_spec.rb +0 -0
- data/spec/secure_trading/st_settlement_request_spec.rb +0 -0
- data/spec/secure_trading/three_d_secure_credentials_xml_spec.rb +42 -0
- data/spec/secure_trading/xpay_socket_spec.rb +14 -0
- data/spec/secure_trading/xpay_spec.rb +9 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/matchers/have_tag.rb +112 -0
- metadata +163 -0
data/spec/blueprints.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'machinist/object'
|
2
|
+
|
3
|
+
BreadMachine::Card.blueprint do
|
4
|
+
issuer { 'Visa' }
|
5
|
+
number { 4111111111111111 }
|
6
|
+
expiry_date { Date.today.strftime("%m/%y") }
|
7
|
+
end
|
8
|
+
|
9
|
+
BreadMachine::CustomerInfo.blueprint {}
|
10
|
+
|
11
|
+
BreadMachine::CustomerInfo.blueprint(:card_query) do
|
12
|
+
accept { "text/html" }
|
13
|
+
user_agent { "Mozilla/5.0" }
|
14
|
+
end
|
15
|
+
|
16
|
+
BreadMachine::CustomerInfo.blueprint(:auth) do
|
17
|
+
first_name { "Joe"}
|
18
|
+
last_name { "Bloggs" }
|
19
|
+
street { "29 Acacia Road" }
|
20
|
+
city { "London" }
|
21
|
+
state { "Greater London" }
|
22
|
+
postcode { "W1T 2DQ" }
|
23
|
+
iso_2_country { "GB" }
|
24
|
+
telephone { "020 7323 9787" }
|
25
|
+
email { "nobody@example.com" }
|
26
|
+
end
|
27
|
+
|
28
|
+
BreadMachine::ThreeDSecureCredentials.blueprint do
|
29
|
+
transaction_reference { '13-3-4312345' }
|
30
|
+
enrolled { "Y" }
|
31
|
+
pa_res { "PA-RES" }
|
32
|
+
md { "MD" }
|
33
|
+
end
|
34
|
+
|
35
|
+
BreadMachine::OrderInfo.blueprint do
|
36
|
+
order_reference { "TestOrder12345" }
|
37
|
+
order_information { "1x Assorted Widgets" }
|
38
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Money do
|
4
|
+
|
5
|
+
describe "sterling" do
|
6
|
+
|
7
|
+
it "should create Money (if only!)" do
|
8
|
+
tenner = Money.sterling(10_00)
|
9
|
+
tenner.should be_instance_of(Money)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should create new Money with currency of GBP" do
|
13
|
+
tenner = Money.sterling(10_00)
|
14
|
+
tenner.currency.should == "GBP"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create Money with correct value" do
|
18
|
+
tenner = Money.sterling(10_00)
|
19
|
+
tenner.cents.should == 1000
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::AuthRequest do
|
4
|
+
|
5
|
+
it "should validate input data when initialized"
|
6
|
+
|
7
|
+
describe "XML generation" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@amount = Money.sterling(12_99)
|
11
|
+
@card = BreadMachine::Card.make
|
12
|
+
@customer_info = BreadMachine::CustomerInfo.make(:auth)
|
13
|
+
@order_info = BreadMachine::OrderInfo.make
|
14
|
+
@request = described_class.new(@amount, @card, @customer_info, @order_info)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set correct request type" do
|
18
|
+
request_xml.should have_tag("/Request[@Type='AUTH']")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should populate Operation element with correct data" do
|
22
|
+
BreadMachine::SecureTrading.configure do |config|
|
23
|
+
config.currency = 'GBP'
|
24
|
+
config.site_reference = 'site12345'
|
25
|
+
end
|
26
|
+
amount = Money.sterling(12_50)
|
27
|
+
|
28
|
+
@request = described_class.new(amount, @card, @customer_info, @order_info, settlement_day = 3)
|
29
|
+
|
30
|
+
request_xml.should have_tag("Operation") do |operation|
|
31
|
+
operation.document.should have_tag("Amount", "1250")
|
32
|
+
operation.document.should have_tag("Currency", "GBP")
|
33
|
+
operation.document.should have_tag("SiteReference", "site12345")
|
34
|
+
operation.document.should have_tag("SettlementDay", "3")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should ensure amount is Money of correct currency" do
|
39
|
+
pending "Check that currency of amount matches currency specified in config"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should append CustomerInfo element" do
|
43
|
+
request_xml.should have_tag("Request/CustomerInfo")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should append CreditCard element" do
|
47
|
+
request_xml.should have_tag("PaymentMethod/CreditCard")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should append Order element" do
|
51
|
+
request_xml.should have_tag("Order")
|
52
|
+
end
|
53
|
+
|
54
|
+
def request_xml
|
55
|
+
Nokogiri::XML::Document.parse(@request.to_xml)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine do
|
4
|
+
|
5
|
+
describe "performing a 3-D secure card enrollment check" do
|
6
|
+
|
7
|
+
it "should build a card query request" do
|
8
|
+
card = BreadMachine::Card.make
|
9
|
+
BreadMachine::SecureTrading::St3dCardQueryRequest.should_receive(:new).with(card)
|
10
|
+
BreadMachine::SecureTrading::XPay.stub(:exchange)
|
11
|
+
BreadMachine.three_d_secure_enrolled?(card)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
class TestCard
|
4
|
+
attr_accessor :issuer, :number, :expiry_date, :start_date, :issue, :security_code, :parent_transaction_reference
|
5
|
+
include BreadMachine::SecureTrading::CardXml
|
6
|
+
end
|
7
|
+
|
8
|
+
describe BreadMachine::SecureTrading::CardXml do
|
9
|
+
|
10
|
+
describe "xml representation generation" do
|
11
|
+
|
12
|
+
before(:each) do
|
13
|
+
@card = TestCard.new
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should have CreditCard root element" do
|
17
|
+
xml(@card).should have_tag('/CreditCard')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should have correct Type element" do
|
21
|
+
@card.issuer = 'Maestro'
|
22
|
+
xml(@card).should have_tag("CreditCard/Type", 'Maestro')
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have correct Number element" do
|
26
|
+
@card.number = 6759050000000005
|
27
|
+
xml(@card).should have_tag("CreditCard/Number", '6759050000000005')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have correct ExpiryDate element" do
|
31
|
+
@card.expiry_date = '07/11'
|
32
|
+
xml(@card).should have_tag("CreditCard/ExpiryDate", '07/11')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have correct StartDate element" do
|
36
|
+
@card.start_date = '03/08'
|
37
|
+
xml(@card).should have_tag("CreditCard/StartDate", '03/08')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have correct Issue element" do
|
41
|
+
@card.issue = 2
|
42
|
+
xml(@card).should have_tag("CreditCard/Issue", '2')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have correct SecurityCode element" do
|
46
|
+
@card.security_code = 789
|
47
|
+
xml(@card).should have_tag("CreditCard/SecurityCode", '789')
|
48
|
+
end
|
49
|
+
|
50
|
+
def xml(card)
|
51
|
+
Nokogiri::XML::Document.parse(card.to_xml)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::Config do
|
4
|
+
|
5
|
+
it "should set config from block" do
|
6
|
+
BreadMachine::SecureTrading.configure do |config|
|
7
|
+
config.currency = 'USD'
|
8
|
+
end
|
9
|
+
BreadMachine::SecureTrading.configuration.currency.should == 'USD'
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::CustomerInfoAuthXml do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@customer_info = BreadMachine::CustomerInfo.new
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
described_class.new(@customer_info)
|
11
|
+
end
|
12
|
+
|
13
|
+
def generated_xml
|
14
|
+
Nokogiri::XML::Document.parse(subject.to_xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have correct root element" do
|
18
|
+
generated_xml.should have_tag('/CustomerInfo')
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "postal details" do
|
22
|
+
|
23
|
+
describe "name elements" do
|
24
|
+
|
25
|
+
it "should have correct NamePrefix" do
|
26
|
+
@customer_info.name_prefix = 'Dr'
|
27
|
+
generated_xml.should have_tag('Postal/Name/NamePrefix', 'Dr')
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have correct FirstName" do
|
31
|
+
@customer_info.first_name = 'John'
|
32
|
+
generated_xml.should have_tag('Postal/Name/FirstName', 'John')
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should have correct MiddleName" do
|
36
|
+
@customer_info.middle_name = 'Jonny'
|
37
|
+
generated_xml.should have_tag('Postal/Name/MiddleName', 'Jonny')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "should have correct LastName" do
|
41
|
+
@customer_info.last_name = 'Johnson'
|
42
|
+
generated_xml.should have_tag('Postal/Name/LastName', 'Johnson')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should have correct NameSuffix" do
|
46
|
+
@customer_info.name_suffix = 'Esquire'
|
47
|
+
generated_xml.should have_tag('Postal/Name/NameSuffix', 'Esquire')
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should have correct Company" do
|
53
|
+
@customer_info.company = 'Widgets Inc.'
|
54
|
+
generated_xml.should have_tag('Postal/Company', 'Widgets Inc.')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have correct Street" do
|
58
|
+
@customer_info.street = '1A Juan Street'
|
59
|
+
generated_xml.should have_tag('Postal/Street', '1A Juan Street')
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should have correct City" do
|
63
|
+
@customer_info.city = 'London'
|
64
|
+
generated_xml.should have_tag('Postal/City', 'London')
|
65
|
+
end
|
66
|
+
|
67
|
+
it "should have correct StateProv" do
|
68
|
+
@customer_info.state = 'Greater London'
|
69
|
+
generated_xml.should have_tag('Postal/StateProv', 'Greater London')
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should have correct PostalCode" do
|
73
|
+
@customer_info.postcode = 'W1 4PH'
|
74
|
+
generated_xml.should have_tag('Postal/PostalCode', 'W1 4PH')
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have correct CountryCode" do
|
78
|
+
@customer_info.iso_2_country = 'GB'
|
79
|
+
generated_xml.should have_tag('Postal/CountryCode', 'GB')
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should have correct Phone" do
|
85
|
+
@customer_info.telephone = '020 8888 8888'
|
86
|
+
generated_xml.should have_tag('Telecom/Phone', '020 8888 8888')
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should have correct Email" do
|
90
|
+
@customer_info.email = 'john.jonny.johnson@example.com'
|
91
|
+
generated_xml.should have_tag('Online/Email', 'john.jonny.johnson@example.com')
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::CustomerInfoEnrolmentXml do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@customer_info = BreadMachine::CustomerInfo.new
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
described_class.new(@customer_info)
|
11
|
+
end
|
12
|
+
|
13
|
+
def generated_xml
|
14
|
+
Nokogiri::XML::Document.parse(subject.to_xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have correct root element" do
|
18
|
+
generated_xml.should have_tag('/CustomerInfo')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have correct Accept" do
|
22
|
+
@customer_info.accept = 'text/html'
|
23
|
+
generated_xml.should have_tag('CustomerInfo/Accept', 'text/html')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have correct UserAgent" do
|
27
|
+
@customer_info.user_agent = 'Internet Exploder 5.2'
|
28
|
+
generated_xml.should have_tag('CustomerInfo/UserAgent', 'Internet Exploder 5.2')
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::OrderInfoXml do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@order_info = BreadMachine::OrderInfo.new
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
described_class.new(@order_info)
|
11
|
+
end
|
12
|
+
|
13
|
+
def generated_xml
|
14
|
+
Nokogiri::XML::Document.parse(subject.to_xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have correct root element" do
|
18
|
+
generated_xml.should have_tag('/Order')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have correct Phone" do
|
22
|
+
@order_info.order_reference = 'Order 12345'
|
23
|
+
generated_xml.should have_tag('Order/OrderReference', 'Order 12345')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should have correct Email" do
|
27
|
+
@order_info.order_information = '1 Bag of Assorted Widgets'
|
28
|
+
generated_xml.should have_tag('Order/OrderInformation', '1 Bag of Assorted Widgets')
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::St3dAuthRequest do
|
4
|
+
|
5
|
+
it "should validate input data when initialized"
|
6
|
+
|
7
|
+
describe "XML generation" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@amount = Money.sterling(12_99)
|
11
|
+
@card = BreadMachine::Card.make
|
12
|
+
@customer_info = BreadMachine::CustomerInfo.make(:auth)
|
13
|
+
@order_info = BreadMachine::OrderInfo.make
|
14
|
+
@three_d = BreadMachine::ThreeDSecureCredentials.make
|
15
|
+
@request = described_class.new(@amount, @card, @customer_info, @order_info, @three_d)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should set correct request type" do
|
19
|
+
request_xml.should have_tag("/Request[@Type='ST3DAUTH']")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should populate Operation element with correct data" do
|
23
|
+
BreadMachine::SecureTrading.configure do |config|
|
24
|
+
config.currency = 'GBP'
|
25
|
+
config.site_reference = 'site12345'
|
26
|
+
end
|
27
|
+
amount = Money.sterling(200_00)
|
28
|
+
|
29
|
+
@request = described_class.new(amount, @card, @customer_info, @order_info, @three_d, settlement_day = 2)
|
30
|
+
|
31
|
+
request_xml.should have_tag("Operation") do |operation|
|
32
|
+
operation.document.should have_tag("Amount", "20000")
|
33
|
+
operation.document.should have_tag("Currency", "GBP")
|
34
|
+
operation.document.should have_tag("SiteReference", "site12345")
|
35
|
+
operation.document.should have_tag("SettlementDay", "2")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should ensure amount is Money of correct currency" do
|
40
|
+
pending "Check that currency of amount matches currency specified in config"
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should append CustomerInfo element" do
|
44
|
+
request_xml.should have_tag("Request/CustomerInfo")
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should append CreditCard element" do
|
48
|
+
request_xml.should have_tag("PaymentMethod/CreditCard")
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should append ThreeDSecure element" do
|
52
|
+
request_xml.should have_tag("PaymentMethod/ThreeDSecure")
|
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
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::St3dCardQueryRequest do
|
4
|
+
|
5
|
+
it "should validate input data when initialized"
|
6
|
+
|
7
|
+
context "XML generation" do
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@card = BreadMachine::Card.make
|
11
|
+
@customer_info = BreadMachine::CustomerInfo.make(:card_query)
|
12
|
+
@order_info = BreadMachine::OrderInfo.make
|
13
|
+
@amount = Money.sterling(12_99)
|
14
|
+
@request = described_class.new(@amount, @card, @customer_info, @order_info)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set correct request type" do
|
18
|
+
request_xml.should have_tag("/Request[@Type='ST3DCARDQUERY']")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should populate Operation element with correct data" do
|
22
|
+
BreadMachine::SecureTrading.configure do |config|
|
23
|
+
config.currency = 'USD'
|
24
|
+
config.site_reference = 'site12345'
|
25
|
+
config.term_url = 'http://www.example.com'
|
26
|
+
config.merchant_name = "Bob's Widgets Inc."
|
27
|
+
end
|
28
|
+
amount = Money.sterling(10_99)
|
29
|
+
|
30
|
+
@request = described_class.new(amount, @card, @customer_info, @order_info)
|
31
|
+
|
32
|
+
request_xml.should have_tag("Request/Operation")
|
33
|
+
|
34
|
+
request_xml.should have_tag("Operation/Amount", "1099")
|
35
|
+
request_xml.should have_tag("Operation/Currency", "USD")
|
36
|
+
request_xml.should have_tag("Operation/SiteReference", "site12345")
|
37
|
+
request_xml.should have_tag("Operation/TermUrl", "http://www.example.com")
|
38
|
+
request_xml.should have_tag("Operation/MerchantName", "Bob's Widgets Inc.")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should append CustomerInfo element" do
|
42
|
+
request_xml.should have_tag("Request/CustomerInfo")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should append PaymentMethod element" do
|
46
|
+
request_xml.should have_tag("Request/PaymentMethod")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should ensure amount is Money of correct currency" do
|
50
|
+
pending "Check that currency of amount matches currency specified in config"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should populate PaymentMethod element with correct data when querying from a previous ParentTransactionReference"
|
54
|
+
|
55
|
+
it "should append Order element" do
|
56
|
+
request_xml.should have_tag("Request/Order")
|
57
|
+
end
|
58
|
+
|
59
|
+
def request_xml
|
60
|
+
Nokogiri::XML::Document.parse(@request.to_xml)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::St3dCardQueryResponse do
|
4
|
+
|
5
|
+
it "should be successful when Success element is 1" do
|
6
|
+
# TODO: this should probably be pushed up into a generic Response
|
7
|
+
@response = described_class.new(successful_response)
|
8
|
+
@response.should be_successful
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not be successful when Success element is 0" do
|
12
|
+
# TODO: this should probably be pushed up into a generic Response
|
13
|
+
@response = described_class.new(failed_response)
|
14
|
+
@response.should_not be_successful
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should select PaReq" do
|
18
|
+
@response = described_class.new(successful_response)
|
19
|
+
@response.pa_req.should == "EXAMPLE-PA-REQ"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should select MD" do
|
23
|
+
@response = described_class.new(successful_response)
|
24
|
+
@response.md.should == "EXAMPLE-MD"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should select AcsUrl" do
|
28
|
+
@response = described_class.new(successful_response)
|
29
|
+
@response.acs_url.should == "https://securetrading.net/secureweb/testacs0.cgi"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should select TranscationReference" do
|
33
|
+
@response = described_class.new(successful_response)
|
34
|
+
@response.transaction_reference.should == "15-9-1266891"
|
35
|
+
end
|
36
|
+
|
37
|
+
def successful_response
|
38
|
+
enrolled_response
|
39
|
+
end
|
40
|
+
|
41
|
+
def enrolled_response
|
42
|
+
<<-EOS
|
43
|
+
<ResponseBlock Live="FALSE" Version="3.51">
|
44
|
+
<Response Type="ST3DCARDQUERY">
|
45
|
+
<OperationResponse>
|
46
|
+
<TransactionReference>15-9-1266891</TransactionReference>
|
47
|
+
<TransactionCompletedTimestamp>2009-09-24 14:50:41</TransactionCompletedTimestamp>
|
48
|
+
<TransactionVerifier>AY4LBwreQ1qwbPpuH5PswO4eN7KD27qmNBLG03tCrhBSzLpRXKBXw+PwY7dcuzuGoQXAPVB7phZYZhcP8YcBy9LFXO8zRW02QaHhXXykY7+ekmsYdNGEYjeLE8wI2vUGpD9IrGySGgYQySq1zIFg1wtUg4LmyrlAlUyQUOvPof8c=</TransactionVerifier>
|
49
|
+
<Result>1</Result>
|
50
|
+
<Enrolled>Y</Enrolled>
|
51
|
+
<Html></Html>
|
52
|
+
<MD>EXAMPLE-MD</MD>
|
53
|
+
<PaReq>EXAMPLE-PA-REQ</PaReq>
|
54
|
+
<TermUrl>http://www.example.com</TermUrl>
|
55
|
+
<AcsUrl>https://securetrading.net/secureweb/testacs0.cgi</AcsUrl>
|
56
|
+
</OperationResponse>
|
57
|
+
<Order>
|
58
|
+
<OrderInformation>1x Assorted Widgets</OrderInformation>
|
59
|
+
<OrderReference>TestOrder12345</OrderReference>
|
60
|
+
</Order>
|
61
|
+
</Response>
|
62
|
+
</ResponseBlock>
|
63
|
+
EOS
|
64
|
+
end
|
65
|
+
|
66
|
+
def failed_response
|
67
|
+
<<-EOS
|
68
|
+
<ResponseBlock Live="" Version="3.51">
|
69
|
+
<Response Type="ST3DCARDQUERY">
|
70
|
+
<OperationResponse>
|
71
|
+
<Message>(3100) Invalid CreditCardNumber</Message>
|
72
|
+
<TransactionReference>0-0-0</TransactionReference>
|
73
|
+
<Result>0</Result>
|
74
|
+
</OperationResponse>
|
75
|
+
</Response>
|
76
|
+
</ResponseBlock>
|
77
|
+
EOS
|
78
|
+
end
|
79
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::ThreeDSecureCredentialsXml do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@credentials = BreadMachine::ThreeDSecureCredentials.new
|
7
|
+
end
|
8
|
+
|
9
|
+
subject do
|
10
|
+
described_class.new(@credentials)
|
11
|
+
end
|
12
|
+
|
13
|
+
def generated_xml
|
14
|
+
Nokogiri::XML::Document.parse(subject.to_xml)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should have correct root element" do
|
18
|
+
generated_xml.should have_tag('/ThreeDSecure')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should correctly populate Enrolled element" do
|
22
|
+
@credentials.enrolled = 'Y'
|
23
|
+
generated_xml.should have_tag('ThreeDSecure/Enrolled', 'Y')
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should correctly populate PaRes element" do
|
27
|
+
@credentials.pa_res = 'A_PA_RES_VALUE'
|
28
|
+
generated_xml.should have_tag('ThreeDSecure/PaRes', 'A_PA_RES_VALUE')
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should correctly populate MD element" do
|
32
|
+
@credentials.md = 'A_MD_VALUE'
|
33
|
+
generated_xml.should have_tag('ThreeDSecure/MD', 'A_MD_VALUE')
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should correctly populate TransactionReference element" do
|
37
|
+
@credentials.transaction_reference = '121-43-422344'
|
38
|
+
generated_xml.should have_tag('ThreeDSecure/TransactionReference', '121-43-422344')
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe BreadMachine::SecureTrading::XPaySocket do
|
4
|
+
|
5
|
+
it "should open TCPSocket connection with correct host" do
|
6
|
+
TCPSocket.should_receive(:open).with("localhost", 5000)
|
7
|
+
BreadMachine::SecureTrading::XPaySocket.open("localhost", 5000)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should pass block to the socket" do
|
11
|
+
pending "Not sure how to test this??"
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|