fat_zebra 3.2.1 → 3.2.2

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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +1 -0
  4. data/README.md +3 -3
  5. data/fat_zebra.gemspec +3 -3
  6. data/lib/fat_zebra.rb +7 -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/version.rb +1 -1
  14. data/spec/cassettes/FatZebra_Authenticate/_authenticate/validations/1_3_5_1.yml +46 -0
  15. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_challenge_response/1_3_3_1.yml +12 -13
  16. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_challenge_response/1_3_3_2.yml +12 -13
  17. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_frictionless_response/1_3_2_1.yml +12 -13
  18. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_frictionless_response/1_3_2_2.yml +12 -13
  19. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_invalid_input/1_3_1_1.yml +12 -13
  20. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_invalid_input/1_3_1_2.yml +8 -8
  21. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_invalid_input/1_3_1_3.yml +14 -14
  22. data/spec/cassettes/FatZebra_Authenticate/_authenticate/with_invalid_input/1_3_1_4.yml +13 -14
  23. data/spec/cassettes/FatZebra_Authenticate/_authenticate/{validations → with_type_validation}/1_3_4_1.yml +4 -4
  24. data/spec/cassettes/FatZebra_Authenticate/_decode_session/when_token_is_invalid/returns_error_when_invalid_token.yml +5 -5
  25. data/spec/cassettes/FatZebra_Authenticate/_decode_session/when_token_is_valid/decodes_JWT.yml +10 -10
  26. data/spec/cassettes/FatZebra_Authenticate/_session/returns_JWT_with_given_params.yml +5 -5
  27. data/spec/cassettes/FatZebra_Authenticate/_session/{returns_JWT_with_no_params.yml → returns_JWT_with_no_amount.yml} +5 -5
  28. data/spec/cassettes/FatZebra_Authenticate/_session/returns_error_when_amount_is_invalid.yml +5 -5
  29. data/spec/cassettes/FatZebra_Authenticate/_session/returns_error_when_currency_is_invalid.yml +46 -0
  30. data/spec/cassettes/FatZebra_Card/_find/1_3_1.yml +111 -0
  31. data/spec/cassettes/FatZebra_Card/_find/1_3_2.yml +111 -0
  32. data/spec/cassettes/FatZebra_Paypal_Authorization/_capture/returns_a_new_capture_record.yml +45 -0
  33. data/spec/cassettes/FatZebra_Paypal_Authorization/_find/when_found/returns_authorization.yml +46 -0
  34. data/spec/cassettes/FatZebra_Paypal_Authorization/_search/with_date_filter/returns_records_created_after_start_date.yml +46 -0
  35. data/spec/cassettes/FatZebra_Paypal_Authorization/_void/returns_a_voided_capture_record.yml +44 -0
  36. data/spec/cassettes/FatZebra_Paypal_BillingAgreement/_charge/Valid_payload/returns_a_new_order_record.yml +48 -0
  37. data/spec/cassettes/FatZebra_Paypal_BillingAgreement/_find/when_found/returns_billing_agreement.yml +48 -0
  38. data/spec/cassettes/FatZebra_Paypal_BillingAgreement/_search/with_date_filter/returns_records_created_after_start_date.yml +48 -0
  39. data/spec/cassettes/FatZebra_Paypal_Capture/_find/when_found/returns_capture.yml +47 -0
  40. data/spec/cassettes/FatZebra_Paypal_Capture/_refund/returns_a_new_refund_record.yml +45 -0
  41. data/spec/cassettes/FatZebra_Paypal_Capture/_search/with_date_filter/returns_records_created_after_start_date.yml +49 -0
  42. data/spec/cassettes/FatZebra_Paypal_Order/_find/when_found/returns_order.yml +48 -0
  43. data/spec/cassettes/FatZebra_Paypal_Order/_search/with_date_filter/returns_orders_created_after_start_date.yml +55 -0
  44. data/spec/cassettes/FatZebra_Paypal_Refund/_find/when_found/returns_refund.yml +47 -0
  45. data/spec/cassettes/FatZebra_Paypal_Refund/_search/with_date_filter/returns_all_refund_records_created_after_start_date.yml +50 -0
  46. data/spec/lib/fat_zebra/authenticate_spec.rb +88 -45
  47. data/spec/lib/fat_zebra/card_spec.rb +8 -0
  48. data/spec/lib/fat_zebra/paypal/authorization_spec.rb +79 -0
  49. data/spec/lib/fat_zebra/paypal/billing_agreement_spec.rb +62 -0
  50. data/spec/lib/fat_zebra/paypal/capture_spec.rb +60 -0
  51. data/spec/lib/fat_zebra/paypal/order_spec.rb +35 -0
  52. data/spec/lib/fat_zebra/paypal/refund_spec.rb +36 -0
  53. data/spec/spec_helper.rb +0 -1
  54. data/spec/support/payloads.rb +129 -41
  55. metadata +39 -12
  56. data/spec/cassettes/FatZebra_Authenticate/_session/returns_JWT_with_some_params.yml +0 -44
