fat_zebra_multi 3.2.0.1 → 3.2.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.travis.yml +3 -3
  4. data/README.md +5 -4
  5. data/fat_zebra_multi.gemspec +4 -3
  6. data/lib/fat_zebra/authenticate.rb +64 -0
  7. data/lib/fat_zebra/card.rb +1 -0
  8. data/lib/fat_zebra/paypal/authorization.rb +49 -0
  9. data/lib/fat_zebra/paypal/billing_agreement.rb +56 -0
  10. data/lib/fat_zebra/paypal/capture.rb +36 -0
  11. data/lib/fat_zebra/paypal/order.rb +22 -0
  12. data/lib/fat_zebra/paypal/refund.rb +22 -0
  13. data/lib/fat_zebra/util.rb +1 -1
  14. data/lib/fat_zebra/version.rb +1 -1
  15. data/lib/fat_zebra.rb +8 -1
  16. data/spec/cassettes/FatZebra_Authenticate/_authenticate/validations/1_3_5_1.yml +46 -0
  17. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_challenge_response/1_3_3_1.yml +90 -0
  18. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_challenge_response/1_3_3_2.yml +90 -0
  19. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_frictionless_response/1_3_2_1.yml +90 -0
  20. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_frictionless_response/1_3_2_2.yml +90 -0
  21. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_invalid_input/1_3_1_1.yml +90 -0
  22. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_invalid_input/1_3_1_2.yml +87 -0
  23. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_invalid_input/1_3_1_3.yml +92 -0
  24. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_invalid_input/1_3_1_4.yml +91 -0
  25. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_type_validation/1_3_4_1.yml +46 -0
  26. data/spec/cassettes/FatZebra_Authenticate/_decode_session/when_token_is_invalid/returns_error_when_invalid_token.yml +47 -0
  27. data/spec/cassettes/FatZebra_Authenticate/_decode_session/when_token_is_valid/decodes_JWT.yml +87 -0
  28. data/spec/cassettes/FatZebra_Authenticate/_session/returns_JWT_with_given_params.yml +44 -0
  29. data/spec/cassettes/FatZebra_Authenticate/_session/returns_JWT_with_no_amount.yml +44 -0
  30. data/spec/cassettes/FatZebra_Authenticate/_session/returns_error_when_amount_is_invalid.yml +44 -0
  31. data/spec/cassettes/FatZebra_Authenticate/_session/returns_error_when_currency_is_invalid.yml +46 -0
  32. data/spec/cassettes/FatZebra_Card/_find/1_3_1.yml +111 -0
  33. data/spec/cassettes/FatZebra_Card/_find/1_3_2.yml +111 -0
  34. data/spec/cassettes/FatZebra_Paypal_Authorization/_capture/returns_a_new_capture_record.yml +45 -0
  35. data/spec/cassettes/{FatZebra_Authorise/_jwt_token/returns_JWT_with_no_params.yml → FatZebra_Paypal_Authorization/_find/when_found/returns_authorization.yml} +5 -5
  36. data/spec/cassettes/FatZebra_Paypal_Authorization/_search/with_date_filter/returns_records_created_after_start_date.yml +46 -0
  37. data/spec/cassettes/FatZebra_Paypal_Authorization/_void/returns_a_voided_capture_record.yml +44 -0
  38. data/spec/cassettes/FatZebra_Paypal_BillingAgreement/_charge/Valid_payload/returns_a_new_order_record.yml +48 -0
  39. data/spec/cassettes/FatZebra_Paypal_BillingAgreement/_find/when_found/returns_billing_agreement.yml +48 -0
  40. data/spec/cassettes/FatZebra_Paypal_BillingAgreement/_search/with_date_filter/returns_records_created_after_start_date.yml +48 -0
  41. data/spec/cassettes/FatZebra_Paypal_Capture/_find/when_found/returns_capture.yml +47 -0
  42. data/spec/cassettes/FatZebra_Paypal_Capture/_refund/returns_a_new_refund_record.yml +45 -0
  43. data/spec/cassettes/FatZebra_Paypal_Capture/_search/with_date_filter/returns_records_created_after_start_date.yml +49 -0
  44. data/spec/cassettes/FatZebra_Paypal_Order/_find/when_found/returns_order.yml +48 -0
  45. data/spec/cassettes/FatZebra_Paypal_Order/_search/with_date_filter/returns_orders_created_after_start_date.yml +55 -0
  46. data/spec/cassettes/{FatZebra_Authorise/_jwt_token/returns_JWT_with_some_params.yml → FatZebra_Paypal_Refund/_find/when_found/returns_refund.yml} +6 -5
  47. data/spec/cassettes/FatZebra_Paypal_Refund/_search/with_date_filter/returns_all_refund_records_created_after_start_date.yml +50 -0
  48. data/spec/lib/fat_zebra/authenticate_spec.rb +187 -0
  49. data/spec/lib/fat_zebra/card_spec.rb +8 -0
  50. data/spec/lib/fat_zebra/paypal/authorization_spec.rb +79 -0
  51. data/spec/lib/fat_zebra/paypal/billing_agreement_spec.rb +62 -0
  52. data/spec/lib/fat_zebra/paypal/capture_spec.rb +60 -0
  53. data/spec/lib/fat_zebra/paypal/order_spec.rb +35 -0
  54. data/spec/lib/fat_zebra/paypal/refund_spec.rb +36 -0
  55. data/spec/spec_helper.rb +0 -1
  56. data/spec/support/payloads.rb +129 -36
  57. metadata +65 -18
  58. data/lib/fat_zebra/authorise.rb +0 -49
  59. data/spec/cassettes/FatZebra_Authorise/_authorise/with_challenge_response/1_2_3_1.yml +0 -48
  60. data/spec/cassettes/FatZebra_Authorise/_authorise/with_challenge_response/1_2_3_2.yml +0 -48
  61. data/spec/cassettes/FatZebra_Authorise/_authorise/with_frictionless_response/1_2_2_1.yml +0 -48
  62. data/spec/cassettes/FatZebra_Authorise/_authorise/with_frictionless_response/1_2_2_2.yml +0 -48
  63. data/spec/cassettes/FatZebra_Authorise/_authorise/with_invalid_input/1_2_1_1.yml +0 -50
  64. data/spec/cassettes/FatZebra_Authorise/_jwt_token/returns_JWT_with_given_params.yml +0 -46
  65. data/spec/lib/fat_zebra/authorise_spec.rb +0 -101
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::Authenticate do
4
+ describe '.session', :vcr do
5
+ subject(:token) { FatZebra::Authenticate.session(valid_3ds_token_payload) }
6
+
7
+ let(:valid_3ds_token_payload) {{
8
+ currency: 'AUD',
9
+ amount: 100
10
+ }}
11
+
12
+ it 'returns JWT with given params' do
13
+ is_expected.to be_accepted
14
+ expect(token.jwt).to be_truthy
15
+ end
16
+
17
+ it 'returns JWT with no amount' do
18
+ valid_3ds_token_payload.delete(:amount)
19
+ is_expected.to be_accepted
20
+ expect(token.jwt).to be_truthy
21
+ end
22
+
23
+ it 'returns error when currency is invalid' do
24
+ valid_3ds_token_payload[:currency] = 'INVALID'
25
+ is_expected.not_to be_accepted
26
+ expect(token.errors).to be_a(Array)
27
+ expect(token.errors.join).to match(/INVALID is not valid for this merchant. Permitted currencies:/)
28
+ end
29
+
30
+ it 'returns error when amount is invalid' do
31
+ valid_3ds_token_payload[:amount] = 'INVALID'
32
+ is_expected.not_to be_accepted
33
+ expect(token.errors).to eq(['Amount is invalid'])
34
+ end
35
+ end
36
+
37
+ describe '.decode_session', :vcr do
38
+ subject(:decoded) { FatZebra::Authenticate.decode_session(token: jwt) }
39
+
40
+ context 'when token is valid' do
41
+ let(:valid_3ds_token_payload) {{
42
+ currency: 'AUD',
43
+ amount: 100
44
+ }}
45
+ let(:jwt) { FatZebra::Authenticate.session(valid_3ds_token_payload).jwt }
46
+
47
+ it 'decodes JWT' do
48
+ is_expected.to be_accepted
49
+ expect(decoded.keys).to include('processor_transaction_id', 'consumer_session_id', 'error_number', 'error_description')
50
+ expect(decoded.errors).to be_empty
51
+ end
52
+ end
53
+
54
+ context 'when token is invalid' do
55
+ let(:jwt) { 'INVALID TOKEN' }
56
+
57
+ it 'returns error when invalid token' do
58
+ is_expected.not_to be_accepted
59
+ expect(decoded.errors).to eq(['Decoding JWT failed: The token is invalid'])
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '.authenticate', :vcr do
65
+ subject(:authenticate) { FatZebra::Authenticate.authenticate(valid_sca_authentication_payload) }
66
+ let!(:credit_card) { FatZebra::Card.create(valid_credit_card_payload) }
67
+
68
+ context 'with invalid input' do
69
+ before do
70
+ valid_sca_authentication_payload[:sca].merge!(valid_sca_enrollment_payload)
71
+ end
72
+
73
+ it do
74
+ valid_sca_authentication_payload[:card_token] = 'INVALID'
75
+ is_expected.not_to be_accepted
76
+ expect(authenticate.errors.join).to match(/Card not found/)
77
+ end
78
+
79
+ it do
80
+ valid_sca_authentication_payload[:sca] = {}
81
+ is_expected.not_to be_accepted
82
+ expect(authenticate.errors.join).to match(/Invalid input data/)
83
+ end
84
+
85
+ it do
86
+ valid_sca_authentication_payload[:currency] = 'INVALID'
87
+ is_expected.not_to be_accepted
88
+ expect(authenticate.errors.join).to match(/INVALID is not valid for this merchant. Permitted currencies:/)
89
+ end
90
+
91
+ it do
92
+ valid_sca_authentication_payload[:amount] = 'INVALID'
93
+ is_expected.not_to be_accepted
94
+ expect(authenticate.errors.join).to match(/3DS authenticate request failed: amount must be filled/)
95
+ end
96
+ end
97
+
98
+ context 'with frictionless response' do
99
+ before do
100
+ valid_credit_card_payload[:card_number] = '4000000000001000'
101
+ valid_sca_authentication_payload[:sca].merge!(valid_sca_enrollment_payload)
102
+ end
103
+
104
+ it do
105
+ is_expected.to be_accepted
106
+ expect(authenticate.keys).to include('enrolled', 'acs_url', 'version', 'card_bin', 'authentication_transaction_id')
107
+ expect(authenticate.errors).to be_empty
108
+ end
109
+
110
+ it do
111
+ expect(authenticate.enrolled).to be_truthy
112
+ expect(authenticate.version).to be_truthy
113
+ expect(authenticate.card_bin).to be_truthy
114
+ expect(authenticate.authentication_transaction_id).to be_truthy
115
+ end
116
+ end
117
+
118
+ context 'with challenge response' do
119
+ before do
120
+ valid_credit_card_payload[:card_number] = '4000000000001091'
121
+ valid_sca_authentication_payload[:sca].merge!(valid_sca_enrollment_payload)
122
+ end
123
+
124
+ it do
125
+ is_expected.to be_accepted
126
+ expect(authenticate.keys).to include('enrolled', 'version', 'card_bin', 'authentication_transaction_id')
127
+ expect(authenticate.errors).to be_empty
128
+ end
129
+
130
+ it do
131
+ expect(authenticate.enrolled).to be_truthy
132
+ expect(authenticate.version).to be_truthy
133
+ expect(authenticate.card_bin).to be_truthy
134
+ expect(authenticate.authentication_transaction_id).to be_truthy
135
+ end
136
+ end
137
+
138
+ context 'with type = validation' do
139
+ subject(:authenticate) { FatZebra::Authenticate.authenticate(valid_sca_authentication_payload) }
140
+
141
+ before do
142
+ allow(FatZebra::Authenticate).to receive(:authenticate)
143
+ .with(valid_sca_authentication_payload)
144
+ .and_return(FatZebra::FatZebraObject.initialize_from(validation_response.to_json))
145
+
146
+ valid_credit_card_payload[:card_number] = '4000000000001091'
147
+ valid_sca_authentication_payload[:sca][:type] = 'validation'
148
+ valid_sca_authentication_payload[:sca].merge!(valid_sca_validation_payload)
149
+ end
150
+
151
+ let(:validation_response) do
152
+ {
153
+ successful: true,
154
+ response: {
155
+ action: {
156
+ proceed: true
157
+ },
158
+ version: '2.2.0',
159
+ enrolled: 'Y',
160
+ cavv: SecureRandom.hex,
161
+ xid: SecureRandom.hex,
162
+ pares: 'Y',
163
+ eci: '05',
164
+ authentication_transaction_id: SecureRandom.hex,
165
+ card_bin: '400000',
166
+ request_id: SecureRandom.hex,
167
+ decision: 'ACCEPT'
168
+ },
169
+ errors: [],
170
+ test: true
171
+ }
172
+ end
173
+
174
+ it do
175
+ is_expected.to be_accepted
176
+ expect(authenticate.keys).to include('enrolled', 'version', 'card_bin', 'authentication_transaction_id', 'cavv', 'eci', 'xid', 'pares')
177
+ expect(authenticate.errors).to be_empty
178
+ end
179
+ end
180
+
181
+ context 'validations' do
182
+ let(:valid_sca_authentication_payload) {{}}
183
+
184
+ it { expect{ authenticate }.to raise_error(FatZebra::RequestValidationError) }
185
+ end
186
+ end
187
+ end
@@ -38,4 +38,12 @@ describe FatZebra::Card do
38
38
  end
