braintree 4.34.0 → 4.36.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.
- checksums.yaml +4 -4
- data/lib/braintree/apple_pay_card.rb +7 -0
- data/lib/braintree/apple_pay_gateway.rb +43 -0
- data/lib/braintree/base_module.rb +9 -0
- data/lib/braintree/credit_card_verification.rb +2 -0
- data/lib/braintree/customer.rb +2 -2
- data/lib/braintree/customer_gateway.rb +2 -0
- data/lib/braintree/error_codes.rb +20 -0
- data/lib/braintree/gateway.rb +4 -0
- data/lib/braintree/graphql/inputs/billing_address_input.rb +34 -0
- data/lib/braintree/graphql/inputs/create_local_payment_context_input.rb +44 -0
- data/lib/braintree/graphql/inputs/payer_info_input.rb +38 -0
- data/lib/braintree/graphql/inputs/shipping_address_input.rb +34 -0
- data/lib/braintree/local_payment_context.rb +108 -0
- data/lib/braintree/local_payment_context_gateway.rb +132 -0
- data/lib/braintree/local_payment_type.rb +6 -0
- data/lib/braintree/merchant_gateway.rb +16 -16
- data/lib/braintree/monetary_amount.rb +24 -0
- data/lib/braintree/payment_instrument_type.rb +1 -0
- data/lib/braintree/payment_method_parser.rb +1 -0
- data/lib/braintree/successful_result.rb +1 -0
- data/lib/braintree/test/nonce.rb +1 -0
- data/lib/braintree/test/transaction_amounts.rb +1 -0
- data/lib/braintree/transaction/visa_checkout_card_details.rb +2 -0
- data/lib/braintree/transaction.rb +8 -2
- data/lib/braintree/transaction_gateway.rb +12 -5
- data/lib/braintree/transaction_search.rb +1 -0
- data/lib/braintree/validation_error_collection.rb +1 -1
- data/lib/braintree/version.rb +1 -1
- data/lib/braintree/visa_checkout_card.rb +2 -0
- data/lib/braintree.rb +20 -3
- data/spec/integration/braintree/customer_spec.rb +550 -16
- data/spec/integration/braintree/http_spec.rb +1 -1
- data/spec/integration/braintree/local_payment_context_spec.rb +168 -0
- data/spec/integration/braintree/merchant_spec.rb +5 -169
- data/spec/integration/braintree/payment_method_spec.rb +174 -1
- data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +1 -1
- data/spec/integration/braintree/test_transaction_spec.rb +6 -6
- data/spec/integration/braintree/transaction_idempotency_spec.rb +320 -0
- data/spec/integration/braintree/transaction_search_spec.rb +3 -2
- data/spec/integration/braintree/transaction_spec.rb +91 -0
- data/spec/integration/braintree/transaction_us_bank_account_spec.rb +42 -0
- data/spec/integration/braintree/visa_checkout_card_spec.rb +4 -100
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/braintree/credit_card_verification_spec.rb +1 -1
- data/spec/unit/braintree/customer_spec.rb +67 -1
- data/spec/unit/braintree/graphql/billing_address_input_spec.rb +68 -0
- data/spec/unit/braintree/graphql/create_local_payment_context_input_spec.rb +63 -0
- data/spec/unit/braintree/graphql/monetary_amount_input_spec.rb +55 -0
- data/spec/unit/braintree/graphql/payer_info_input_spec.rb +92 -0
- data/spec/unit/braintree/local_payment_context_gateway_spec.rb +149 -0
- data/spec/unit/braintree/local_payment_context_spec.rb +141 -0
- data/spec/unit/braintree/monetary_amount_spec.rb +34 -0
- data/spec/unit/braintree/three_d_secure_info_spec.rb +3 -1
- data/spec/unit/braintree/transaction/apple_pay_details_spec.rb +7 -7
- data/spec/unit/braintree/transaction/google_pay_details_spec.rb +7 -7
- data/spec/unit/braintree/transaction/meta_checkout_card_details_spec.rb +6 -6
- data/spec/unit/braintree/transaction/meta_checkout_token_details_spec.rb +6 -6
- data/spec/unit/braintree/transaction/payment_receipt_spec.rb +4 -4
- data/spec/unit/braintree/transaction/visa_checkout_card_details_spec.rb +6 -6
- data/spec/unit/braintree/transaction_gateway_spec.rb +5 -3
- data/spec/unit/braintree/transaction_spec.rb +31 -0
- data/spec/unit/braintree/visa_checkout_card_spec.rb +1 -0
- data/spec/unit/credit_card_details_spec.rb +6 -6
- data/spec/unit/spec_helper.rb +9 -0
- metadata +23 -6
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
2
|
+
|
|
3
|
+
describe Braintree::Transaction, "idempotency" do
|
|
4
|
+
describe "sale" do
|
|
5
|
+
it "returns original transaction on duplicate request with same api_request_key" do
|
|
6
|
+
api_request_key = "idempotency-key-#{rand(1000000)}"
|
|
7
|
+
|
|
8
|
+
transaction_params = {
|
|
9
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
10
|
+
:api_request_key => api_request_key,
|
|
11
|
+
:credit_card => {
|
|
12
|
+
:number => "4111111111111111",
|
|
13
|
+
:expiration_date => "05/2035"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
result1 = Braintree::Transaction.sale(transaction_params)
|
|
18
|
+
expect(result1).to be_success
|
|
19
|
+
transaction1 = result1.transaction
|
|
20
|
+
expect(transaction1.id).not_to be_nil
|
|
21
|
+
|
|
22
|
+
result2 = Braintree::Transaction.sale(transaction_params)
|
|
23
|
+
expect(result2).to be_success
|
|
24
|
+
transaction2 = result2.transaction
|
|
25
|
+
|
|
26
|
+
expect(transaction1.status).to eq(transaction2.status)
|
|
27
|
+
expect(transaction1.id).to eq(transaction2.id)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "fails when different request used with same key" do
|
|
31
|
+
api_request_key = "idempotency-key-#{rand(1000000)}"
|
|
32
|
+
|
|
33
|
+
transaction_params1 = {
|
|
34
|
+
:amount => "100.00",
|
|
35
|
+
:api_request_key => api_request_key,
|
|
36
|
+
:credit_card => {
|
|
37
|
+
:number => "4111111111111111",
|
|
38
|
+
:expiration_date => "05/2035"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
result1 = Braintree::Transaction.sale(transaction_params1)
|
|
43
|
+
expect(result1).to be_success
|
|
44
|
+
|
|
45
|
+
transaction_params2 = {
|
|
46
|
+
:amount => "200.00",
|
|
47
|
+
:api_request_key => api_request_key,
|
|
48
|
+
:credit_card => {
|
|
49
|
+
:number => "4111111111111111",
|
|
50
|
+
:expiration_date => "05/2035"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
result2 = Braintree::Transaction.sale(transaction_params2)
|
|
55
|
+
|
|
56
|
+
expect(result2).not_to be_success
|
|
57
|
+
expect(result2.errors).not_to be_nil
|
|
58
|
+
errors = result2.errors.for(:transaction)
|
|
59
|
+
expect(errors.size).to be > 0
|
|
60
|
+
expect(errors.first.code).to eq(Braintree::ErrorCodes::Transaction::ApiRequestKeyCanBeReusedOnlyWithTheSameRequest)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "same sales with different api_request_keys create different transactions" do
|
|
64
|
+
api_request_key1 = "idempotency-key-#{rand(1000000)}"
|
|
65
|
+
|
|
66
|
+
transaction_params1 = {
|
|
67
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
68
|
+
:api_request_key => api_request_key1,
|
|
69
|
+
:credit_card => {
|
|
70
|
+
:number => "4111111111111111",
|
|
71
|
+
:expiration_date => "05/2035"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
result1 = Braintree::Transaction.sale(transaction_params1)
|
|
76
|
+
expect(result1).to be_success
|
|
77
|
+
transaction1 = result1.transaction
|
|
78
|
+
expect(transaction1.id).not_to be_nil
|
|
79
|
+
|
|
80
|
+
api_request_key2 = "idempotency-key-different-#{rand(1000000)}"
|
|
81
|
+
transaction_params2 = {
|
|
82
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
83
|
+
:api_request_key => api_request_key2,
|
|
84
|
+
:credit_card => {
|
|
85
|
+
:number => "4111111111111111",
|
|
86
|
+
:expiration_date => "05/2035"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
result2 = Braintree::Transaction.sale(transaction_params2)
|
|
91
|
+
expect(result2).to be_success
|
|
92
|
+
transaction2 = result2.transaction
|
|
93
|
+
|
|
94
|
+
expect(transaction1.id).not_to eq(transaction2.id)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "fails when api_request_key is too big" do
|
|
98
|
+
transaction_params1 = {
|
|
99
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
100
|
+
:api_request_key => "x" * 255,
|
|
101
|
+
:credit_card => {
|
|
102
|
+
:number => "4111111111111111",
|
|
103
|
+
:expiration_date => "05/2035"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
result1 = Braintree::Transaction.sale(transaction_params1)
|
|
108
|
+
expect(result1).to be_success
|
|
109
|
+
|
|
110
|
+
transaction_params2 = {
|
|
111
|
+
:amount => "200.00",
|
|
112
|
+
:api_request_key => "x" * 256,
|
|
113
|
+
:credit_card => {
|
|
114
|
+
:number => "4111111111111111",
|
|
115
|
+
:expiration_date => "05/2035"
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
result2 = Braintree::Transaction.sale(transaction_params2)
|
|
120
|
+
|
|
121
|
+
expect(result2).not_to be_success
|
|
122
|
+
expect(result2.errors).not_to be_nil
|
|
123
|
+
errors = result2.errors.for(:transaction)
|
|
124
|
+
expect(errors.size).to be > 0
|
|
125
|
+
expect(errors.first.code).to eq(Braintree::ErrorCodes::Transaction::ApiRequestKeyTooLong)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
describe "credit" do
|
|
130
|
+
it "returns original on duplicate request with same api_request_key" do
|
|
131
|
+
api_request_key = "credit-idempotency-key-#{rand(1000000)}"
|
|
132
|
+
|
|
133
|
+
transaction_params = {
|
|
134
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
135
|
+
:api_request_key => api_request_key,
|
|
136
|
+
:credit_card => {
|
|
137
|
+
:number => "4111111111111111",
|
|
138
|
+
:expiration_date => "05/2035"
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
credit_result1 = Braintree::Transaction.credit(transaction_params)
|
|
143
|
+
expect(credit_result1).to be_success
|
|
144
|
+
credit_transaction1 = credit_result1.transaction
|
|
145
|
+
expect(credit_transaction1.type).to eq(Braintree::Transaction::Type::Credit)
|
|
146
|
+
expect(credit_transaction1.id).not_to be_nil
|
|
147
|
+
|
|
148
|
+
credit_result2 = Braintree::Transaction.credit(transaction_params)
|
|
149
|
+
expect(credit_result2).to be_success
|
|
150
|
+
credit_transaction2 = credit_result2.transaction
|
|
151
|
+
|
|
152
|
+
expect(credit_transaction1.id).to eq(credit_transaction2.id)
|
|
153
|
+
expect(credit_transaction1.type).to eq(credit_transaction2.type)
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
describe "submit_for_partial_settlement" do
|
|
158
|
+
it "returns original on duplicate request with same api_request_key" do
|
|
159
|
+
api_request_key = "partial-settlement-idempotency-key-#{rand(1000000)}"
|
|
160
|
+
|
|
161
|
+
sale_request = {
|
|
162
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
163
|
+
:credit_card => {
|
|
164
|
+
:number => "4111111111111111",
|
|
165
|
+
:expiration_date => "05/2035"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
sale_result = Braintree::Transaction.sale(sale_request)
|
|
170
|
+
expect(sale_result).to be_success
|
|
171
|
+
transaction_id = sale_result.transaction.id
|
|
172
|
+
|
|
173
|
+
partial_amount = "50.00"
|
|
174
|
+
partial_settlement_options = {
|
|
175
|
+
:api_request_key => api_request_key
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
partial_settlement_result1 = Braintree::Transaction.submit_for_partial_settlement(
|
|
179
|
+
transaction_id,
|
|
180
|
+
partial_amount,
|
|
181
|
+
partial_settlement_options,
|
|
182
|
+
)
|
|
183
|
+
expect(partial_settlement_result1).to be_success
|
|
184
|
+
partial_settlement_transaction1 = partial_settlement_result1.transaction
|
|
185
|
+
expect(partial_settlement_transaction1.amount).to eq(BigDecimal(partial_amount))
|
|
186
|
+
expect(partial_settlement_transaction1.id).not_to be_nil
|
|
187
|
+
|
|
188
|
+
partial_settlement_result2 = Braintree::Transaction.submit_for_partial_settlement(
|
|
189
|
+
transaction_id,
|
|
190
|
+
partial_amount,
|
|
191
|
+
partial_settlement_options,
|
|
192
|
+
)
|
|
193
|
+
expect(partial_settlement_result2).to be_success
|
|
194
|
+
partial_settlement_transaction2 = partial_settlement_result2.transaction
|
|
195
|
+
|
|
196
|
+
expect(partial_settlement_transaction1.id).to eq(partial_settlement_transaction2.id)
|
|
197
|
+
expect(partial_settlement_transaction1.amount).to eq(partial_settlement_transaction2.amount)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
describe "submit_for_settlement" do
|
|
202
|
+
it "returns original on duplicate request with same api_request_key" do
|
|
203
|
+
api_request_key = "settlement-idempotency-key-#{rand(1000000)}"
|
|
204
|
+
|
|
205
|
+
sale_request = {
|
|
206
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
207
|
+
:credit_card => {
|
|
208
|
+
:number => "4111111111111111",
|
|
209
|
+
:expiration_date => "05/2035"
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
sale_result = Braintree::Transaction.sale(sale_request)
|
|
214
|
+
expect(sale_result).to be_success
|
|
215
|
+
transaction_id = sale_result.transaction.id
|
|
216
|
+
original_amount = sale_result.transaction.amount
|
|
217
|
+
|
|
218
|
+
settlement_options = {
|
|
219
|
+
:api_request_key => api_request_key
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
settlement_result1 = Braintree::Transaction.submit_for_settlement(
|
|
223
|
+
transaction_id,
|
|
224
|
+
nil,
|
|
225
|
+
settlement_options,
|
|
226
|
+
)
|
|
227
|
+
expect(settlement_result1).to be_success
|
|
228
|
+
settlement_transaction1 = settlement_result1.transaction
|
|
229
|
+
expect(settlement_transaction1.amount).to eq(original_amount)
|
|
230
|
+
expect(settlement_transaction1.id).not_to be_nil
|
|
231
|
+
|
|
232
|
+
settlement_result2 = Braintree::Transaction.submit_for_settlement(
|
|
233
|
+
transaction_id,
|
|
234
|
+
nil,
|
|
235
|
+
settlement_options,
|
|
236
|
+
)
|
|
237
|
+
expect(settlement_result2).to be_success
|
|
238
|
+
settlement_transaction2 = settlement_result2.transaction
|
|
239
|
+
|
|
240
|
+
expect(settlement_transaction1.id).to eq(settlement_transaction2.id)
|
|
241
|
+
expect(settlement_transaction1.amount).to eq(settlement_transaction2.amount)
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
describe "void" do
|
|
246
|
+
it "returns original void on duplicate request with same api_request_key" do
|
|
247
|
+
api_request_key = "void-idempotency-key-#{rand(1000000)}"
|
|
248
|
+
|
|
249
|
+
sale_request = {
|
|
250
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
251
|
+
:credit_card => {
|
|
252
|
+
:number => "4111111111111111",
|
|
253
|
+
:expiration_date => "05/2035"
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
sale_result = Braintree::Transaction.sale(sale_request)
|
|
258
|
+
expect(sale_result).to be_success
|
|
259
|
+
transaction_id = sale_result.transaction.id
|
|
260
|
+
|
|
261
|
+
void_options = {
|
|
262
|
+
:api_request_key => api_request_key
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
void_result1 = Braintree::Transaction.void(transaction_id, void_options)
|
|
266
|
+
expect(void_result1).to be_success
|
|
267
|
+
voided_transaction1 = void_result1.transaction
|
|
268
|
+
expect(voided_transaction1.status).to eq(Braintree::Transaction::Status::Voided)
|
|
269
|
+
|
|
270
|
+
void_result2 = Braintree::Transaction.void(transaction_id, void_options)
|
|
271
|
+
expect(void_result2).to be_success
|
|
272
|
+
voided_transaction2 = void_result2.transaction
|
|
273
|
+
|
|
274
|
+
expect(voided_transaction1.id).to eq(voided_transaction2.id)
|
|
275
|
+
expect(voided_transaction1.status).to eq(voided_transaction2.status)
|
|
276
|
+
expect(voided_transaction2.status).to eq(Braintree::Transaction::Status::Voided)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
|
|
280
|
+
describe "refund" do
|
|
281
|
+
it "returns original refund on duplicate request with same api_request_key" do
|
|
282
|
+
api_request_key = "refund-idempotency-key-#{rand(1000000)}"
|
|
283
|
+
|
|
284
|
+
sale_request = {
|
|
285
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
286
|
+
:credit_card => {
|
|
287
|
+
:number => "4111111111111111",
|
|
288
|
+
:expiration_date => "05/2035"
|
|
289
|
+
},
|
|
290
|
+
:options => {
|
|
291
|
+
:submit_for_settlement => true
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
sale_result = Braintree::Transaction.sale(sale_request)
|
|
296
|
+
expect(sale_result).to be_success
|
|
297
|
+
transaction_id = sale_result.transaction.id
|
|
298
|
+
|
|
299
|
+
settled_result = Braintree::TestTransaction.settle(transaction_id)
|
|
300
|
+
expect(settled_result.transaction.status).to eq(Braintree::Transaction::Status::Settled)
|
|
301
|
+
|
|
302
|
+
refund_options = {
|
|
303
|
+
:api_request_key => api_request_key
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
refund_result1 = Braintree::Transaction.refund(transaction_id, refund_options)
|
|
307
|
+
expect(refund_result1).to be_success
|
|
308
|
+
refund_transaction1 = refund_result1.transaction
|
|
309
|
+
expect(refund_transaction1.type).to eq(Braintree::Transaction::Type::Credit)
|
|
310
|
+
expect(refund_transaction1.id).not_to be_nil
|
|
311
|
+
|
|
312
|
+
refund_result2 = Braintree::Transaction.refund(transaction_id, refund_options)
|
|
313
|
+
expect(refund_result2).to be_success
|
|
314
|
+
refund_transaction2 = refund_result2.transaction
|
|
315
|
+
|
|
316
|
+
expect(refund_transaction1.id).to eq(refund_transaction2.id)
|
|
317
|
+
expect(refund_transaction1.type).to eq(refund_transaction2.type)
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
end
|
|
@@ -69,6 +69,7 @@ describe Braintree::Transaction, "search" do
|
|
|
69
69
|
credit_card = Braintree::CreditCard.find(token)
|
|
70
70
|
|
|
71
71
|
search_criteria = {
|
|
72
|
+
:acquirer_reference_number => transaction.acquirer_reference_number,
|
|
72
73
|
:billing_company => "Braintree",
|
|
73
74
|
:billing_country_name => "United States of America",
|
|
74
75
|
:billing_extended_address => "Suite 123",
|
|
@@ -207,9 +208,9 @@ describe Braintree::Transaction, "search" do
|
|
|
207
208
|
end
|
|
208
209
|
item = collection.find { |t| t.id == transaction_id }
|
|
209
210
|
expect(item.ach_return_code).to eq("RJCT")
|
|
210
|
-
expect(item.ach_reject_reason).to eq("Bank accounts located outside of the U.S. are not supported
|
|
211
|
+
expect(item.ach_reject_reason).to eq("Bank accounts located outside of the U.S. are not supported")
|
|
211
212
|
expect(item.ach_return_responses.first[:reason_code]).to eq("RJCT")
|
|
212
|
-
expect(item.ach_return_responses.first[:reject_reason]).to eq("Bank accounts located outside of the U.S. are not supported
|
|
213
|
+
expect(item.ach_return_responses.first[:reject_reason]).to eq("Bank accounts located outside of the U.S. are not supported")
|
|
213
214
|
end
|
|
214
215
|
|
|
215
216
|
it "searches on reason_codes" do
|
|
@@ -812,6 +812,22 @@ describe Braintree::Transaction do
|
|
|
812
812
|
expect(result.transaction.foreign_retailer).to be_nil
|
|
813
813
|
end
|
|
814
814
|
|
|
815
|
+
it "returns true for partial_authorization if the processor_response_code is 1004" do
|
|
816
|
+
result = Braintree::Transaction.create(
|
|
817
|
+
:type => "sale",
|
|
818
|
+
:amount => Braintree::Test::TransactionAmounts::PartiallyAuthorized,
|
|
819
|
+
:accept_partial_authorization => true,
|
|
820
|
+
:credit_card => {
|
|
821
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
822
|
+
:expiration_date => "05/2029"
|
|
823
|
+
},
|
|
824
|
+
)
|
|
825
|
+
|
|
826
|
+
expect(result.success?).to eq(true)
|
|
827
|
+
expect(result.transaction.processor_response_code).to eq("1004")
|
|
828
|
+
expect(result.transaction.partially_authorized).to eq(true)
|
|
829
|
+
end
|
|
830
|
+
|
|
815
831
|
it "returns nil when foreign_retailer param is nil" do
|
|
816
832
|
result = Braintree::Transaction.create(
|
|
817
833
|
:type => "sale",
|
|
@@ -5308,6 +5324,64 @@ describe Braintree::Transaction do
|
|
|
5308
5324
|
expect(transaction.shipping_details.international_phone[:national_number]).to eq("3121234567")
|
|
5309
5325
|
end
|
|
5310
5326
|
|
|
5327
|
+
it "accepts customer international_phone" do
|
|
5328
|
+
result = Braintree::Transaction.sale(
|
|
5329
|
+
:amount => "100.00",
|
|
5330
|
+
:credit_card => {
|
|
5331
|
+
:number => "5105105105105100",
|
|
5332
|
+
:expiration_date => "05/2011",
|
|
5333
|
+
},
|
|
5334
|
+
:customer => {
|
|
5335
|
+
:first_name => "Dan",
|
|
5336
|
+
:last_name => "Smith",
|
|
5337
|
+
:international_phone => {:country_code => "1", :national_number => "3121234567"},
|
|
5338
|
+
},
|
|
5339
|
+
)
|
|
5340
|
+
|
|
5341
|
+
expect(result.success?).to eq(true)
|
|
5342
|
+
transaction = result.transaction
|
|
5343
|
+
expect(transaction.customer_details.first_name).to eq("Dan")
|
|
5344
|
+
expect(transaction.customer_details.last_name).to eq("Smith")
|
|
5345
|
+
expect(transaction.customer_details.international_phone[:country_code]).to eq("1")
|
|
5346
|
+
expect(transaction.customer_details.international_phone[:national_number]).to eq("3121234567")
|
|
5347
|
+
end
|
|
5348
|
+
|
|
5349
|
+
it "returns validation error for an invalid international_phone country code" do
|
|
5350
|
+
result = Braintree::Transaction.sale(
|
|
5351
|
+
:amount => "100.00",
|
|
5352
|
+
:credit_card => {
|
|
5353
|
+
:number => "5105105105105100",
|
|
5354
|
+
:expiration_date => "05/2011",
|
|
5355
|
+
},
|
|
5356
|
+
:customer => {
|
|
5357
|
+
:first_name => "Dan",
|
|
5358
|
+
:last_name => "Smith",
|
|
5359
|
+
:international_phone => {:country_code => "1111", :national_number => "3121234567"},
|
|
5360
|
+
},
|
|
5361
|
+
)
|
|
5362
|
+
|
|
5363
|
+
expect(result.success?).to eq(false)
|
|
5364
|
+
expect(result.errors.map(&:code)).to include(Braintree::ErrorCodes::Customer::InternationalPhoneCountryCodeIsInvalid)
|
|
5365
|
+
end
|
|
5366
|
+
|
|
5367
|
+
it "returns validation error for an invalid international_phone national number" do
|
|
5368
|
+
result = Braintree::Transaction.sale(
|
|
5369
|
+
:amount => "100.00",
|
|
5370
|
+
:credit_card => {
|
|
5371
|
+
:number => "5105105105105100",
|
|
5372
|
+
:expiration_date => "05/2011",
|
|
5373
|
+
},
|
|
5374
|
+
:customer => {
|
|
5375
|
+
:first_name => "Dan",
|
|
5376
|
+
:last_name => "Smith",
|
|
5377
|
+
:international_phone => {:country_code => "1", :national_number => "31212345611111"},
|
|
5378
|
+
},
|
|
5379
|
+
)
|
|
5380
|
+
|
|
5381
|
+
expect(result.success?).to eq(false)
|
|
5382
|
+
expect(result.errors.map(&:code)).to include(Braintree::ErrorCodes::Customer::InternationalPhoneNationalNumberIsInvalid)
|
|
5383
|
+
end
|
|
5384
|
+
|
|
5311
5385
|
it "accepts processing_merchant_category_code" do
|
|
5312
5386
|
result = Braintree::Transaction.sale(
|
|
5313
5387
|
:amount => "100.00",
|
|
@@ -7885,4 +7959,21 @@ describe Braintree::Transaction do
|
|
|
7885
7959
|
expect(transaction.upcoming_retry_date).to eq(tomorrow.to_s)
|
|
7886
7960
|
end
|
|
7887
7961
|
end
|
|
7962
|
+
|
|
7963
|
+
context "Surcharge Amount" do
|
|
7964
|
+
it "accepts surcharge_amount field" do
|
|
7965
|
+
result = Braintree::Transaction.create(
|
|
7966
|
+
:type => "sale",
|
|
7967
|
+
:amount => "10.00",
|
|
7968
|
+
:surcharge_amount => "1.00",
|
|
7969
|
+
:credit_card => {
|
|
7970
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
|
7971
|
+
:expiration_date => "05/2029"
|
|
7972
|
+
},
|
|
7973
|
+
)
|
|
7974
|
+
|
|
7975
|
+
expect(result.success?).to eq(true)
|
|
7976
|
+
expect(result.transaction.surcharge_amount).to eq(BigDecimal("1.00"))
|
|
7977
|
+
end
|
|
7978
|
+
end
|
|
7888
7979
|
end
|
|
@@ -143,6 +143,25 @@ describe Braintree::Transaction do
|
|
|
143
143
|
expect(transaction.us_bank_account_details.ach_mandate.accepted_at).to be_a Time
|
|
144
144
|
end
|
|
145
145
|
|
|
146
|
+
it "returns ach_type and requested_ach_type on transaction create" do
|
|
147
|
+
result = Braintree::Transaction.create(
|
|
148
|
+
:type => "sale",
|
|
149
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
|
150
|
+
:merchant_account_id => SpecHelper::UsBankMerchantAccountId,
|
|
151
|
+
:payment_method_nonce => non_plaid_nonce,
|
|
152
|
+
:options => {
|
|
153
|
+
:submit_for_settlement => true,
|
|
154
|
+
:us_bank_account => {
|
|
155
|
+
:ach_type => "same_day",
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
)
|
|
159
|
+
expect(result.success?).to eq(true)
|
|
160
|
+
# if the test is ran before 2pm - it returns 'same_day', otherwise 'standard'
|
|
161
|
+
expect(result.transaction.ach_type).to eq("same_day").or eq("standard")
|
|
162
|
+
expect(result.transaction.requested_ach_type).to eq("same_day")
|
|
163
|
+
end
|
|
164
|
+
|
|
146
165
|
it "sale fails for invalid nonce" do
|
|
147
166
|
result = Braintree::Transaction.create(
|
|
148
167
|
:type => "sale",
|
|
@@ -192,4 +211,27 @@ describe Braintree::Transaction do
|
|
|
192
211
|
end
|
|
193
212
|
end
|
|
194
213
|
end
|
|
214
|
+
|
|
215
|
+
describe "self.find" do
|
|
216
|
+
it "returns ach_type and requested_ach_type for same_day ach with same_day requested" do
|
|
217
|
+
transaction = Braintree::Transaction.find("sameday_ach_sameday_requested")
|
|
218
|
+
|
|
219
|
+
expect(transaction.ach_type).to eq("same_day")
|
|
220
|
+
expect(transaction.requested_ach_type).to eq("same_day")
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
it "returns ach_type and requested_ach_type for standard ach with same_day requested" do
|
|
224
|
+
transaction = Braintree::Transaction.find("standard_ach_sameday_requested")
|
|
225
|
+
|
|
226
|
+
expect(transaction.ach_type).to eq("standard")
|
|
227
|
+
expect(transaction.requested_ach_type).to eq("same_day")
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
it "returns ach_type and requested_ach_type for standard ach with standard requested" do
|
|
231
|
+
transaction = Braintree::Transaction.find("standard_ach_standard_requested")
|
|
232
|
+
|
|
233
|
+
expect(transaction.ach_type).to eq("standard")
|
|
234
|
+
expect(transaction.requested_ach_type).to eq("standard")
|
|
235
|
+
end
|
|
236
|
+
end
|
|
195
237
|
end
|
|
@@ -1,110 +1,14 @@
|
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + "/client_api/spec_helper")
|
|
3
3
|
|
|
4
|
+
# DEPRECATED: Visa Checkout is no longer supported for creating new transactions.
|
|
5
|
+
# Search functionality is retained for historical transactions only.
|
|
4
6
|
describe Braintree::VisaCheckoutCard do
|
|
5
|
-
it "can
|
|
6
|
-
customer = Braintree::Customer.create!
|
|
7
|
-
|
|
8
|
-
result = Braintree::PaymentMethod.create(
|
|
9
|
-
:payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutDiscover,
|
|
10
|
-
:customer_id => customer.id,
|
|
11
|
-
)
|
|
12
|
-
expect(result).to be_success
|
|
13
|
-
|
|
14
|
-
visa_checkout_card = result.payment_method
|
|
15
|
-
expect(visa_checkout_card).to be_a(Braintree::VisaCheckoutCard)
|
|
16
|
-
expect(visa_checkout_card.call_id).to eq("abc123")
|
|
17
|
-
expect(visa_checkout_card.billing_address).not_to be_nil
|
|
18
|
-
expect(visa_checkout_card.bin).not_to be_nil
|
|
19
|
-
expect(visa_checkout_card.card_type).not_to be_nil
|
|
20
|
-
expect(visa_checkout_card.cardholder_name).not_to be_nil
|
|
21
|
-
expect(visa_checkout_card.commercial).not_to be_nil
|
|
22
|
-
expect(visa_checkout_card.country_of_issuance).not_to be_nil
|
|
23
|
-
expect(visa_checkout_card.created_at).not_to be_nil
|
|
24
|
-
expect(visa_checkout_card.customer_id).not_to be_nil
|
|
25
|
-
expect(visa_checkout_card.customer_location).not_to be_nil
|
|
26
|
-
expect(visa_checkout_card.debit).not_to be_nil
|
|
27
|
-
expect(visa_checkout_card.default?).not_to be_nil
|
|
28
|
-
expect(visa_checkout_card.durbin_regulated).not_to be_nil
|
|
29
|
-
expect(visa_checkout_card.expiration_date).not_to be_nil
|
|
30
|
-
expect(visa_checkout_card.expiration_month).not_to be_nil
|
|
31
|
-
expect(visa_checkout_card.expiration_year).not_to be_nil
|
|
32
|
-
expect(visa_checkout_card.expired?).not_to be_nil
|
|
33
|
-
expect(visa_checkout_card.healthcare).not_to be_nil
|
|
34
|
-
expect(visa_checkout_card.image_url).not_to be_nil
|
|
35
|
-
expect(visa_checkout_card.issuing_bank).not_to be_nil
|
|
36
|
-
expect(visa_checkout_card.last_4).not_to be_nil
|
|
37
|
-
expect(visa_checkout_card.payroll).not_to be_nil
|
|
38
|
-
expect(visa_checkout_card.prepaid).not_to be_nil
|
|
39
|
-
expect(visa_checkout_card.product_id).not_to be_nil
|
|
40
|
-
expect(visa_checkout_card.subscriptions).not_to be_nil
|
|
41
|
-
expect(visa_checkout_card.token).not_to be_nil
|
|
42
|
-
expect(visa_checkout_card.unique_number_identifier).not_to be_nil
|
|
43
|
-
expect(visa_checkout_card.updated_at).not_to be_nil
|
|
44
|
-
|
|
45
|
-
customer = Braintree::Customer.find(customer.id)
|
|
46
|
-
expect(customer.visa_checkout_cards.size).to eq(1)
|
|
47
|
-
expect(customer.visa_checkout_cards.first).to eq(visa_checkout_card)
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "can create with verification" do
|
|
51
|
-
customer = Braintree::Customer.create!
|
|
52
|
-
|
|
53
|
-
result = Braintree::PaymentMethod.create(
|
|
54
|
-
:payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutDiscover,
|
|
55
|
-
:customer_id => customer.id,
|
|
56
|
-
:options => {:verify_card => true},
|
|
57
|
-
)
|
|
58
|
-
expect(result).to be_success
|
|
59
|
-
expect(result.payment_method.verification.status).to eq(Braintree::CreditCardVerification::Status::Verified)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
it "can search for transactions" do
|
|
63
|
-
transaction_create_result = Braintree::Transaction.sale(
|
|
64
|
-
:payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutDiscover,
|
|
65
|
-
:amount => "47.00",
|
|
66
|
-
)
|
|
67
|
-
expect(transaction_create_result).to be_success
|
|
68
|
-
transaction_id = transaction_create_result.transaction.id
|
|
69
|
-
|
|
7
|
+
it "can search by payment instrument type" do
|
|
70
8
|
search_results = Braintree::Transaction.search do |search|
|
|
71
|
-
search.id.is transaction_id
|
|
72
9
|
search.payment_instrument_type.is Braintree::PaymentInstrumentType::VisaCheckoutCard
|
|
73
10
|
end
|
|
74
|
-
expect(search_results.first.id).to eq(transaction_id)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it "can create transaction from nonce and vault" do
|
|
78
|
-
customer = Braintree::Customer.create!
|
|
79
|
-
|
|
80
|
-
result = Braintree::Transaction.sale(
|
|
81
|
-
:payment_method_nonce => Braintree::Test::Nonce::VisaCheckoutDiscover,
|
|
82
|
-
:customer_id => customer.id,
|
|
83
|
-
:amount => "47.00",
|
|
84
|
-
:options => {:store_in_vault => true},
|
|
85
|
-
)
|
|
86
|
-
expect(result).to be_success
|
|
87
11
|
|
|
88
|
-
|
|
89
|
-
expect(visa_checkout_card_details.call_id).to eq("abc123")
|
|
90
|
-
expect(visa_checkout_card_details.bin).not_to be_nil
|
|
91
|
-
expect(visa_checkout_card_details.card_type).not_to be_nil
|
|
92
|
-
expect(visa_checkout_card_details.cardholder_name).not_to be_nil
|
|
93
|
-
expect(visa_checkout_card_details.commercial).not_to be_nil
|
|
94
|
-
expect(visa_checkout_card_details.country_of_issuance).not_to be_nil
|
|
95
|
-
expect(visa_checkout_card_details.customer_location).not_to be_nil
|
|
96
|
-
expect(visa_checkout_card_details.debit).not_to be_nil
|
|
97
|
-
expect(visa_checkout_card_details.durbin_regulated).not_to be_nil
|
|
98
|
-
expect(visa_checkout_card_details.expiration_date).not_to be_nil
|
|
99
|
-
expect(visa_checkout_card_details.expiration_month).not_to be_nil
|
|
100
|
-
expect(visa_checkout_card_details.expiration_year).not_to be_nil
|
|
101
|
-
expect(visa_checkout_card_details.healthcare).not_to be_nil
|
|
102
|
-
expect(visa_checkout_card_details.image_url).not_to be_nil
|
|
103
|
-
expect(visa_checkout_card_details.issuing_bank).not_to be_nil
|
|
104
|
-
expect(visa_checkout_card_details.last_4).not_to be_nil
|
|
105
|
-
expect(visa_checkout_card_details.payroll).not_to be_nil
|
|
106
|
-
expect(visa_checkout_card_details.prepaid).not_to be_nil
|
|
107
|
-
expect(visa_checkout_card_details.product_id).not_to be_nil
|
|
108
|
-
expect(visa_checkout_card_details.token).not_to be_nil
|
|
12
|
+
expect(search_results).not_to be_nil
|
|
109
13
|
end
|
|
110
14
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -3,6 +3,7 @@ unless defined?(SPEC_HELPER_LOADED)
|
|
|
3
3
|
project_root = File.expand_path(File.dirname(__FILE__) + "/..")
|
|
4
4
|
require "rubygems"
|
|
5
5
|
require "bundler/setup"
|
|
6
|
+
|
|
6
7
|
require "rspec"
|
|
7
8
|
require "rspec/retry"
|
|
8
9
|
require "pry"
|
|
@@ -42,6 +43,7 @@ unless defined?(SPEC_HELPER_LOADED)
|
|
|
42
43
|
HiperBRLMerchantAccountId = "hiper_brl"
|
|
43
44
|
NonDefaultMerchantAccountId = "sandbox_credit_card_non_default"
|
|
44
45
|
PinlessDebitMerchantAccountId = "pinless_debit"
|
|
46
|
+
SuspendedAccount = "suspended_account"
|
|
45
47
|
ThreeDSecureMerchantAccountId = "three_d_secure_merchant_account"
|
|
46
48
|
UsBankMerchantAccountId = "us_bank_merchant_account"
|
|
47
49
|
|
|
@@ -19,7 +19,7 @@ describe Braintree::CreditCardVerification do
|
|
|
19
19
|
:network_response_code => "05",
|
|
20
20
|
:network_response_text => "Do not Honor",
|
|
21
21
|
)
|
|
22
|
-
expect(verification.inspect).to eq(%(#<Braintree::CreditCardVerification amount: "12.45", ani_first_name_response_code: "I", ani_last_name_response_code: "I", avs_error_response_code: "I", avs_postal_code_response_code: "I", avs_street_address_response_code: "I", billing: nil, created_at: nil, credit_card: nil, currency_iso_code: "USD", cvv_response_code: "I", gateway_rejection_reason: nil, id: nil, merchant_account_id: "some_id", network_response_code: "05", network_response_text: "Do not Honor", processor_response_code: "2000", processor_response_text: "Do Not Honor", status: "verified">))
|
|
22
|
+
expect(verification.inspect).to eq(%(#<Braintree::CreditCardVerification amount: "12.45", ani_first_name_response_code: "I", ani_last_name_response_code: "I", apple_pay: nil, avs_error_response_code: "I", avs_postal_code_response_code: "I", avs_street_address_response_code: "I", billing: nil, created_at: nil, credit_card: nil, currency_iso_code: "USD", cvv_response_code: "I", gateway_rejection_reason: nil, id: nil, merchant_account_id: "some_id", network_response_code: "05", network_response_text: "Do not Honor", processor_response_code: "2000", processor_response_text: "Do Not Honor", status: "verified">))
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
it "has a status" do
|