@@ -0,0 +1,50 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://gateway.sandbox.fatzebra.com.au/v1.0//paypal/refunds?from=2020/08/05&limit=10&offset=0&test=true
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - application/json
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - gateway.sandbox.fatzebra.com.au
18
+ Authorization:
19
+ - Basic VEVTVDpURVNU
20
+ Content-Type:
21
+ - application/json
22
+ response:
23
+ status:
24
+ code: 200
25
+ message: OK
26
+ headers:
27
+ Cache-Control:
28
+ - no-store
29
+ Pragma:
30
+ - no-cache
31
+ Content-Type:
32
+ - application/json; charset=utf-8
33
+ X-Request-Version:
34
+ - 1.21.8
35
+ X-Request-Id:
36
+ - f9e0e746bb7c4611132605c0fefbd352
37
+ X-Runtime:
38
+ - '0.086558'
39
+ Transfer-Encoding:
40
+ - chunked
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"successful":true,"response":[{"id":"071-PPR-SRR9FP7ZKXT9IXU3","amount":100,"refunded":"Approved","message":"Approved","transaction_id":"071-PPR-SRR9FP7ZKXT9IXU3","currency":"AUD","successful":true,"transaction_date":"2020-08-06T23:26:56+10:00","response_code":"00","standalone":false,"note_to_payer":"test
44
+ note","invoice_id":"071-PPR-SRR9FP7ZKXT9IXU3","decimal_amount":1.0,"paypal_fee":2,"seller_payable_net_amount":98,"balance_available_for_refund":11900,"capture":"071-PPC-TUOHT8YJHBY7SBJU","order":"071-PPO-U7RRMGM3OY3V2ZMN"},{"id":"071-PPR-10HDHDI4QRHVDOGV","amount":10900,"refunded":"Approved","message":"Approved","transaction_id":"071-PPR-10HDHDI4QRHVDOGV","currency":"AUD","successful":true,"transaction_date":"2020-08-05T16:54:15+10:00","response_code":"00","standalone":false,"invoice_id":"071-PPR-10HDHDI4QRHVDOGV","decimal_amount":109.0,"paypal_fee":262,"seller_payable_net_amount":10638,"balance_available_for_refund":0,"capture":"071-PPC-JUNNKEGCHIOL1CFR","order":"071-PPO-RXFR2E6ILCIE6HKI"},{"id":"071-PPR-7BIDZCFHPCCBUSJH","amount":100,"refunded":"Approved","message":"Approved","transaction_id":"071-PPR-7BIDZCFHPCCBUSJH","currency":"AUD","successful":true,"transaction_date":"2020-08-05T11:24:24+10:00","response_code":"00","standalone":false,"note_to_payer":"refund
45
+ the rest","invoice_id":"071-PPR-7BIDZCFHPCCBUSJH","decimal_amount":1.0,"paypal_fee":2,"seller_payable_net_amount":98,"balance_available_for_refund":0,"capture":"071-PPC-JUNNKEGCHIOL1CFR","order":"071-PPO-RXFR2E6ILCIE6HKI"},{"id":"071-PPR-WXEAYHCGZY7DJYZ2","amount":1000,"refunded":"Approved","message":"Approved","transaction_id":"071-PPR-WXEAYHCGZY7DJYZ2","currency":"AUD","successful":true,"transaction_date":"2020-08-05T10:46:21+10:00","response_code":"00","standalone":false,"note_to_payer":"refund
46
+ the rest","invoice_id":"071-PPR-WXEAYHCGZY7DJYZ2","decimal_amount":10.0,"paypal_fee":24,"seller_payable_net_amount":976,"balance_available_for_refund":0,"capture":"071-PPC-RBJV9SSA7PWXVXFB","order":"071-PPO-5ICGTHBIMG9T7D4I"},{"id":"071-PPR-6FOW2YDJYBPSDBNB","amount":100,"refunded":"Approved","message":"Approved","transaction_id":"071-PPR-6FOW2YDJYBPSDBNB","currency":"AUD","successful":true,"transaction_date":"2020-08-05T10:40:07+10:00","response_code":"00","standalone":false,"note_to_payer":"refund
47
+ billing agreement","invoice_id":"071-PPR-6FOW2YDJYBPSDBNB","decimal_amount":1.0,"paypal_fee":2,"seller_payable_net_amount":98,"balance_available_for_refund":0,"capture":"071-PPC-RBJV9SSA7PWXVXFB","order":"071-PPO-5ICGTHBIMG9T7D4I"}],"errors":[],"test":true,"records":5,"total_records":5,"page":1,"total_pages":1}'
48
+ http_version:
49
+ recorded_at: Fri, 07 Aug 2020 00:03:14 GMT
50
+ recorded_with: VCR 3.0.3
@@ -5,37 +5,32 @@ describe FatZebra::Authenticate do
5
5
  subject(:token) { FatZebra::Authenticate.session(valid_3ds_token_payload) }
6
6
 
7
7
  let(:valid_3ds_token_payload) {{
8
- reference_id: 'xxxx-xxxx-xxxx',
9
- confirm_url: 'https://example.com',
10
- order_number: 'xxxx-xxxx-xxxx',
11
- currency: 'AUS',
8
+ currency: 'AUD',
12
9
  amount: 100
13
10
  }}
14
11
 
15
12
  it 'returns JWT with given params' do
16
13
  is_expected.to be_accepted
17
14
  expect(token.jwt).to be_truthy
18
- expect(token.reference_id).to be_truthy
19
15
  end
20
16
 
21
- it 'returns JWT with some params' do
22
- valid_3ds_token_payload.delete(:reference_id)
17
+ it 'returns JWT with no amount' do
18
+ valid_3ds_token_payload.delete(:amount)
23
19
  is_expected.to be_accepted
24
20
  expect(token.jwt).to be_truthy
25
- expect(token.reference_id).to be_truthy
26
21
  end
27
22
 
28
- it 'returns JWT with no params' do
29
- valid_3ds_token_payload.clear
30
- is_expected.to be_accepted
31
- expect(token.jwt).to be_truthy
32
- expect(token.reference_id).to be_truthy
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:/)
33
28
  end
34
29
 
35
30
  it 'returns error when amount is invalid' do
36
31
  valid_3ds_token_payload[:amount] = 'INVALID'
37
32
  is_expected.not_to be_accepted
38
- expect(token.errors).to match(/Amount is invalid/)
33
+ expect(token.errors).to eq(['Amount is invalid'])
39
34
  end
40
35
  end
41
36
 
@@ -43,13 +38,16 @@ describe FatZebra::Authenticate do
43
38
  subject(:decoded) { FatZebra::Authenticate.decode_session(token: jwt) }
44
39
 
45
40
  context 'when token is valid' do
46
- let(:jwt) { FatZebra::Authenticate.session({}).jwt }
41
+ let(:valid_3ds_token_payload) {{
42
+ currency: 'AUD',
43
+ amount: 100
44
+ }}
45
+ let(:jwt) { FatZebra::Authenticate.session(valid_3ds_token_payload).jwt }
47
46
 
48
47
  it 'decodes JWT' do
49
48
  is_expected.to be_accepted
50
- expect(decoded.keys).to include('payload')
51
- expect(decoded.payload).to be_a(Hash)
52
- expect(decoded.errors).not_to be_truthy
49
+ expect(decoded.keys).to include('processor_transaction_id', 'consumer_session_id', 'error_number', 'error_description')
50
+ expect(decoded.errors).to be_empty
53
51
  end
54
52
  end
55
53
 
@@ -58,85 +56,130 @@ describe FatZebra::Authenticate do
58
56
 
59
57
  it 'returns error when invalid token' do
60
58
  is_expected.not_to be_accepted
61
- expect(decoded.errors).to match(/The token is invalid/)
59
+ expect(decoded.errors).to eq(['Decoding JWT failed: The token is invalid'])
62
60
  end
63
61
  end
64
62
  end
65
63
 
66
64
  describe '.authenticate', :vcr do
67
- subject(:authenticate) { FatZebra::Authenticate.authenticate(valid_sca_authenticate_payload) }
65
+ subject(:authenticate) { FatZebra::Authenticate.authenticate(valid_sca_authentication_payload) }
68
66
  let!(:credit_card) { FatZebra::Card.create(valid_credit_card_payload) }
69
67
 
70
68
  context 'with invalid input' do
69
+ before do
70
+ valid_sca_authentication_payload[:sca].merge!(valid_sca_enrollment_payload)
71
+ end
72
+
71
73
  it do
72
- valid_sca_authenticate_payload[:card_token] = 'INVALID'
74
+ valid_sca_authentication_payload[:card_token] = 'INVALID'
73
75
  is_expected.not_to be_accepted
74
- expect(authenticate.errors).to match(/Card not found/)
76
+ expect(authenticate.errors.join).to match(/Card not found/)
75
77
  end
76
78
 
77
79
  it do
78
- valid_sca_authenticate_payload[:sca] = {}
80
+ valid_sca_authentication_payload[:sca] = {}
79
81
  is_expected.not_to be_accepted
80
82
  expect(authenticate.errors.join).to match(/Invalid input data/)
81
83
  end
82
84
 
83
85
  it do
84
- valid_sca_authenticate_payload[:sca][:currency] = 'INVALID'
86
+ valid_sca_authentication_payload[:currency] = 'INVALID'
85
87
  is_expected.not_to be_accepted
86
- expect(authenticate.errors).to match(/3DS lookup request process failed/)
88
+ expect(authenticate.errors.join).to match(/INVALID is not valid for this merchant. Permitted currencies:/)
87
89
  end
88
90
 
89
91
  it do
90
- valid_sca_authenticate_payload[:sca][:amount] = 'INVALID'
92
+ valid_sca_authentication_payload[:amount] = 'INVALID'
91
93
  is_expected.not_to be_accepted
92
- expect(authenticate.errors).to match(/3DS lookup request process failed/)
94
+ expect(authenticate.errors.join).to match(/3DS authenticate request failed: amount must be filled/)
93
95
  end
94
96
  end
95
97
 
96
98
  context 'with frictionless response' do
97
99
  before do
98
100
  valid_credit_card_payload[:card_number] = '4000000000001000'
101
+ valid_sca_authentication_payload[:sca].merge!(valid_sca_enrollment_payload)
99
102
  end
100
103
 
101
104
  it do
102
105
  is_expected.to be_accepted
103
- expect(authenticate.keys).to include('Enrolled', 'ACSUrl', 'CardBin', 'TransactionId')
104
- expect(authenticate.errors).not_to be_truthy
106
+ expect(authenticate.keys).to include('enrolled', 'acs_url', 'version', 'card_bin', 'authentication_transaction_id')
107
+ expect(authenticate.errors).to be_empty
105
108
  end
106
109
 
107
110
  it do
108
- expect(authenticate.Enrolled).to be_truthy
109
- expect(authenticate.CardBin).to be_truthy
110
- expect(authenticate.ErrorNo).to eq('0')
111
- expect(authenticate.ErrorDesc).not_to be_truthy
112
- expect(authenticate.CardBrand).to be_truthy
113
- expect(authenticate.TransactionId).to be_truthy
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
114
115
  end
115
116
  end
116
117
 
117
118
  context 'with challenge response' do
118
119
  before do
119
120
  valid_credit_card_payload[:card_number] = '4000000000001091'
121
+ valid_sca_authentication_payload[:sca].merge!(valid_sca_enrollment_payload)
120
122
  end
121
123
 
122
124
  it do
123
125
  is_expected.to be_accepted
124
- expect(authenticate.keys).to include('Enrolled', 'ACSUrl', 'CardBin', 'TransactionId')
125
- expect(authenticate.errors).not_to be_truthy
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
+ }
126
172
  end
127
-
173
+
128
174
  it do
129
- expect(authenticate.Enrolled).to be_truthy
130
- expect(authenticate.CardBin).to be_truthy
131
- expect(authenticate.ErrorNo).to eq('0')
132
- expect(authenticate.ErrorDesc).not_to be_truthy
133
- expect(authenticate.CardBrand).to be_truthy
134
- expect(authenticate.TransactionId).to be_truthy
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
135
178
  end
136
179
  end
137
180
 
138
181
  context 'validations' do
139
- let(:valid_sca_authenticate_payload) {{}}
182
+ let(:valid_sca_authentication_payload) {{}}
140
183
 
141
184
  it { expect{ authenticate }.to raise_error(FatZebra::RequestValidationError) }
142
185
  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