39
39
  end
40
40
 
41
+ describe '.find', :vcr do
42
+ let(:create) { FatZebra::Card.create(valid_credit_card_payload) }
43
+ subject(:card) { FatZebra::Card.find(create.token) }
44
+
45
+ it { is_expected.to be_accepted }
46
+ it { expect(card.token).to eq(create.token) }
47
+ end
48
+
41
49
  end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::Paypal::Authorization do
4
+
5
+ describe '.find', :vcr do
6
+ subject(:authorization) { FatZebra::Paypal::Authorization.find(authorization_id) }
7
+
8
+ context 'when found' do
9
+ let(:authorization_id) { '071-PPA-3AM3CXFFKMFYI3QM' }
10
+
11
+ it 'returns authorization' do
12
+ expect(authorization).to be_accepted
13
+ expect(authorization.id).to eq(authorization_id)
14
+ expect(authorization.order).to include('PPO')
15
+ end
16
+ end
17
+ end
18
+
19
+ describe '.search', :vcr do
20
+ context 'with date filter' do
21
+ subject(:authorizations) { FatZebra::Paypal::Authorization.search(from: start) }
22
+
23
+ let(:start) { Date.parse('2020-08-05') }
24
+
25
+ it 'returns records created after start date' do
26
+ created_date_check = authorizations.data.map { |rec| DateTime.strptime(rec.transaction_date, '%Y-%m-%dT%H:%M:%S%z').iso8601 >= start.iso8601 }
27
+
28
+ is_expected.to be_accepted
29
+
30
+ expect(authorizations.data).to be_a(Array)
31
+ expect(authorizations.data.first).to be_a(FatZebra::Paypal::Authorization)
32
+ expect(created_date_check.all?).to be(true)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#capture', :vcr do
38
+ subject(:capture_record) { FatZebra::Paypal::Authorization.capture(authorization_id, params_for_capture) }
39
+
40
+ let(:authorization_id) { '071-PPA-3AM3CXFFKMFYI3QM' }
41
+ let(:capture_amount) { 200 }
42
+ let(:note) { 'test capture $2' }
43
+ let(:params_for_capture) do
44
+ {
45
+ amount: capture_amount,
46
+ final_Capture: false,
47
+ note_to_payer: note
48
+ }
49
+ end
50
+
51
+ it 'returns a new capture record' do
52
+ is_expected.to be_accepted
53
+ is_expected.to be_successful
54
+
55
+ expect(capture_record).to be_a(FatZebra::Paypal::Capture)
56
+ expect(capture_record.id).to include('PPC')
57
+ expect(capture_record.order).to include('PPO')
58
+ expect(capture_record.amount).to eq(capture_amount)
59
+ expect(capture_record.note_to_payer).to eq(note)
60
+ expect(capture_record.balance_available_for_capture).to be > 0
61
+ end
62
+ end
63
+
64
+ describe '#void', :vcr do
65
+ subject(:voided_authorization_record) { FatZebra::Paypal::Authorization.void(authorization_id) }
66
+
67
+ let(:authorization_id) { '071-PPA-XB5CXLVNIGCNTB8V' }
68
+
69
+ it 'returns a voided capture record' do
70
+ is_expected.to be_accepted
71
+ is_expected.to be_successful
72
+
73
+ expect(voided_authorization_record).to be_a(FatZebra::Paypal::Authorization)
74
+ expect(voided_authorization_record.id).to include('PPA')
75
+ expect(voided_authorization_record.response_code).to eq('00')
76
+ expect(voided_authorization_record.balance_available_for_capture).to eq(0)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::Paypal::BillingAgreement do
4
+
5
+ describe '.find', :vcr do
6
+ subject(:billing_agreement) { FatZebra::Paypal::BillingAgreement.find(id) }
7
+
8
+ context 'when found' do
9
+ let(:id) { '071-PBA-PYG1L6M4CV4DYHTZ' }
10
+
11
+ it 'returns billing_agreement' do
12
+ expect(billing_agreement).to be_accepted
13
+ expect(billing_agreement.id).to eq(id)
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '.search', :vcr do
19
+ context 'with date filter' do
20
+ subject(:billing_agreements) { FatZebra::Paypal::BillingAgreement.search(from: start) }
21
+
22
+ let(:start) { Date.parse('2020-08-05') }
23
+
24
+ it 'returns records created after start date' do
25
+ created_date_check = billing_agreements.data.map { |rec| DateTime.strptime(rec.created_at, '%Y-%m-%dT%H:%M:%S%z').iso8601 >= start.iso8601 }
26
+
27
+ is_expected.to be_accepted
28
+
29
+ expect(billing_agreements.data).to be_a(Array)
30
+ expect(billing_agreements.data.first).to be_a(FatZebra::Paypal::BillingAgreement)
31
+ expect(created_date_check.all?).to be(true)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#charge', :vcr do
37
+ let(:id) { '071-PBA-PYG1L6M4CV4DYHTZ' }
38
+
39
+ context 'Valid payload' do
40
+ subject(:charge) { FatZebra::Paypal::BillingAgreement.charge(id, valid_charge_billing_agreement_payload) }
41
+
42
+ it 'returns a new order record' do
43
+ is_expected.to be_accepted
44
+ is_expected.to be_successful
45
+
46
+ expect(charge).to be_a(FatZebra::Paypal::Order)
47
+ expect(charge.billing_agreement_id).to eq(id)
48
+ expect(charge.payment_source).to eq('BILLING_AGREEMENT')
49
+ expect(charge.id).to include('PPO')
50
+ expect(charge.captures.count).to eq(1)
51
+ end
52
+ end
53
+
54
+ context 'Invalid payload' do
55
+ subject(:charge) { FatZebra::Paypal::BillingAgreement.charge(id, {}) }
56
+
57
+ it 'failed to execute call' do
58
+ expect{ charge }.to raise_error(FatZebra::RequestValidationError)
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::Paypal::Capture do
4
+
5
+ describe '.find', :vcr do
6
+ subject(:capture) { FatZebra::Paypal::Capture.find(capture_id) }
7
+
8
+ context 'when found' do
9
+ let(:capture_id) { '071-PPC-TUOHT8YJHBY7SBJU' }
10
+
11
+ it 'returns capture' do
12
+ expect(capture).to be_accepted
13
+ expect(capture.id).to eq(capture_id)
14
+ expect(capture.order).to include('PPO')
15
+ end
16
+ end
17
+ end
18
+
19
+ describe '.search', :vcr do
20
+ context 'with date filter' do
21
+ subject(:captures) { FatZebra::Paypal::Capture.search(from: start) }
22
+
23
+ let(:start) { Date.parse('2020-08-05') }
24
+
25
+ it 'returns records created after start date' do
26
+ created_date_check = captures.data.map { |rec| DateTime.strptime(rec.transaction_date, '%Y-%m-%dT%H:%M:%S%z').iso8601 >= start.iso8601 }
27
+
28
+ is_expected.to be_accepted
29
+
30
+ expect(captures.data).to be_a(Array)
31
+ expect(captures.data.first).to be_a(FatZebra::Paypal::Capture)
32
+ expect(created_date_check.all?).to be(true)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#refund', :vcr do
38
+ subject(:refund_record) { FatZebra::Paypal::Capture.refund(capture_id, params_for_refund) }
39
+
40
+ let(:capture_id) { '071-PPC-TUOHT8YJHBY7SBJU' }
41
+ let(:refund_amount) { 100 }
42
+ let(:params_for_refund) do
43
+ {
44
+ amount: refund_amount,
45
+ note_to_payer: 'test note'
46
+ }
47
+ end
48
+
49
+ it 'returns a new refund record' do
50
+ is_expected.to be_accepted
51
+ is_expected.to be_successful
52
+
53
+ expect(refund_record).to be_a(FatZebra::Paypal::Refund)
54
+ expect(refund_record.amount).to eq(refund_amount)
55
+ expect(refund_record.note_to_payer).to eq('test note')
56
+ expect(refund_record.id).to include('PPR')
57
+ expect(refund_record.order).to include('PPO')
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::Paypal::Order do
4
+
5
+ describe '.find', :vcr do
6
+ subject(:order) { FatZebra::Paypal::Order.find(order_id) }
7
+
8
+ context 'when found' do
9
+ let(:order_id) { '071-PPO-U7RRMGM3OY3V2ZMN' }
10
+
11
+ it 'returns order' do
12
+ expect(order).to be_accepted
13
+ expect(order.id).to eq(order_id)
14
+ end
15
+ end
16
+ end
17
+
18
+ describe '.search', :vcr do
19
+ context 'with date filter' do
20
+ subject(:orders) { FatZebra::Paypal::Order.search(from: start) }
21
+
22
+ let(:start) { Date.parse('2020-08-05') }
23
+
24
+ it 'returns orders created after start date' do
25
+ created_date_check = orders.data.map { |rec| DateTime.strptime(rec.transaction_date, '%Y-%m-%dT%H:%M:%S%z').iso8601 >= start.iso8601 }
26
+
27
+ is_expected.to be_accepted
28
+
29
+ expect(orders.data).to be_a(Array)
30
+ expect(orders.data.first).to be_a(FatZebra::Paypal::Order)
31
+ expect(created_date_check.all?).to be(true)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe FatZebra::Paypal::Refund do
4
+
5
+ describe '.find', :vcr do
6
+ subject(:refund) { FatZebra::Paypal::Refund.find(refund_id) }
7
+
8
+ context 'when found' do
9
+ let(:refund_id) { '071-PPR-SRR9FP7ZKXT9IXU3' }
10
+
11
+ it 'returns refund' do
12
+ expect(refund).to be_accepted
13
+ expect(refund.id).to eq(refund_id)
14
+ expect(refund.order).to include('PPO')
15
+ end
16
+ end
17
+ end
18
+
19
+ describe '.search', :vcr do
20
+ context 'with date filter' do
21
+ subject(:refunds) { FatZebra::Paypal::Refund.search(from: start) }
22
+
23
+ let(:start) { Date.parse('2020-08-05') }
24
+
25
+ it 'returns all refund records created after start date' do
26
+ created_date_check = refunds.data.map { |rec| DateTime.strptime(rec.transaction_date, '%Y-%m-%dT%H:%M:%S%z').iso8601 >= start.iso8601 }
27
+
28
+ is_expected.to be_accepted
29
+
30
+ expect(refunds.data).to be_a(Array)
31
+ expect(refunds.data.first).to be_a(FatZebra::Paypal::Refund)
32
+ expect(created_date_check.all?).to be(true)
33
+ end
34
+ end
35
+ end
36
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/setup'
3
- require 'pry'
4
3
  require 'rspec'
