xpay 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ <ResponseBlock Live='FALSE' Version='3.51'>
2
+ <Response Type='ST3DCARDQUERY'>
3
+ <OperationResponse>
4
+ <TransactionReference>17-9-1909368</TransactionReference>
5
+ <TransactionCompletedTimestamp>2010-10-25 11:37:16</TransactionCompletedTimestamp>
6
+ <TransactionVerifier>ArOH5um+qGhwLbuobJ5mdgzTr1qclm1j/qyG+VGDe9QSslGFXtwFA2A6jvM+qgUuZ0lLQPvJ82U1SkLOhm32dPRABlh0EkyrvKamrsDDRcsFZhWQLmS+yE0+keSaBq8C537NQAXIYcCYVvoOVKhDwdW4hZVfOtKFND+QxR2p89rw=</TransactionVerifier>
7
+ <Result>1</Result>
8
+ <Enrolled>Y</Enrolled>
9
+ <Html>&lt;!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01//EN'>
10
+ &lt;HTML>&lt;HEAD>&lt;TITLE>Redirecting...&lt;/TITLE>&lt;META http-equiv='Content-Type' content='text/html; charset=utf-8'>&lt;/HEAD>
11
+ &lt;BODY onload="setTimeout('document.form.submit()','500')">
12
+ &lt;H2>If you are not redirected automatically please click to continue&lt;/H2>
13
+ &lt;FORM name='form' id='form' METHOD='POST' ACTION='https://securetrading.net/secureweb/testacs0.cgi'>
14
+ &lt;P>&lt;INPUT type='hidden' name='PaReq' value='eJxVUstyAiEQvOcrLO86gK81NVJl4iEefJTJDxB2yl2zsgpsYvz6wLqbGC50z0DTNOBbZokWr6Qr
15
+ SxJX5JzaUydPZ93tfEfnHueciel0MEmmY9HrCZYkYjJijHcl1iskfpJ1eWkk77O+QGhpELM6U8ZL
16
+ VPr8tFxLLgbD0RihoXgku1w01UnCbgPhVkajjiQ3lS/Id3bk8pSMz1WBUDdQl5Xx9lsmIii2BCtb
17
+ yMz7k3sEKEqtiqx0HgZpQMW70h8IcQXCn7dtFZELipc8lZvFfrg+zK/r6/5rdVjNHhBiGVPlSfqM
18
+ OhEg1BTVMR4ree26IXiKevP7zn0FQ86WjG59twzpcipNuKEMCf5iTMnp4LaZ/qw+v8RQtQ85Dfn9
19
+ GEcnt0aUzEMmnHFea0aCELdC83LQvHdA//7BDz/HrvY=
20
+ '>
21
+ &lt;INPUT type='hidden' name='TermUrl' value='https://localhost/3dcallback'>
22
+ &lt;INPUT type='hidden' name='MD' value='MTI4ODAwNjYzNi41MjAuMTc2MzczMzc3MDExMjg4MDA2NjM2LjUyMC4xNzYzNzMzNzcwMTEyODgwMDY2MzYuNTIwLjE3NjM3MzM3NzAxMTI4ODAwNjYzNi41MjAuMTc2MzczMzc3MDExMjg4MDA2NjM2LjUyMC4xNzYzNzMzNzcwMTEyODgwMDY2MzYuNTIwLjE3NjM3MzM3NzAxMTI4ODAwNjYzNi41MjAuMTc2MzczMzc3MDExMjg4MDA2NjM2LjUyMC4xNzYzNzMzNzcwMTEyODgwMDY2MzYuNTIwLjE3NjM3MzM3NzAxMTI4ODAwNjYzNi41MjAuMTc2MzczMzc3MDE='>
23
+ &lt;INPUT TYPE='submit' VALUE=' Continue ' SIZE='30'>
24
+ &lt;/P>&lt;/FORM>&lt;/BODY>&lt;/HTML></Html>
25
+ <MD>MTI4ODAwNjYzNi41MjAuMTc2MzczMzc3MDExMjg4MDA2NjM2LjUyMC4xNzYzNzMzNzcwMTEyODgwMDY2MzYuNTIwLjE3NjM3MzM3NzAxMTI4ODAwNjYzNi41MjAuMTc2MzczMzc3MDExMjg4MDA2NjM2LjUyMC4xNzYzNzMzNzcwMTEyODgwMDY2MzYuNTIwLjE3NjM3MzM3NzAxMTI4ODAwNjYzNi41MjAuMTc2MzczMzc3MDExMjg4MDA2NjM2LjUyMC4xNzYzNzMzNzcwMTEyODgwMDY2MzYuNTIwLjE3NjM3MzM3NzAxMTI4ODAwNjYzNi41MjAuMTc2MzczMzc3MDE=</MD>
26
+ <PaReq>eJxVUstyAiEQvOcrLO86gK81NVJl4iEefJTJDxB2yl2zsgpsYvz6wLqbGC50z0DTNOBbZokWr6Qr
27
+ SxJX5JzaUydPZ93tfEfnHueciel0MEmmY9HrCZYkYjJijHcl1iskfpJ1eWkk77O+QGhpELM6U8ZL
28
+ VPr8tFxLLgbD0RihoXgku1w01UnCbgPhVkajjiQ3lS/Id3bk8pSMz1WBUDdQl5Xx9lsmIii2BCtb
29
+ yMz7k3sEKEqtiqx0HgZpQMW70h8IcQXCn7dtFZELipc8lZvFfrg+zK/r6/5rdVjNHhBiGVPlSfqM
30
+ OhEg1BTVMR4ree26IXiKevP7zn0FQ86WjG59twzpcipNuKEMCf5iTMnp4LaZ/qw+v8RQtQ85Dfn9
31
+ GEcnt0aUzEMmnHFea0aCELdC83LQvHdA//7BDz/HrvY=
32
+ </PaReq>
33
+ <TermUrl>https://localhost/3dcallback</TermUrl>
34
+ <AcsUrl>https://securetrading.net/secureweb/testacs0.cgi</AcsUrl>
35
+ </OperationResponse>
36
+ <Order>
37
+ <OrderReference>TestOrder1245</OrderReference>
38
+ </Order>
39
+ </Response>
40
+ </ResponseBlock>
@@ -0,0 +1 @@
1
+ <?xml version='1.0' encoding='ISO-8859-1'?><RequestBlock Version='3.51'><Request Type='ST3DCARDQUERY'><Operation><SiteReference>site12345</SiteReference></Operation></Request><Certificate>site12345</Certificate></RequestBlock>
@@ -0,0 +1,21 @@
1
+ default:
2
+ merchant_name: CompanyName
3
+ version: "3.51"
4
+ alias: site12345
5
+ site_reference: site12345
6
+ port: 5000
7
+ callback_url: "http://localhost/gateway_callback"
8
+ default_query: "ST3DCARDQUERY"
9
+ settlement_day: "1"
10
+ default_currency: "GBP"
11
+
12
+ config_load_test:
13
+ merchant_name: Outlet Residential
14
+ alias: testoutlet12091
15
+ site_reference: testoutlet12091
16
+ version: "3.52"
17
+ port: 6000
18
+ callback_url: "http://127.0.0.1/callback"
19
+ default_query: "AUTH"
20
+ settlement_day: "2"
21
+ default_currency: "USD"
@@ -0,0 +1,84 @@
1
+ require 'test_helper'
2
+ require 'xpay'
3
+
4
+ class PaymentFunctionTest < Test::Unit::TestCase
5
+ context "with rightly formed request" do
6
+ context "a visa succesful no 3D payment" do
7
+ setup do
8
+ options = {:creditcard => Xpay::CreditCard.new(credit_card("visa_no3d_auth")), :operation => Xpay::Operation.new(operation("test_1")), :customer => Xpay::Customer.new(customer("test_1"))}
9
+ @p = Xpay::Payment.new(options)
10
+ Xpay.config.port = 5000
11
+ end
12
+ should "return 1 on make_payment" do
13
+ rt = @p.make_payment
14
+ assert_equal 1, rt
15
+ end
16
+ end
17
+
18
+ context "a visa unsuccesful no 3D payment" do
19
+ setup do
20
+ options = {:creditcard => Xpay::CreditCard.new(credit_card("visa_no3d_decl")), :operation => Xpay::Operation.new(operation("test_1")), :customer => Xpay::Customer.new(customer("test_1"))}
21
+ @p2 = Xpay::Payment.new(options)
22
+ Xpay.config.port = 5000
23
+ end
24
+ should "return 0 on make_payment" do
25
+ rt = @p2.make_payment
26
+ assert_equal 2, rt
27
+ end
28
+ end
29
+
30
+ context "a mastercard succesful no 3D payment" do
31
+ setup do
32
+ options = {:creditcard => Xpay::CreditCard.new(credit_card("master_no3d_auth")), :operation => Xpay::Operation.new(operation("test_1")), :customer => Xpay::Customer.new(customer("test_1"))}
33
+ @p = Xpay::Payment.new(options)
34
+ Xpay.config.port = 5000
35
+ end
36
+ should "return 1 on make_payment" do
37
+ rt = @p.make_payment
38
+ assert_equal 1, rt
39
+ end
40
+ end
41
+
42
+ context "an mastercard unsuccesful no 3D payment" do
43
+ setup do
44
+ options = {:creditcard => Xpay::CreditCard.new(credit_card("master_no3d_decl")), :operation => Xpay::Operation.new(operation("test_1")), :customer => Xpay::Customer.new(customer("test_1"))}
45
+ @p2 = Xpay::Payment.new(options)
46
+ Xpay.config.port = 5000
47
+ end
48
+ should "return 0 on make_payment" do
49
+ rt = @p2.make_payment
50
+ assert_equal 2, rt
51
+ end
52
+ end
53
+
54
+ context "an visa succesful 3D payment" do
55
+ setup do
56
+ options = {:creditcard => Xpay::CreditCard.new(credit_card("visa_3d_auth")), :operation => Xpay::Operation.new(operation("test_1")), :customer => Xpay::Customer.new(customer("test_1"))}
57
+ @p = Xpay::Payment.new(options)
58
+ Xpay.config.port = 5000
59
+ end
60
+ should "return -1 on make_payment" do
61
+ rt = @p.make_payment
62
+ assert_equal -1, rt
63
+ end
64
+ end
65
+ end
66
+ context "with wrongly formed request" do
67
+ context "a visa with invalid datetime format" do
68
+ setup do
69
+ options = {:creditcard => Xpay::CreditCard.new(credit_card("visa_no3d_auth")), :operation => Xpay::Operation.new(operation("test_1")), :customer => Xpay::Customer.new(customer("test_1"))}
70
+ options[:creditcard].valid_until = "0910"
71
+ @p = Xpay::Payment.new(options)
72
+ Xpay.config.port = 5000
73
+ @rt = @p.make_payment
74
+ end
75
+ should "return 0 on make_payment" do
76
+ assert_equal 0, @rt
77
+ end
78
+ should "return '(3100) Invalid ExpiryDate' in response block error code" do
79
+ rt = @p.response_block[:error_code]
80
+ assert_equal "(3100) Invalid ExpiryDate", rt
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'active_support'
3
+ require 'active_support/core_ext'
4
+ require 'active_support/test_case'
5
+ require 'active_support/time'
6
+ require 'shoulda'
7
+ require 'fileutils'
8
+ require 'log_buddy'
9
+ require 'ostruct'
10
+ require 'rexml/document'
11
+
12
+ def credit_card(which)
13
+ conf = YAML::load(ERB.new(IO.read(File.expand_path(File.dirname(__FILE__) + '/fixtures/creditcards.yml'))).result)[which]
14
+ end
15
+ def customer(which)
16
+ conf = YAML::load(ERB.new(IO.read(File.expand_path(File.dirname(__FILE__) + '/fixtures/customer.yml'))).result)[which]
17
+ end
18
+ def customer_xml_string
19
+ x = REXML::Document.new(File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/customer.xml'))).root.to_s
20
+ end
21
+
22
+ def operation(which)
23
+ conf = YAML::load(ERB.new(IO.read(File.expand_path(File.dirname(__FILE__) + '/fixtures/operation.yml'))).result)[which]
24
+ end
25
+ def operation_xml_string(which="operation")
26
+ operation_xml(which).root.to_s
27
+ end
28
+ def operation_xml(which="operation")
29
+ REXML::Document.new(File.open(File.expand_path(File.dirname(__FILE__) + "/fixtures/#{which}.xml")))
30
+ end
31
+
32
+ def root_xml_string
33
+ x = REXML::Document.new(File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/root.xml'))).root.to_s
34
+ end
35
+
36
+ def xpay_config(which)
37
+ YAML::load(IO.read(File.expand_path(File.dirname(__FILE__) + '/fixtures/xpay_defaults.yml')))[which]
38
+ end
39
+
40
+ log_dir = File.expand_path('../../log', __FILE__)
41
+ FileUtils.mkdir_p(log_dir) unless File.exist?(log_dir)
42
+ logger = Logger.new(log_dir + '/test.log')
43
+
44
+ LogBuddy.init(:logger => logger)
45
+
46
+
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class CreditCardTest < Test::Unit::TestCase
4
+ context "a creditcard instance" do
5
+ setup do
6
+ @cc = Xpay::CreditCard.new(credit_card("class_test"))
7
+ end
8
+ should "have a credit card type" do
9
+ assert_equal @cc.card_type, "Visa"
10
+ end
11
+ should "have a partly hidden credit card number" do
12
+ assert_equal @cc.number, "xxxxxxxxxxxx1111"
13
+ end
14
+ should "have an expiry date" do
15
+ assert_instance_of(String, @cc.valid_until)
16
+ assert_not_nil @cc.valid_until =~ /\A\d{2}\/\d{2}/
17
+ assert_equal @cc.valid_until.length, 5
18
+ end
19
+ should "have an start date" do
20
+ assert_instance_of(String, @cc.valid_from)
21
+ assert_not_nil @cc.valid_from =~ /\A\d{2}\/\d{2}/
22
+ assert_equal @cc.valid_from.length, 5
23
+ end
24
+ should "have an issue number" do
25
+ assert_equal @cc.issue, "1"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,63 @@
1
+ require 'test_helper'
2
+
3
+ class CustomerTest < Test::Unit::TestCase
4
+ context "a customer instance" do
5
+ setup do
6
+ @cus = Xpay::Customer.new(customer("class_test"))
7
+ @request_xml = REXML::Document.new(Xpay.root_to_s)
8
+ end
9
+ should "have a title" do
10
+ assert_equal @cus.title, "MR"
11
+ end
12
+ should "have a fullname" do
13
+ assert_equal @cus.fullname, "JOE BLOGGS"
14
+ end
15
+ should "have a firstname" do
16
+ assert_equal @cus.firstname, "Joe"
17
+ end
18
+ should "have a lastname" do
19
+ assert_equal @cus.lastname, "Bloggs"
20
+ end
21
+ should "have a middlename" do
22
+ assert_equal @cus.middlename, "X"
23
+ end
24
+ should "have a namesuffix" do
25
+ assert_equal @cus.namesuffix, "PhD"
26
+ end
27
+ should "have a companyname" do
28
+ assert_equal @cus.companyname, "NotInventedHere.com"
29
+ end
30
+ should "have a street" do
31
+ assert_equal @cus.street, "tonowhere crescent"
32
+ end
33
+ should "have a city" do
34
+ assert_equal @cus.city, "beyond the rainbow on stale bread"
35
+ end
36
+ should "have a stateprovince" do
37
+ assert_equal @cus.stateprovince, "East-West Swampshire"
38
+ end
39
+ should "have a postcode" do
40
+ assert_equal @cus.postcode, "X01 Z10"
41
+ end
42
+ should "have a countrycode" do
43
+ assert_equal @cus.countrycode, "GB"
44
+ end
45
+ should "have a phone" do
46
+ assert_equal @cus.phone, "07950 843 363"
47
+ end
48
+ should "have a email" do
49
+ assert_equal @cus.email, "joe.x.bloggs@notinventedhere.com"
50
+ end
51
+ should "have a http_accept" do
52
+ assert_equal @cus.http_accept, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
53
+ end
54
+ should "have a user_agent" do
55
+ assert_equal @cus.user_agent, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; GTB5; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; InfoPath.1; .NET4.0C; AskTbGLSV5/5.8.0.12304)"
56
+ end
57
+ should "create a xml document according to xpay spec" do
58
+ @cus.add_to_xml(@request_xml)
59
+ assert_equal(customer_xml_string, @request_xml.root.to_s)
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,45 @@
1
+ require 'test_helper'
2
+
3
+ class OperationTest < Test::Unit::TestCase
4
+ context "an operation instance" do
5
+ setup do
6
+ @ops = Xpay::Operation.new(operation("class_test"))
7
+ @request_xml = REXML::Document.new(Xpay.root_to_s)
8
+ end
9
+ should "have a auth_type" do
10
+ assert_equal @ops.auth_type, "AUTH"
11
+ end
12
+ should "have a currency" do
13
+ assert_equal @ops.currency, "USD"
14
+ end
15
+ should "have a amount=" do
16
+ assert_equal @ops.amount, "1000"
17
+ end
18
+ should "have a settlement_day" do
19
+ assert_equal @ops.settlement_day, "3"
20
+ end
21
+ should "have a callback_url" do
22
+ assert_equal @ops.callback_url, "https://localhost/3dcallback"
23
+ end
24
+ should "have a site_reference" do
25
+ assert_equal @ops.site_reference, "site56987"
26
+ end
27
+ should "have a site_alias" do
28
+ assert_equal @ops.site_alias, "site56987"
29
+ end
30
+ should "have a merchant_name" do
31
+ assert_equal @ops.merchant_name, "TestMerchant"
32
+ end
33
+ should "have a order_reference" do
34
+ assert_equal @ops.order_reference, "TestOrder1245"
35
+ end
36
+ should "have a order_info" do
37
+ assert_equal @ops.order_info, "TestOrderInfo"
38
+ end
39
+ should "create an xml document according to xpay spec" do
40
+ @ops.add_to_xml(@request_xml)
41
+ assert_equal(operation_xml_string, @request_xml.root.to_s)
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,105 @@
1
+ require 'test_helper'
2
+ require 'xpay'
3
+
4
+ class PaymentTest < Test::Unit::TestCase
5
+ context "an empty payment instance" do
6
+ setup do
7
+ @p = Xpay::Payment.new()
8
+ end
9
+
10
+ should "have a the same xml as the module" do
11
+ assert_equal @p.request_xml.root.to_s, Xpay.root_xml.root.to_s
12
+ end
13
+
14
+ should "have a response block with return nil" do
15
+ assert @p.response_block.empty?
16
+ end
17
+
18
+ should "have a threesecure hash that has only emtpy elements" do
19
+ assert @p.three_secure.empty?
20
+ end
21
+ end
22
+
23
+ context "a payment instance from hashes" do
24
+ setup do
25
+ options = {:creditcard => credit_card("class_test"), :operation => operation("class_test"), :customer => customer("class_test")}
26
+ @p = Xpay::Payment.new(options)
27
+ end
28
+ should "have a customer instance variable" do
29
+ assert_instance_of(Xpay::Customer, @p.customer)
30
+ end
31
+ should "have a operations instance variable" do
32
+ assert_instance_of(Xpay::Operation, @p.operation)
33
+ end
34
+ should "have a creditcard instance variable" do
35
+ assert_instance_of(Xpay::CreditCard, @p.creditcard)
36
+ end
37
+ end
38
+ context "a payment instance from class instance" do
39
+ setup do
40
+ options = {:creditcard => Xpay::CreditCard.new(credit_card("class_test")), :operation => Xpay::Operation.new(operation("class_test")), :customer => Xpay::Customer.new(customer("class_test"))}
41
+ @p = Xpay::Payment.new(options)
42
+ end
43
+ should "have a customer instance variable" do
44
+ assert_instance_of(Xpay::Customer, @p.customer)
45
+ end
46
+ should "have a operations instance variable" do
47
+ assert_instance_of(Xpay::Operation, @p.operation)
48
+ end
49
+ should "have a creditcard instance variable" do
50
+ assert_instance_of(Xpay::CreditCard, @p.creditcard)
51
+ end
52
+ end
53
+ context "an empty payment instance with set 3D secure response" do
54
+ setup do
55
+ @p = Xpay::Payment.new()
56
+ @p.send("response_xml=", operation_xml("response_3d"))
57
+ end
58
+
59
+ should "have a non-empty hash as a response block" do
60
+ assert !@p.response_block.empty?
61
+ end
62
+
63
+ should "have a non-empty hash as threesecure block" do
64
+ assert !@p.three_secure.empty?
65
+ end
66
+ end
67
+ context "a non-empty payment instance with set 3D secure response" do
68
+ setup do
69
+ Xpay::Payment.send(:public, *Xpay::Payment.private_instance_methods)
70
+ options = {:creditcard => Xpay::CreditCard.new(credit_card("class_test")), :operation => Xpay::Operation.new(operation("class_test")), :customer => Xpay::Customer.new(customer("class_test"))}
71
+ @p = Xpay::Payment.new(options)
72
+ @p.send("response_xml=", operation_xml("response_3d"))
73
+
74
+ end
75
+ should "have a new request_xml after rewrite" do
76
+ @p.rewrite_request_block
77
+ assert_equal operation_xml_string("request_rewritten"), @p.request_xml.root.to_s
78
+ d { @p.request_xml.to_s }
79
+ end
80
+
81
+ should "have a non-empty hash as a response block" do
82
+ assert !@p.response_block.empty?
83
+ end
84
+
85
+ should "have a non-empty hash as threesecure block" do
86
+ assert !@p.three_secure.empty?
87
+ end
88
+ end
89
+
90
+ context "a payment instance created from xml without PaRes" do
91
+ should "throw error 2500, PaRes missing" do
92
+ options = {:xml => operation_xml_string("request_rewritten")}
93
+ assert_raise(Xpay::PaResMissing) {Xpay::Payment.new(options)}
94
+ end
95
+ end
96
+ context "a payment instance created from xml without PaRes" do
97
+ setup do
98
+ options = {:xml => operation_xml_string("request_rewritten"), :pares => "ABJASDKA+SDKAJ/SGDSAD"}
99
+ @p = Xpay::Payment.new(options)
100
+ end
101
+ should "should have a request_xml document" do
102
+ assert_instance_of(REXML::Document, @p.request_xml)
103
+ end
104
+ end
105
+ end