worldnet_tps 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rvmrc +1 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +9 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +70 -0
  8. data/Rakefile +6 -0
  9. data/lib/worldnet_tps.rb +12 -0
  10. data/lib/worldnet_tps/const.rb +42 -0
  11. data/lib/worldnet_tps/gateway.rb +71 -0
  12. data/lib/worldnet_tps/gateway.xsd +1909 -0
  13. data/lib/worldnet_tps/request/base.rb +107 -0
  14. data/lib/worldnet_tps/request/payment.rb +89 -0
  15. data/lib/worldnet_tps/request/refund.rb +59 -0
  16. data/lib/worldnet_tps/request/secure_card/registration.rb +71 -0
  17. data/lib/worldnet_tps/request/secure_card/removal.rb +46 -0
  18. data/lib/worldnet_tps/request/secure_card/search.rb +52 -0
  19. data/lib/worldnet_tps/response/error.rb +18 -0
  20. data/lib/worldnet_tps/response/invalid_hash.rb +21 -0
  21. data/lib/worldnet_tps/response/success.rb +25 -0
  22. data/lib/worldnet_tps/version.rb +3 -0
  23. data/lib/worldnet_tps/ws_object.rb +76 -0
  24. data/lib/worldnet_tps/xsd.rb +27 -0
  25. data/spec/fixtures/vcr_cassettes/payment/credit_card/failed.yml +60 -0
  26. data/spec/fixtures/vcr_cassettes/payment/credit_card/success.yml +59 -0
  27. data/spec/fixtures/vcr_cassettes/payment/secure_card/failed.yml +57 -0
  28. data/spec/fixtures/vcr_cassettes/payment/secure_card/success.yml +56 -0
  29. data/spec/fixtures/vcr_cassettes/refund/order_id/failed.yml +47 -0
  30. data/spec/fixtures/vcr_cassettes/refund/order_id/success.yml +46 -0
  31. data/spec/fixtures/vcr_cassettes/refund/unique_ref/failed.yml +47 -0
  32. data/spec/fixtures/vcr_cassettes/refund/unique_ref/success.yml +46 -0
  33. data/spec/fixtures/vcr_cassettes/secure_card/registration/registrarion_failed.yml +49 -0
  34. data/spec/fixtures/vcr_cassettes/secure_card/registration/registration_failed.yml +49 -0
  35. data/spec/fixtures/vcr_cassettes/secure_card/registration/registration_success.yml +48 -0
  36. data/spec/fixtures/vcr_cassettes/secure_card/registration/update_failed.yml +49 -0
  37. data/spec/fixtures/vcr_cassettes/secure_card/registration/update_success.yml +48 -0
  38. data/spec/fixtures/vcr_cassettes/secure_card/registration/update_success_success.yml +48 -0
  39. data/spec/fixtures/vcr_cassettes/secure_card/removal/failed.yml +45 -0
  40. data/spec/fixtures/vcr_cassettes/secure_card/removal/success.yml +44 -0
  41. data/spec/fixtures/vcr_cassettes/secure_card/search/failed.yml +44 -0
  42. data/spec/fixtures/vcr_cassettes/secure_card/search/success.yml +44 -0
  43. data/spec/gateway_spec.rb +42 -0
  44. data/spec/payment_spec.rb +117 -0
  45. data/spec/refund_spec.rb +95 -0
  46. data/spec/secure_card/registration_spec.rb +103 -0
  47. data/spec/secure_card/removal_spec.rb +57 -0
  48. data/spec/secure_card/search_spec.rb +58 -0
  49. data/spec/spec_helper.rb +58 -0
  50. data/spec/xsd_spec.rb +30 -0
  51. data/worldnet_tps.gemspec +28 -0
  52. metadata +205 -0
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://testpayments.worldnettps.com/merchant/xmlpayment
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0" encoding="UTF-8"?>
10
+ <SECURECARDSEARCH>
11
+ <MERCHANTREF>secure_card_search</MERCHANTREF>
12
+ <TERMINALID>6003</TERMINALID>
13
+ <DATETIME>10-12-2016:12:00:00:000</DATETIME>
14
+ <HASH>8d9d5953e4990066b4a5b984b4ed69f4</HASH>
15
+ </SECURECARDSEARCH>
16
+ headers:
17
+ Accept-Encoding:
18
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
19
+ Accept:
20
+ - "*/*"
21
+ User-Agent:
22
+ - Ruby
23
+ response:
24
+ status:
25
+ code: 200
26
+ message: OK
27
+ headers:
28
+ Date:
29
+ - Thu, 15 Dec 2016 16:49:28 GMT
30
+ Server:
31
+ - Apache
32
+ Content-Length:
33
+ - '134'
34
+ Strict-Transport-Security:
35
+ - max-age=15768000
36
+ Content-Type:
37
+ - text/xml;charset=UTF-8
38
+ body:
39
+ encoding: UTF-8
40
+ string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<ERROR><ERRORCODE>E04</ERRORCODE><ERRORSTRING>INVALID
41
+ REFERENCE DETAILS</ERRORSTRING></ERROR>\n"
42
+ http_version:
43
+ recorded_at: Thu, 15 Dec 2016 16:49:28 GMT
44
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,44 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://testpayments.worldnettps.com/merchant/xmlpayment
6
+ body:
7
+ encoding: UTF-8
8
+ string: |
9
+ <?xml version="1.0" encoding="UTF-8"?>
10
+ <SECURECARDSEARCH>
11
+ <MERCHANTREF>secure_card_search</MERCHANTREF>
12
+ <TERMINALID>6003</TERMINALID>
13
+ <DATETIME>10-12-2016:12:00:00:000</DATETIME>
14
+ <HASH>8d9d5953e4990066b4a5b984b4ed69f4</HASH>
15
+ </SECURECARDSEARCH>
16
+ headers:
17
+ Accept-Encoding:
18
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
19
+ Accept:
20
+ - "*/*"
21
+ User-Agent:
22
+ - Ruby
23
+ response:
24
+ status:
25
+ code: 200
26
+ message: OK
27
+ headers:
28
+ Date:
29
+ - Thu, 15 Dec 2016 16:53:29 GMT
30
+ Server:
31
+ - Apache
32
+ Content-Length:
33
+ - '376'
34
+ Strict-Transport-Security:
35
+ - max-age=15768000
36
+ Content-Type:
37
+ - text/xml;charset=UTF-8
38
+ body:
39
+ encoding: UTF-8
40
+ string: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<SECURECARDSEARCHRESPONSE><MERCHANTREF>secure_card_search</MERCHANTREF><CARDREFERENCE>2967534155322758</CARDREFERENCE><CARDTYPE>Visa
41
+ Credit</CARDTYPE><CARDEXPIRY>1234</CARDEXPIRY><CARDHOLDERNAME>John Doe</CARDHOLDERNAME><DATETIME>15-12-2016:16:53:29:830</DATETIME><HASH>a4182243666de17582b649302ac9f638</HASH></SECURECARDSEARCHRESPONSE>"
42
+ http_version:
43
+ recorded_at: Thu, 15 Dec 2016 16:53:29 GMT
44
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ describe WorldnetTps::Gateway do
3
+ subject do
4
+ WorldnetTps::Gateway.new(attributes)
5
+ end
6
+
7
+ let(:attributes) do
8
+ WorldnetTpsSharedContext::SandboxCredentials.attributes
9
+ end
10
+
11
+ context 'production environment' do
12
+ let(:attributes) do
13
+ super().merge(environment: :production)
14
+ end
15
+ describe '.domain' do
16
+ it 'should be live endpoint' do
17
+ expect(subject.endpoint).to eq('https://payments.worldnettps.com')
18
+ end
19
+
20
+ end
21
+ describe '.is_test?' do
22
+ it 'should be false' do
23
+ expect(subject.is_test?).to eq(false)
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ describe '.endpoint' do
30
+ it 'should be sandbox endpoint' do
31
+ expect(subject.endpoint).to eq('https://testpayments.worldnettps.com')
32
+ end
33
+ end
34
+
35
+ describe '.is_test?' do
36
+ it 'should be true' do
37
+ expect(subject.is_test?).to eq(true)
38
+ end
39
+ end
40
+
41
+
42
+ end
@@ -0,0 +1,117 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorldnetTps::Request::Payment do
4
+
5
+ let(:operation) do
6
+ gateway.payment(payment_attributes)
7
+ end
8
+
9
+ let(:payment_attributes) do
10
+ {
11
+ amount: '10.50',
12
+ order_id: 'TXN-124-55',
13
+ post_code: '98104',
14
+ email: 'john.doe@gmail.com',
15
+ address1: '100 MAIN ST',
16
+ address2: 'SEATTLE WA',
17
+ phone: '2064960114',
18
+ city: 'SEATTLE',
19
+ country: 'US'
20
+ }
21
+ end
22
+
23
+
24
+ subject do
25
+ VCR.use_cassette(vcr_cassette, match_requests_on: [:method, :uri, :body]) do
26
+ operation.invoke!
27
+ end
28
+ end
29
+
30
+
31
+ it 'should be valid object' do
32
+ expect(operation).to be_a_kind_of(WorldnetTps::Request::Payment)
33
+ expect(operation.gateway).to eq(gateway)
34
+ end
35
+
36
+ describe '.invoke!' do
37
+
38
+ include_context :xsd_validation
39
+
40
+ context 'credit card' do
41
+
42
+ let(:payment_attributes) do
43
+ super().merge(
44
+ card_number: '4000060000000006',
45
+ card_type: 'VISA',
46
+ card_expiry: '1223',
47
+ card_holder_name: 'John Doe',
48
+ cvv: '111',
49
+ order_id: 'TXN-124-59'
50
+ )
51
+ end
52
+ let(:vcr_cassette) { 'payment/credit_card/success' }
53
+ it 'should have valid data' do
54
+ expect(subject.attributes).to(
55
+ match(
56
+ a_hash_including(
57
+ approval_code: be_present,
58
+ date_time: be_present,
59
+ hash: be_present,
60
+ response_text: be_present,
61
+ response_code: be_present
62
+ )
63
+ )
64
+ )
65
+ expect(subject).to be_success
66
+ end
67
+ context 'failed response' do
68
+ let(:payment_attributes) do
69
+ super().merge(
70
+ card_number: '4000060000000006',
71
+ card_type: 'UNSUPPORTED',
72
+ order_id: 'TXN-124-56'
73
+ )
74
+ end
75
+ let(:vcr_cassette) { 'payment/credit_card/failed' }
76
+ it_behaves_like :failed_response
77
+ end
78
+
79
+ end
80
+
81
+ context 'secure card' do
82
+ let(:payment_attributes) do
83
+ super().merge(
84
+ card_number: '2967539270368883',
85
+ card_type: WorldnetTps::Const::SECURECARD,
86
+ )
87
+ end
88
+ let(:vcr_cassette) { 'payment/secure_card/success' }
89
+
90
+
91
+ it 'should have valid data' do
92
+ expect(subject.attributes).to(
93
+ match(
94
+ a_hash_including(
95
+ approval_code: be_present,
96
+ date_time: be_present,
97
+ hash: be_present,
98
+ response_text: be_present,
99
+ response_code: be_present
100
+ )
101
+ )
102
+ )
103
+ expect(subject).to be_success
104
+ end
105
+
106
+ context 'failed response' do
107
+ let(:vcr_cassette) { 'payment/secure_card/failed' }
108
+ it_behaves_like :failed_response
109
+ end
110
+
111
+
112
+ end
113
+
114
+
115
+ end
116
+
117
+ end
@@ -0,0 +1,95 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorldnetTps::Request::Refund do
4
+
5
+ let(:operation) do
6
+ gateway.refund(refund_attributes)
7
+ end
8
+
9
+ let(:refund_attributes) do
10
+ {
11
+ amount: '10.50',
12
+ operator: 'John',
13
+ reason: 'Product is defective'
14
+ }
15
+ end
16
+
17
+
18
+ it 'should be valid object' do
19
+ expect(operation).to be_a_kind_of(WorldnetTps::Request::Refund)
20
+ expect(operation.gateway).to eq(gateway)
21
+ end
22
+
23
+
24
+
25
+ subject do
26
+ VCR.use_cassette(vcr_cassette, match_requests_on: [:method, :uri, :body]) do
27
+ operation.invoke!
28
+ end
29
+ end
30
+
31
+ describe '.invoke!' do
32
+
33
+ include_context :xsd_validation
34
+
35
+ context 'by order id' do
36
+
37
+ let(:vcr_cassette) { 'refund/order_id/success' }
38
+ let(:refund_attributes){
39
+ super().merge(order_id: 'TXN-124-57')
40
+ }
41
+ it 'should have valid data' do
42
+ expect(subject.attributes).to(
43
+ match(
44
+ a_hash_including(
45
+ response_code: be_present,
46
+ response_text: be_present,
47
+ hash: be_present,
48
+ order_id: be_present,
49
+ date_time: be_present
50
+ )
51
+ )
52
+ )
53
+ expect(subject).to be_success
54
+ end
55
+ context 'failed response' do
56
+ let(:vcr_cassette) { 'refund/order_id/failed' }
57
+ it_behaves_like :failed_response
58
+ end
59
+
60
+
61
+ end
62
+
63
+
64
+ context 'by unique_ref' do
65
+
66
+ let(:vcr_cassette) { 'refund/unique_ref/success' }
67
+ let(:refund_attributes){
68
+ super().merge(unique_ref: 'KR3XSVSZ41')
69
+ }
70
+ it 'should have valid data' do
71
+ expect(subject.attributes).to(
72
+ match(
73
+ a_hash_including(
74
+ response_code: be_present,
75
+ response_text: be_present,
76
+ hash: be_present,
77
+ unique_ref: be_present,
78
+ date_time: be_present
79
+ )
80
+ )
81
+ )
82
+
83
+ expect(subject).to be_success
84
+ end
85
+
86
+ context 'failed response' do
87
+ let(:vcr_cassette) { 'refund/unique_ref/failed' }
88
+ it_behaves_like :failed_response
89
+ end
90
+
91
+
92
+ end
93
+ end
94
+
95
+ end
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+ require 'active_support/core_ext/numeric'
3
+
4
+ describe WorldnetTps::Request::SecureCard::Registration do
5
+
6
+ let(:visa) { '4000060000000006' }
7
+ let(:master_card) { '5001650000000000' }
8
+
9
+
10
+ let(:merchant_ref) { 'worldnet_tps.gem' }
11
+ let(:attributes) do
12
+ {
13
+ card_number: visa,
14
+ card_type: 'VISA',
15
+ card_expiry: '1234', #december 2034
16
+ cvv: '111',
17
+ card_holder_name: 'John Doe',
18
+ merchant_ref: merchant_ref
19
+ }
20
+ end
21
+
22
+ let(:operation) do
23
+ gateway.secure_card_registration(attributes)
24
+ end
25
+
26
+ it 'should be valid object' do
27
+ expect(operation).to be_a_kind_of(WorldnetTps::Request::SecureCard::Registration)
28
+ expect(operation.gateway).to eq(gateway)
29
+ end
30
+
31
+ shared_examples :successful_response do
32
+ it 'should be success' do
33
+ expect(subject).to be_kind_of(WorldnetTps::Response::Success)
34
+ expect(subject).to be_success
35
+ end
36
+
37
+ it 'should have valid data' do
38
+ expect(subject.attributes).to(
39
+ match(
40
+ a_hash_including(
41
+ card_reference: be_present,
42
+ date_time: be_present,
43
+ hash: be_present,
44
+ merchant_ref: merchant_ref
45
+ )
46
+ )
47
+ )
48
+ end
49
+ end
50
+
51
+ describe '.create!' do
52
+
53
+ include_context :xsd_validation
54
+
55
+ let(:vcr_cassette) { 'secure_card/registration/registration_success' }
56
+
57
+ subject do
58
+ VCR.use_cassette(vcr_cassette, match_requests_on: [:method, :uri, :body]) do
59
+ operation.create!
60
+ end
61
+ end
62
+
63
+ include_examples :successful_response
64
+
65
+ context 'when response failed' do
66
+ let(:vcr_cassette) { 'secure_card/registration/registration_failed' }
67
+ it_behaves_like :failed_response do
68
+ it 'should contain error code' do
69
+ expect(subject.code).to be_present
70
+ end
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ describe '.update!' do
77
+
78
+ include_context :xsd_validation
79
+
80
+ let(:vcr_cassette) { 'secure_card/registration/update_success_success' }
81
+
82
+ let(:attributes) {
83
+ super().merge(card_number: master_card, card_type: 'MASTERCARD')
84
+ }
85
+
86
+ subject do
87
+ VCR.use_cassette(vcr_cassette, match_requests_on: [:method, :uri, :body]) do
88
+ operation.update!
89
+ end
90
+ end
91
+
92
+ include_examples :successful_response
93
+
94
+ context 'when response failed' do
95
+ let(:vcr_cassette) { 'secure_card/registration/update_failed' }
96
+ it_behaves_like :failed_response do
97
+ it 'should contain error code' do
98
+ expect(subject.code).to be_present
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end