5
4
  require 'vcr'
6
5
  require 'webmock/rspec'
@@ -40,46 +40,139 @@ shared_context 'payloads' do
40
40
  }
41
41
  }}
42
42
 
43
- let(:valid_3ds_authorise_payload) {{
44
- card_number: '5123456789012346',
45
- card_expiry: DateTime.now.next_year.strftime('%m/%Y'),
46
- threeds: {
47
- enabled: true,
48
- amount: 100,
49
- billing_address1: 'SOME ADDRESS',
50
- billing_city: 'Sydney',
51
- billing_country_code: '036', # Australia
52
- billing_first_name: 'John',
53
- billing_last_name: 'Smith',
54
- billing_postal_code: '2000',
55
- billing_state: 'NSW',
56
- currency_code: '036',
57
- df_reference_id: SecureRandom.hex(10),
58
- mobile_phone: '1234567890',
59
- email: 'dev@fatzebra.com.au',
43
+ let(:valid_sca_enrollment_payload) {{
44
+ customer: {
45
+ address_1: '23 Smith Road',
46
+ address_2: 'North Shore',
47
+ city: 'Canberra',
48
+ country: 'AU',
49
+ state: 'NSW',
50
+ email: 'test@test.com',
51
+ first_name: 'James',
52
+ last_name: 'Smith',
53
+ phone_number: '0444555666',
54
+ post_code: '2000',
55
+ passport_number: 'X1234567890',
56
+ passport_country: '036',
57
+ account_changed_at: '20191210',
58
+ account_created_at: '20191210',
59
+ account_password_changed_at: '20191210'
60
+ },
61
+ shipping_address: {
62
+ address_1: '23 Smith Road',
63
+ address_2: 'North Shore',
64
+ city: 'Sydney',
65
+ country: 'AU',
66
+ state: 'NSW',
67
+ email: 'test@test.com',
68
+ first_name: 'James',
69
+ last_name: 'Smith',
70
+ phone_number: '0444555666',
71
+ post_code: '2000',
72
+ method: 'pickup',
73
+ destination_code: '01',
74
+ },
75
+ custom: {
60
76
  transaction_mode: 'mobile',
61
- transaction_type: 'C',
62
- order_number: SecureRandom.hex(10),
77
+ reference_id: SecureRandom.hex,
78
+
79
+ merchant_name: 'TEST',
80
+ merchant_new_customer: true,
81
+ preorder: 1,
63
82
 
64
- shipping_address1: 'SOME ADDRESS',
65
- shipping_state: 'NSW',
66
- shipping_city: 'Sydney',
67
- shipping_country_code: '036',
68
- shipping_address2: 'SOME ADDRESS',
69
- shipping_address3: 'SOME ADDRESS',
70
- shipping_postal_code: '2000',
71
- billing_phone: '1234567890',
72
- work_phone: '1234567890',
73
- billing_address2: 'SOME ADDRESS',
74
- billing_address3: 'SOME ADDRESS',
75
- authentication_indicator: '01',
76
- product_code: 'PHY',
83
+ http_accept: 'text/html',
84
+ http_user_agent: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',
77
85
 
78
- installment: 2,
79
- purchase_date: DateTime.now.next_year.strftime('%Y%m%d%H%M%S'),
80
- recurring_end: DateTime.now.next_year.strftime('%Y%m%d'),
81
- recurring_frequency: 31
86
+ recurring_end_date: '20201201',
87
+ recurring_frequency: 3,
88
+ recurring_original_purchase_date: '2019120112:00:00'
89
+ },
90
+ items: [
91
+ {
92
+ unit_price: 23.3,
93
+ product_description: 'Widgets',
94
+ product_name: 'Watch',
95
+ quantity: 1,
96
+ product_sku: '9999',
97
+ passenger_first_name: 'John',
98
+ passenger_last_name: 'Smith',
99
+ }
100
+ ],
101
+ airline_data: {
102
+ legs: [
103
+ {
104
+ carrier_code: 'code',
105
+ departure_date: '20221012',
106
+ destination: 'SYD',
107
+ originating_airport_code: 'MEL',
108
+ }
109
+ ],
110
+ number_of_passengers: 2,
111
+ passengers: [
112
+ {
113
+ first_name: 'John',
114
+ last_name: 'Smith',
115
+ },
116
+ {
117
+ first_name: 'Megan',
118
+ last_name: 'Doe',
119
+ }
120
+ ]
82
121
  }
83
122
  }}
84
123
 
124
+ let(:valid_sca_validation_payload) {{
125
+ authentication_transaction_id: SecureRandom.hex,
126
+ signed_pares: SecureRandom.hex
127
+ }}
128
+
129
+ let(:valid_sca_authentication_payload) {{
130
+ card_token: credit_card.token,
131
+ amount: 100,
132
+ currency: 'AUD',
133
+ customer_ip: '111.111.111.111',
134
+ sca: {
135
+ type: 'enrollment',
136
+ merchant_reference_code: SecureRandom.uuid,
137
+ }
138
+ }}
139
+
140
+ let(:valid_charge_billing_agreement_payload) {{
141
+ reference: SecureRandom.uuid,
142
+ amount: 1100,
143
+ currency: "AUD",
144
+ customer_ip: '1.2.3.4',
145
+ options: {
146
+ brand_name: "EXAMPLE INC"
147
+ },
148
+ purchases: [{
149
+ description: "Sporting Goods",
150
+ custom_id: "CUST-HighFashions",
151
+ soft_descriptor: "HighFashions",
152
+ amount: {
153
+ item_total: 900,
154
+ shipping: 200
155
+ },
156
+ items: [{
157
+ name: "T-Shirt",
158
+ unit_amount: 900,
159
+ qty: 1,
160
+ category: "PHYSICAL_GOODS"
161
+ }],
162
+ shipping_address: {
163
+ method: "United States Postal Service 1",
164
+ address: {
165
+ first_name: "John",
166
+ last_name: "Doe",
167
+ address_1: "100 Kent Street",
168
+ address_2: "Cafe Lane",
169
+ city: "Sydney",
170
+ state: "NSW",
171
+ postcode: "2000",
172
+ country: "AU"
173
+ }
174
+ }
175
+ }]
176
+ }}
177
+
85
178
  end