braintree 2.104.0 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -1
- data/braintree.gemspec +6 -3
- data/lib/braintree.rb +5 -17
- data/lib/braintree/address.rb +0 -22
- data/lib/braintree/base_module.rb +6 -0
- data/lib/braintree/bin_data.rb +9 -2
- data/lib/braintree/configuration.rb +1 -1
- data/lib/braintree/credit_card.rb +0 -75
- data/lib/braintree/credit_card_gateway.rb +4 -33
- data/lib/braintree/credit_card_verification.rb +13 -0
- data/lib/braintree/customer.rb +3 -74
- data/lib/braintree/customer_gateway.rb +0 -23
- data/lib/braintree/dispute.rb +1 -7
- data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
- data/lib/braintree/dispute_gateway.rb +2 -7
- data/lib/braintree/error_codes.rb +144 -170
- data/lib/braintree/exceptions.rb +5 -3
- data/lib/braintree/gateway.rb +0 -14
- data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +1 -2
- data/lib/braintree/local_payment_completed.rb +1 -1
- data/lib/braintree/merchant_account_gateway.rb +2 -0
- data/lib/braintree/payment_instrument_type.rb +1 -5
- data/lib/braintree/payment_method_gateway.rb +5 -10
- data/lib/braintree/payment_method_parser.rb +1 -8
- data/lib/braintree/resource_collection.rb +8 -3
- data/lib/braintree/risk_data.rb +3 -1
- data/lib/braintree/subscription.rb +5 -5
- data/lib/braintree/successful_result.rb +0 -1
- data/lib/braintree/test/credit_card.rb +1 -0
- data/lib/braintree/test/nonce.rb +4 -23
- data/lib/braintree/three_d_secure_info.rb +22 -12
- data/lib/braintree/transaction.rb +12 -80
- data/lib/braintree/transaction/disbursement_details.rb +1 -0
- data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
- data/lib/braintree/transaction/installment.rb +28 -0
- data/lib/braintree/transaction/installment/adjustment.rb +33 -0
- data/lib/braintree/transaction/paypal_details.rb +1 -0
- data/lib/braintree/transaction/subscription_details.rb +2 -0
- data/lib/braintree/transaction_gateway.rb +14 -21
- data/lib/braintree/transaction_search.rb +0 -1
- data/lib/braintree/util.rb +17 -2
- data/lib/braintree/version.rb +2 -2
- data/lib/braintree/webhook_notification.rb +0 -10
- data/lib/braintree/webhook_testing_gateway.rb +0 -43
- data/lib/braintree/xml/libxml.rb +1 -0
- data/lib/braintree/xml/parser.rb +11 -34
- data/spec/integration/braintree/address_spec.rb +2 -89
- data/spec/integration/braintree/client_api/spec_helper.rb +0 -26
- data/spec/integration/braintree/credit_card_spec.rb +13 -476
- data/spec/integration/braintree/customer_spec.rb +189 -362
- data/spec/integration/braintree/dispute_search_spec.rb +3 -3
- data/spec/integration/braintree/dispute_spec.rb +1 -2
- data/spec/integration/braintree/merchant_spec.rb +2 -2
- data/spec/integration/braintree/payment_method_spec.rb +254 -120
- data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +8 -4
- data/spec/integration/braintree/subscription_spec.rb +11 -16
- data/spec/integration/braintree/transaction_search_spec.rb +3 -3
- data/spec/integration/braintree/transaction_spec.rb +324 -550
- data/spec/integration/braintree/transaction_us_bank_account_spec.rb +12 -6
- data/spec/integration/spec_helper.rb +8 -5
- data/spec/spec_helper.rb +2 -11
- data/spec/unit/braintree/address_spec.rb +0 -8
- data/spec/unit/braintree/credit_card_spec.rb +3 -22
- data/spec/unit/braintree/credit_card_verification_spec.rb +6 -2
- data/spec/unit/braintree/customer_spec.rb +2 -13
- data/spec/unit/braintree/dispute_spec.rb +1 -12
- data/spec/unit/braintree/http_spec.rb +3 -3
- data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
- data/spec/unit/braintree/resource_collection_spec.rb +29 -0
- data/spec/unit/braintree/risk_data_spec.rb +9 -5
- data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
- data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
- data/spec/unit/braintree/transaction/paypal_details_spec.rb +2 -0
- data/spec/unit/braintree/transaction_spec.rb +1 -35
- data/spec/unit/braintree/util_spec.rb +37 -3
- data/spec/unit/braintree/webhook_notification_spec.rb +1 -1
- data/spec/unit/braintree/xml/parser_spec.rb +21 -16
- metadata +29 -30
- data/lib/braintree/amex_express_checkout_card.rb +0 -40
- data/lib/braintree/coinbase_account.rb +0 -34
- data/lib/braintree/europe_bank_account.rb +0 -36
- data/lib/braintree/europe_bank_account_gateway.rb +0 -17
- data/lib/braintree/ideal_payment.rb +0 -61
- data/lib/braintree/ideal_payment_gateway.rb +0 -19
- data/lib/braintree/masterpass_card.rb +0 -83
- data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
- data/lib/braintree/transaction/coinbase_details.rb +0 -16
- data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
- data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
- data/lib/braintree/transparent_redirect.rb +0 -40
- data/lib/braintree/transparent_redirect_gateway.rb +0 -105
- data/lib/braintree/xml/rexml.rb +0 -71
- data/spec/hacks/tcp_socket.rb +0 -18
- data/spec/integration/braintree/coinbase_spec.rb +0 -34
- data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
- data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
- data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
- data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -13,7 +13,8 @@ describe Braintree::PaymentMethod do
|
|
13
13
|
context "plaid verified nonce" do
|
14
14
|
let(:nonce) { generate_valid_plaid_us_bank_account_nonce }
|
15
15
|
|
16
|
-
|
16
|
+
# we are temporarily skipping this test until we have a more stable CI env
|
17
|
+
xit "succeeds" do
|
17
18
|
customer = Braintree::Customer.create.customer
|
18
19
|
result = Braintree::PaymentMethod.create(
|
19
20
|
:payment_method_nonce => nonce,
|
@@ -49,7 +50,8 @@ describe Braintree::PaymentMethod do
|
|
49
50
|
Braintree::UsBankAccountVerification::VerificationMethod::IndependentCheck,
|
50
51
|
Braintree::UsBankAccountVerification::VerificationMethod::NetworkCheck,
|
51
52
|
].each do |method|
|
52
|
-
|
53
|
+
# we are temporarily skipping this test until we have a more stable CI env
|
54
|
+
xit "succeeds and verifies via #{method}" do
|
53
55
|
customer = Braintree::Customer.create.customer
|
54
56
|
result = Braintree::PaymentMethod.create(
|
55
57
|
:payment_method_nonce => nonce,
|
@@ -183,7 +185,8 @@ describe Braintree::PaymentMethod do
|
|
183
185
|
|
184
186
|
let(:nonce) { generate_valid_plaid_us_bank_account_nonce }
|
185
187
|
|
186
|
-
|
188
|
+
# we are temporarily skipping this test until we have a more stable CI env
|
189
|
+
xit "succeeds and verifies via independent check" do
|
187
190
|
customer = Braintree::Customer.create.customer
|
188
191
|
result = Braintree::PaymentMethod.create(
|
189
192
|
:payment_method_nonce => nonce,
|
@@ -219,7 +222,8 @@ describe Braintree::PaymentMethod do
|
|
219
222
|
context "non plaid verified nonce" do
|
220
223
|
let(:nonce) { generate_non_plaid_us_bank_account_nonce }
|
221
224
|
|
222
|
-
|
225
|
+
# we are temporarily skipping this test until we have a more stable CI env
|
226
|
+
xit "succeeds and verifies via independent check" do
|
223
227
|
customer = Braintree::Customer.create.customer
|
224
228
|
result = Braintree::PaymentMethod.create(
|
225
229
|
:payment_method_nonce => nonce,
|
@@ -19,23 +19,21 @@ describe Braintree::Subscription do
|
|
19
19
|
:plan_id => SpecHelper::TriallessPlan[:id]
|
20
20
|
)
|
21
21
|
|
22
|
-
date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/
|
23
22
|
result.success?.should == true
|
24
23
|
result.subscription.id.should =~ /^\w{6}$/
|
25
24
|
result.subscription.status.should == Braintree::Subscription::Status::Active
|
26
25
|
result.subscription.plan_id.should == "integration_trialless_plan"
|
27
26
|
|
28
|
-
result.subscription.first_billing_date.
|
29
|
-
result.subscription.next_billing_date.
|
30
|
-
result.subscription.billing_period_start_date.
|
31
|
-
result.subscription.billing_period_end_date.
|
32
|
-
result.subscription.paid_through_date.
|
27
|
+
expect(result.subscription.first_billing_date).to be_a Date
|
28
|
+
expect(result.subscription.next_billing_date).to be_a Date
|
29
|
+
expect(result.subscription.billing_period_start_date).to be_a Date
|
30
|
+
expect(result.subscription.billing_period_end_date).to be_a Date
|
31
|
+
expect(result.subscription.paid_through_date).to be_a Date
|
33
32
|
|
34
33
|
result.subscription.created_at.between?(Time.now - 60, Time.now).should == true
|
35
34
|
result.subscription.updated_at.between?(Time.now - 60, Time.now).should == true
|
36
35
|
|
37
36
|
result.subscription.failure_count.should == 0
|
38
|
-
result.subscription.next_bill_amount.should == "12.34"
|
39
37
|
result.subscription.next_billing_period_amount.should == "12.34"
|
40
38
|
result.subscription.payment_method_token.should == @credit_card.token
|
41
39
|
|
@@ -68,7 +66,6 @@ describe Braintree::Subscription do
|
|
68
66
|
:id => new_id
|
69
67
|
)
|
70
68
|
|
71
|
-
date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/
|
72
69
|
result.success?.should == true
|
73
70
|
result.subscription.id.should == new_id
|
74
71
|
end
|
@@ -195,7 +192,7 @@ describe Braintree::Subscription do
|
|
195
192
|
)
|
196
193
|
|
197
194
|
result.success?.should == true
|
198
|
-
result.subscription.first_billing_date.should ==
|
195
|
+
result.subscription.first_billing_date.should == Date.today + 3
|
199
196
|
result.subscription.status.should == Braintree::Subscription::Status::Pending
|
200
197
|
end
|
201
198
|
|
@@ -678,20 +675,18 @@ describe Braintree::Subscription do
|
|
678
675
|
:plan_id => SpecHelper::TriallessPlan[:id]
|
679
676
|
)
|
680
677
|
|
681
|
-
date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/
|
682
678
|
subscription.id.should =~ /^\w{6}$/
|
683
679
|
subscription.status.should == Braintree::Subscription::Status::Active
|
684
680
|
subscription.plan_id.should == "integration_trialless_plan"
|
685
681
|
|
686
|
-
subscription.first_billing_date.
|
687
|
-
subscription.next_billing_date.
|
688
|
-
subscription.billing_period_start_date.
|
689
|
-
subscription.billing_period_end_date.
|
690
|
-
subscription.paid_through_date.
|
682
|
+
expect(subscription.first_billing_date).to be_a Date
|
683
|
+
expect(subscription.next_billing_date).to be_a Date
|
684
|
+
expect(subscription.billing_period_start_date).to be_a Date
|
685
|
+
expect(subscription.billing_period_end_date).to be_a Date
|
686
|
+
expect(subscription.paid_through_date).to be_a Date
|
691
687
|
|
692
688
|
subscription.failure_count.should == 0
|
693
689
|
subscription.current_billing_cycle.should == 1
|
694
|
-
subscription.next_bill_amount.should == "12.34"
|
695
690
|
subscription.next_billing_period_amount.should == "12.34"
|
696
691
|
subscription.payment_method_token.should == @credit_card.token
|
697
692
|
end
|
@@ -468,7 +468,7 @@ describe Braintree::Transaction, "search" do
|
|
468
468
|
)
|
469
469
|
SpecHelper.settle_transaction transaction.id
|
470
470
|
|
471
|
-
refund_transaction =
|
471
|
+
refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
|
472
472
|
|
473
473
|
collection = Braintree::Transaction.search do |search|
|
474
474
|
search.credit_card_cardholder_name.is cardholder_name
|
@@ -1316,12 +1316,12 @@ describe Braintree::Transaction, "search" do
|
|
1316
1316
|
end
|
1317
1317
|
|
1318
1318
|
context "when the search times out" do
|
1319
|
-
it "raises a
|
1319
|
+
it "raises a UnexpectedError" do
|
1320
1320
|
expect {
|
1321
1321
|
collection = Braintree::Transaction.search do |search|
|
1322
1322
|
search.amount.is -10
|
1323
1323
|
end
|
1324
|
-
}.to raise_error(Braintree::
|
1324
|
+
}.to raise_error(Braintree::UnexpectedError)
|
1325
1325
|
end
|
1326
1326
|
end
|
1327
1327
|
end
|
@@ -123,8 +123,8 @@ describe Braintree::Transaction do
|
|
123
123
|
|
124
124
|
describe "self.create" do
|
125
125
|
describe "risk data" do
|
126
|
-
it "returns decision, device_data_captured and
|
127
|
-
|
126
|
+
it "returns decision, device_data_captured, id, transaction_risk_score, and decision_reasons" do
|
127
|
+
with_fraud_protection_enterprise_merchant do
|
128
128
|
result = Braintree::Transaction.create(
|
129
129
|
:type => "sale",
|
130
130
|
:amount => 1_00,
|
@@ -134,15 +134,17 @@ describe Braintree::Transaction do
|
|
134
134
|
}
|
135
135
|
)
|
136
136
|
result.transaction.risk_data.should be_a(Braintree::RiskData)
|
137
|
-
result.transaction.risk_data.
|
138
|
-
result.transaction.risk_data.
|
139
|
-
result.transaction.risk_data.
|
140
|
-
result.transaction.risk_data.
|
137
|
+
result.transaction.risk_data.id.should_not be_nil
|
138
|
+
result.transaction.risk_data.decision.should_not be_nil
|
139
|
+
result.transaction.risk_data.decision_reasons.should_not be_nil
|
140
|
+
result.transaction.risk_data.device_data_captured.should_not be_nil
|
141
|
+
result.transaction.risk_data.fraud_service_provider.should_not be_nil
|
142
|
+
expect(result.transaction.risk_data).to respond_to(:transaction_risk_score)
|
141
143
|
end
|
142
144
|
end
|
143
145
|
|
144
146
|
it "handles validation errors for invalid risk data attributes" do
|
145
|
-
|
147
|
+
with_advanced_fraud_kount_integration_merchant do
|
146
148
|
result = Braintree::Transaction.create(
|
147
149
|
:type => "sale",
|
148
150
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
@@ -159,7 +161,6 @@ describe Braintree::Transaction do
|
|
159
161
|
}
|
160
162
|
)
|
161
163
|
result.success?.should == false
|
162
|
-
result.errors.for(:transaction).for(:risk_data).on(:customer_browser).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerBrowserIsTooLong
|
163
164
|
result.errors.for(:transaction).for(:risk_data).on(:customer_device_id).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerDeviceIdIsTooLong
|
164
165
|
result.errors.for(:transaction).for(:risk_data).on(:customer_location_zip).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerLocationZipInvalidCharacters
|
165
166
|
result.errors.for(:transaction).for(:risk_data).on(:customer_tenure).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerTenureIsTooLong
|
@@ -182,6 +183,42 @@ describe Braintree::Transaction do
|
|
182
183
|
end
|
183
184
|
end
|
184
185
|
|
186
|
+
describe "sca_exemption" do
|
187
|
+
context "with a valid request" do
|
188
|
+
it "succeeds" do
|
189
|
+
requested_exemption = "low_value"
|
190
|
+
result = Braintree::Transaction.create(
|
191
|
+
:type => "sale",
|
192
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
193
|
+
:credit_card => {
|
194
|
+
:number => Braintree::Test::CreditCardNumbers::VisaCountryOfIssuanceIE,
|
195
|
+
:expiration_date => "05/2009"
|
196
|
+
},
|
197
|
+
:sca_exemption => requested_exemption,
|
198
|
+
)
|
199
|
+
expect(result).to be_success
|
200
|
+
expect(result.transaction.sca_exemption_requested).to eq(requested_exemption)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
context "with an invalid request" do
|
205
|
+
it "returns an error" do
|
206
|
+
result = Braintree::Transaction.create(
|
207
|
+
:type => "sale",
|
208
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
209
|
+
:credit_card => {
|
210
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
211
|
+
:expiration_date => "05/2009"
|
212
|
+
},
|
213
|
+
:sca_exemption => "invalid_sca_exemption_value",
|
214
|
+
)
|
215
|
+
sca_exemption_invalid = Braintree::ErrorCodes::Transaction::ScaExemptionInvalid
|
216
|
+
expect(result).not_to be_success
|
217
|
+
expect(result.errors.for(:transaction).map(&:code)).to eq([sca_exemption_invalid])
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
185
222
|
describe "industry data" do
|
186
223
|
context "for lodging" do
|
187
224
|
it "accepts valid industry data" do
|
@@ -445,6 +482,7 @@ describe Braintree::Transaction do
|
|
445
482
|
result.transaction.credit_card_details.expiration_date.should == "05/2009"
|
446
483
|
result.transaction.credit_card_details.customer_location.should == "US"
|
447
484
|
result.transaction.retrieval_reference_number.should_not be_nil
|
485
|
+
result.transaction.acquirer_reference_number.should be_nil
|
448
486
|
end
|
449
487
|
|
450
488
|
it "returns a successful network response code if successful" do
|
@@ -509,7 +547,7 @@ describe Braintree::Transaction do
|
|
509
547
|
result.transaction.credit_card_details.customer_location.should == "US"
|
510
548
|
end
|
511
549
|
|
512
|
-
it "accepts additional security parameters:
|
550
|
+
it "accepts additional security parameters: device_data" do
|
513
551
|
result = Braintree::Transaction.create(
|
514
552
|
:type => "sale",
|
515
553
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
@@ -517,8 +555,7 @@ describe Braintree::Transaction do
|
|
517
555
|
:number => Braintree::Test::CreditCardNumbers::Visa,
|
518
556
|
:expiration_date => "05/2009"
|
519
557
|
},
|
520
|
-
:
|
521
|
-
:fraud_merchant_id => "7"
|
558
|
+
:device_data => "device_data",
|
522
559
|
)
|
523
560
|
|
524
561
|
result.success?.should == true
|
@@ -895,7 +932,7 @@ describe Braintree::Transaction do
|
|
895
932
|
end
|
896
933
|
|
897
934
|
it "exposes the fraud gateway rejection reason" do
|
898
|
-
|
935
|
+
with_advanced_fraud_kount_integration_merchant do
|
899
936
|
result = Braintree::Transaction.sale(
|
900
937
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
901
938
|
:credit_card => {
|
@@ -910,7 +947,7 @@ describe Braintree::Transaction do
|
|
910
947
|
end
|
911
948
|
|
912
949
|
it "exposes the risk_threshold gateway rejection reason (via test cc num)" do
|
913
|
-
|
950
|
+
with_advanced_fraud_kount_integration_merchant do
|
914
951
|
result = Braintree::Transaction.sale(
|
915
952
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
916
953
|
:credit_card => {
|
@@ -925,7 +962,7 @@ describe Braintree::Transaction do
|
|
925
962
|
end
|
926
963
|
|
927
964
|
it "exposes the risk_threshold gateway rejection reason (via test test nonce)" do
|
928
|
-
|
965
|
+
with_advanced_fraud_kount_integration_merchant do
|
929
966
|
result = Braintree::Transaction.sale(
|
930
967
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
931
968
|
:payment_method_nonce => Braintree::Test::Nonce::GatewayRejectedRiskThresholds,
|
@@ -1372,22 +1409,6 @@ describe Braintree::Transaction do
|
|
1372
1409
|
end
|
1373
1410
|
end
|
1374
1411
|
|
1375
|
-
context "recurring" do
|
1376
|
-
it "marks a transaction as recurring" do
|
1377
|
-
result = Braintree::Transaction.create(
|
1378
|
-
:type => "sale",
|
1379
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
1380
|
-
:credit_card => {
|
1381
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
1382
|
-
:expiration_date => "12/12",
|
1383
|
-
},
|
1384
|
-
:recurring => true
|
1385
|
-
)
|
1386
|
-
result.success?.should == true
|
1387
|
-
result.transaction.recurring.should == true
|
1388
|
-
end
|
1389
|
-
end
|
1390
|
-
|
1391
1412
|
context "transaction_source" do
|
1392
1413
|
it "marks a transactions as recurring_first" do
|
1393
1414
|
result = Braintree::Transaction.create(
|
@@ -1804,106 +1825,83 @@ describe Braintree::Transaction do
|
|
1804
1825
|
apple_pay_details.token.should_not be_nil
|
1805
1826
|
end
|
1806
1827
|
|
1807
|
-
it "can create a transaction with a fake
|
1828
|
+
it "can create a transaction with a fake google pay proxy card nonce" do
|
1808
1829
|
customer = Braintree::Customer.create!
|
1809
1830
|
result = Braintree::Transaction.create(
|
1810
1831
|
:type => "sale",
|
1811
1832
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
1812
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
1833
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover
|
1813
1834
|
)
|
1814
1835
|
result.success?.should == true
|
1815
1836
|
result.transaction.should_not be_nil
|
1816
|
-
|
1817
|
-
|
1818
|
-
|
1819
|
-
|
1820
|
-
|
1821
|
-
|
1822
|
-
|
1823
|
-
|
1824
|
-
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
1828
|
-
|
1829
|
-
|
1830
|
-
|
1831
|
-
|
1832
|
-
|
1833
|
-
|
1834
|
-
|
1835
|
-
|
1836
|
-
|
1837
|
-
end
|
1838
|
-
|
1839
|
-
it "can create a vaulted transaction with a fake
|
1837
|
+
google_pay_details = result.transaction.google_pay_details
|
1838
|
+
google_pay_details.should_not be_nil
|
1839
|
+
google_pay_details.bin.should_not be_nil
|
1840
|
+
google_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
|
1841
|
+
google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
|
1842
|
+
google_pay_details.last_4.should == "1117"
|
1843
|
+
google_pay_details.virtual_card_last_4.should == "1117"
|
1844
|
+
google_pay_details.source_description.should == "Discover 1111"
|
1845
|
+
google_pay_details.expiration_month.to_i.should > 0
|
1846
|
+
google_pay_details.expiration_year.to_i.should > 0
|
1847
|
+
google_pay_details.google_transaction_id.should == "google_transaction_id"
|
1848
|
+
google_pay_details.image_url.should_not be_nil
|
1849
|
+
google_pay_details.is_network_tokenized?.should == false
|
1850
|
+
google_pay_details.token.should be_nil
|
1851
|
+
google_pay_details.prepaid.should_not be_nil
|
1852
|
+
google_pay_details.healthcare.should_not be_nil
|
1853
|
+
google_pay_details.debit.should_not be_nil
|
1854
|
+
google_pay_details.durbin_regulated.should_not be_nil
|
1855
|
+
google_pay_details.commercial.should_not be_nil
|
1856
|
+
google_pay_details.payroll.should_not be_nil
|
1857
|
+
google_pay_details.product_id.should_not be_nil
|
1858
|
+
end
|
1859
|
+
|
1860
|
+
it "can create a vaulted transaction with a fake google pay proxy card nonce" do
|
1840
1861
|
customer = Braintree::Customer.create!
|
1841
1862
|
result = Braintree::Transaction.create(
|
1842
1863
|
:type => "sale",
|
1843
1864
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
1844
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
1865
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
|
1845
1866
|
:options => { :store_in_vault_on_success => true }
|
1846
1867
|
)
|
1847
1868
|
result.success?.should == true
|
1848
1869
|
result.transaction.should_not be_nil
|
1849
|
-
|
1850
|
-
|
1851
|
-
|
1852
|
-
|
1853
|
-
|
1854
|
-
|
1855
|
-
|
1856
|
-
|
1857
|
-
|
1858
|
-
|
1859
|
-
|
1860
|
-
|
1861
|
-
|
1862
|
-
end
|
1863
|
-
|
1864
|
-
it "can create a transaction with a fake
|
1870
|
+
google_pay_details = result.transaction.google_pay_details
|
1871
|
+
google_pay_details.should_not be_nil
|
1872
|
+
google_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
|
1873
|
+
google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
|
1874
|
+
google_pay_details.last_4.should == "1117"
|
1875
|
+
google_pay_details.virtual_card_last_4.should == "1117"
|
1876
|
+
google_pay_details.source_description.should == "Discover 1111"
|
1877
|
+
google_pay_details.expiration_month.to_i.should > 0
|
1878
|
+
google_pay_details.expiration_year.to_i.should > 0
|
1879
|
+
google_pay_details.google_transaction_id.should == "google_transaction_id"
|
1880
|
+
google_pay_details.image_url.should_not be_nil
|
1881
|
+
google_pay_details.is_network_tokenized?.should == false
|
1882
|
+
google_pay_details.token.should_not be_nil
|
1883
|
+
end
|
1884
|
+
|
1885
|
+
it "can create a transaction with a fake google pay network token nonce" do
|
1865
1886
|
customer = Braintree::Customer.create!
|
1866
1887
|
result = Braintree::Transaction.create(
|
1867
1888
|
:type => "sale",
|
1868
1889
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
1869
|
-
:payment_method_nonce => Braintree::Test::Nonce::
|
1890
|
+
:payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard
|
1870
1891
|
)
|
1871
1892
|
result.success?.should == true
|
1872
1893
|
result.transaction.should_not be_nil
|
1873
|
-
|
1874
|
-
|
1875
|
-
|
1876
|
-
|
1877
|
-
|
1878
|
-
|
1879
|
-
|
1880
|
-
|
1881
|
-
|
1882
|
-
|
1883
|
-
|
1884
|
-
end
|
1885
|
-
|
1886
|
-
it "can create a transaction with a fake amex express checkout card nonce" do
|
1887
|
-
result = Braintree::Transaction.create(
|
1888
|
-
:type => "sale",
|
1889
|
-
:merchant_account_id => SpecHelper::FakeAmexDirectMerchantAccountId,
|
1890
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
1891
|
-
:payment_method_nonce => Braintree::Test::Nonce::AmexExpressCheckout,
|
1892
|
-
:options => {:store_in_vault => true}
|
1893
|
-
)
|
1894
|
-
result.success?.should == true
|
1895
|
-
result.transaction.should_not be_nil
|
1896
|
-
checkout_details = result.transaction.amex_express_checkout_details
|
1897
|
-
checkout_details.should_not be_nil
|
1898
|
-
checkout_details.card_type.should == "American Express"
|
1899
|
-
checkout_details.token.should respond_to(:to_str)
|
1900
|
-
checkout_details.bin.should =~ /\A\d{6}\z/
|
1901
|
-
checkout_details.expiration_month.should =~ /\A\d{2}\z/
|
1902
|
-
checkout_details.expiration_year.should =~ /\A\d{4}\z/
|
1903
|
-
checkout_details.card_member_number.should =~ /\A\d{4}\z/
|
1904
|
-
checkout_details.card_member_expiry_date.should =~ /\A\d{2}\/\d{2}\z/
|
1905
|
-
checkout_details.image_url.should include(".png")
|
1906
|
-
checkout_details.source_description.should =~ /\AAmEx \d{4}\z/
|
1894
|
+
google_pay_details = result.transaction.google_pay_details
|
1895
|
+
google_pay_details.should_not be_nil
|
1896
|
+
google_pay_details.card_type.should == Braintree::CreditCard::CardType::MasterCard
|
1897
|
+
google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
|
1898
|
+
google_pay_details.last_4.should == "4444"
|
1899
|
+
google_pay_details.virtual_card_last_4.should == "4444"
|
1900
|
+
google_pay_details.source_description.should == "MasterCard 4444"
|
1901
|
+
google_pay_details.expiration_month.to_i.should > 0
|
1902
|
+
google_pay_details.expiration_year.to_i.should > 0
|
1903
|
+
google_pay_details.google_transaction_id.should == "google_transaction_id"
|
1904
|
+
google_pay_details.is_network_tokenized?.should == true
|
1907
1905
|
end
|
1908
1906
|
|
1909
1907
|
it "can create a transaction with a fake venmo account nonce" do
|
@@ -2703,6 +2701,22 @@ describe Braintree::Transaction do
|
|
2703
2701
|
end
|
2704
2702
|
end
|
2705
2703
|
|
2704
|
+
context "billing agreement" do
|
2705
|
+
it "can create a paypal billing agreement" do
|
2706
|
+
result = Braintree::Transaction.create(
|
2707
|
+
:type => "sale",
|
2708
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
2709
|
+
:payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
|
2710
|
+
:options => {:store_in_vault => true}
|
2711
|
+
)
|
2712
|
+
|
2713
|
+
result.should be_success
|
2714
|
+
result.transaction.paypal_details.should_not be_nil
|
2715
|
+
result.transaction.paypal_details.debug_id.should_not be_nil
|
2716
|
+
result.transaction.paypal_details.billing_agreement_id.should_not be_nil
|
2717
|
+
end
|
2718
|
+
end
|
2719
|
+
|
2706
2720
|
context "local payments" do
|
2707
2721
|
it "can create a local payment transaction with a nonce" do
|
2708
2722
|
result = Braintree::Transaction.create(
|
@@ -2865,14 +2879,6 @@ describe Braintree::Transaction do
|
|
2865
2879
|
}.to raise_error(ArgumentError)
|
2866
2880
|
end
|
2867
2881
|
|
2868
|
-
it "assigns the refund_id on the original transaction" do
|
2869
|
-
transaction = create_paypal_transaction_for_refund
|
2870
|
-
refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
|
2871
|
-
transaction = Braintree::Transaction.find(transaction.id)
|
2872
|
-
|
2873
|
-
transaction.refund_id.should == refund_transaction.id
|
2874
|
-
end
|
2875
|
-
|
2876
2882
|
it "assigns the refunded_transaction_id to the original transaction" do
|
2877
2883
|
transaction = create_paypal_transaction_for_refund
|
2878
2884
|
refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
|
@@ -2902,7 +2908,13 @@ describe Braintree::Transaction do
|
|
2902
2908
|
response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
|
2903
2909
|
result = Braintree::Transaction.refund(transaction.id, :amount => "2046.00")
|
2904
2910
|
result.success?.should == false
|
2905
|
-
result.
|
2911
|
+
result.transaction.id.should =~ /^\w{6,}$/
|
2912
|
+
result.transaction.type.should == "credit"
|
2913
|
+
result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
2914
|
+
result.transaction.processor_response_code.should == "2046"
|
2915
|
+
result.transaction.processor_response_text.should == "Declined"
|
2916
|
+
result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::SoftDeclined
|
2917
|
+
result.transaction.additional_processor_response.should == "2046 : Declined"
|
2906
2918
|
end
|
2907
2919
|
|
2908
2920
|
it "handles hard declined refund authorizations" do
|
@@ -2917,7 +2929,13 @@ describe Braintree::Transaction do
|
|
2917
2929
|
response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
|
2918
2930
|
result = Braintree::Transaction.refund(transaction.id, :amount => "2009.00")
|
2919
2931
|
result.success?.should == false
|
2920
|
-
result.
|
2932
|
+
result.transaction.id.should =~ /^\w{6,}$/
|
2933
|
+
result.transaction.type.should == "credit"
|
2934
|
+
result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
2935
|
+
result.transaction.processor_response_code.should == "2009"
|
2936
|
+
result.transaction.processor_response_text.should == "No Such Issuer"
|
2937
|
+
result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::HardDeclined
|
2938
|
+
result.transaction.additional_processor_response.should == "2009 : No Such Issuer"
|
2921
2939
|
end
|
2922
2940
|
end
|
2923
2941
|
|
@@ -4289,7 +4307,7 @@ describe Braintree::Transaction do
|
|
4289
4307
|
result.errors.for(:transaction).for(:external_vault).on(:status)[0].code.should == Braintree::ErrorCodes::Transaction::ExternalVault::StatusIsInvalid
|
4290
4308
|
end
|
4291
4309
|
|
4292
|
-
context "Visa/Mastercard/Discover" do
|
4310
|
+
context "Visa/Mastercard/Discover/AmEx" do
|
4293
4311
|
it "accepts status" do
|
4294
4312
|
result = Braintree::Transaction.create(
|
4295
4313
|
:type => "sale",
|
@@ -4341,12 +4359,12 @@ describe Braintree::Transaction do
|
|
4341
4359
|
end
|
4342
4360
|
end
|
4343
4361
|
|
4344
|
-
context "Non-(Visa/Mastercard/Discover) card types" do
|
4362
|
+
context "Non-(Visa/Mastercard/Discover/AmEx) card types" do
|
4345
4363
|
it "accepts status" do
|
4346
4364
|
result = Braintree::Transaction.create(
|
4347
4365
|
:type => "sale",
|
4348
4366
|
:credit_card => {
|
4349
|
-
:number => Braintree::Test::CreditCardNumbers::
|
4367
|
+
:number => Braintree::Test::CreditCardNumbers::JCBs[0],
|
4350
4368
|
:expiration_date => "05/2009"
|
4351
4369
|
},
|
4352
4370
|
:external_vault => {
|
@@ -4362,7 +4380,7 @@ describe Braintree::Transaction do
|
|
4362
4380
|
result = Braintree::Transaction.create(
|
4363
4381
|
:type => "sale",
|
4364
4382
|
:credit_card => {
|
4365
|
-
:number => Braintree::Test::CreditCardNumbers::
|
4383
|
+
:number => Braintree::Test::CreditCardNumbers::JCBs[0],
|
4366
4384
|
:expiration_date => "05/2009"
|
4367
4385
|
},
|
4368
4386
|
:external_vault => {
|
@@ -4374,25 +4392,7 @@ describe Braintree::Transaction do
|
|
4374
4392
|
result.success?.should == true
|
4375
4393
|
result.transaction.network_transaction_id.should be_nil
|
4376
4394
|
end
|
4377
|
-
|
4378
|
-
it "rejects previous_network_transaction_id" do
|
4379
|
-
result = Braintree::Transaction.create(
|
4380
|
-
:type => "sale",
|
4381
|
-
:credit_card => {
|
4382
|
-
:number => Braintree::Test::CreditCardNumbers::AmExes[0],
|
4383
|
-
:expiration_date => "05/2009"
|
4384
|
-
},
|
4385
|
-
:external_vault => {
|
4386
|
-
:status => Braintree::Transaction::ExternalVault::Status::Vaulted,
|
4387
|
-
:previous_network_transaction_id => "123456789012345",
|
4388
|
-
},
|
4389
|
-
:amount => "10.00",
|
4390
|
-
)
|
4391
|
-
result.success?.should == false
|
4392
|
-
result.errors.for(:transaction).for(:external_vault).on(:previous_network_transaction_id)[0].code.should == Braintree::ErrorCodes::Transaction::ExternalVault::CardTypeIsInvalid
|
4393
|
-
end
|
4394
4395
|
end
|
4395
|
-
|
4396
4396
|
end
|
4397
4397
|
|
4398
4398
|
context "account_type" do
|
@@ -4571,14 +4571,6 @@ describe Braintree::Transaction do
|
|
4571
4571
|
result.transaction.type.should == "credit"
|
4572
4572
|
end
|
4573
4573
|
|
4574
|
-
it "assigns the refund_id on the original transaction" do
|
4575
|
-
transaction = create_transaction_to_refund
|
4576
|
-
refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
|
4577
|
-
transaction = Braintree::Transaction.find(transaction.id)
|
4578
|
-
|
4579
|
-
transaction.refund_id.should == refund_transaction.id
|
4580
|
-
end
|
4581
|
-
|
4582
4574
|
it "assigns the refunded_transaction_id to the original transaction" do
|
4583
4575
|
transaction = create_transaction_to_refund
|
4584
4576
|
refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
|
@@ -4986,8 +4978,75 @@ describe Braintree::Transaction do
|
|
4986
4978
|
result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
|
4987
4979
|
end
|
4988
4980
|
|
4981
|
+
it "validates currency_iso_code and creates transaction" do
|
4982
|
+
params = {
|
4983
|
+
:transaction => {
|
4984
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
4985
|
+
:currency_iso_code => "USD",
|
4986
|
+
:credit_card => {
|
4987
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
4988
|
+
:expiration_date => "05/2009"
|
4989
|
+
}
|
4990
|
+
}
|
4991
|
+
}
|
4992
|
+
result = Braintree::Transaction.sale(params[:transaction])
|
4993
|
+
result.success?.should == true
|
4994
|
+
result.transaction.currency_iso_code == "USD"
|
4995
|
+
end
|
4996
|
+
|
4997
|
+
it "validates currency_iso_code and returns error" do
|
4998
|
+
params = {
|
4999
|
+
:transaction => {
|
5000
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
5001
|
+
:currency_iso_code => "CAD",
|
5002
|
+
:credit_card => {
|
5003
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
5004
|
+
:expiration_date => "05/2009"
|
5005
|
+
}
|
5006
|
+
}
|
5007
|
+
}
|
5008
|
+
result = Braintree::Transaction.sale(params[:transaction])
|
5009
|
+
result.success?.should == false
|
5010
|
+
result.errors.for(:transaction).on(:currency_iso_code)[0].code.should == Braintree::ErrorCodes::Transaction::CurrencyCodeNotSupportedByMerchantAccount
|
5011
|
+
end
|
5012
|
+
|
5013
|
+
it "validates currency_iso_code and creates transaction with specified merchant account" do
|
5014
|
+
params = {
|
5015
|
+
:transaction => {
|
5016
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
5017
|
+
:merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
5018
|
+
:currency_iso_code => "USD",
|
5019
|
+
:credit_card => {
|
5020
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
5021
|
+
:expiration_date => "05/2009"
|
5022
|
+
}
|
5023
|
+
}
|
5024
|
+
}
|
5025
|
+
result = Braintree::Transaction.sale(params[:transaction])
|
5026
|
+
result.success?.should == true
|
5027
|
+
result.transaction.currency_iso_code == "USD"
|
5028
|
+
result.transaction.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
|
5029
|
+
end
|
5030
|
+
|
5031
|
+
it "validates currency_iso_code and returns error with specified merchant account" do
|
5032
|
+
params = {
|
5033
|
+
:transaction => {
|
5034
|
+
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
5035
|
+
:merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
|
5036
|
+
:currency_iso_code => "CAD",
|
5037
|
+
:credit_card => {
|
5038
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
5039
|
+
:expiration_date => "05/2009"
|
5040
|
+
}
|
5041
|
+
}
|
5042
|
+
}
|
5043
|
+
result = Braintree::Transaction.sale(params[:transaction])
|
5044
|
+
result.success?.should == false
|
5045
|
+
result.errors.for(:transaction).on(:currency_iso_code)[0].code.should == Braintree::ErrorCodes::Transaction::CurrencyCodeNotSupportedByMerchantAccount
|
5046
|
+
end
|
5047
|
+
|
4989
5048
|
it "skips advanced fraud checking if transaction[options][skip_advanced_fraud_checking] is set to true" do
|
4990
|
-
|
5049
|
+
with_advanced_fraud_kount_integration_merchant do
|
4991
5050
|
result = Braintree::Transaction.sale(
|
4992
5051
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
4993
5052
|
:credit_card => {
|
@@ -5020,11 +5079,11 @@ describe Braintree::Transaction do
|
|
5020
5079
|
result.transaction.status.should == Braintree::Transaction::Status::Authorized
|
5021
5080
|
end
|
5022
5081
|
|
5023
|
-
context "
|
5082
|
+
context "Google Pay params" do
|
5024
5083
|
it "works with full params" do
|
5025
5084
|
params = {
|
5026
5085
|
:amount => "3.12",
|
5027
|
-
:
|
5086
|
+
:google_pay_card => {
|
5028
5087
|
:number => "4012888888881881",
|
5029
5088
|
:cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
|
5030
5089
|
:google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
|
@@ -5043,7 +5102,7 @@ describe Braintree::Transaction do
|
|
5043
5102
|
it "works with only number, cryptogram, expiration and transaction ID (network tokenized card)" do
|
5044
5103
|
params = {
|
5045
5104
|
:amount => "3.12",
|
5046
|
-
:
|
5105
|
+
:google_pay_card => {
|
5047
5106
|
:number => "4012888888881881",
|
5048
5107
|
:cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
|
5049
5108
|
:google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
|
@@ -5059,7 +5118,7 @@ describe Braintree::Transaction do
|
|
5059
5118
|
it "works with only number, expiration and transaction ID (non-tokenized card)" do
|
5060
5119
|
params = {
|
5061
5120
|
:amount => "3.12",
|
5062
|
-
:
|
5121
|
+
:google_pay_card => {
|
5063
5122
|
:number => "4012888888881881",
|
5064
5123
|
:google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
|
5065
5124
|
:expiration_month => "10",
|
@@ -6048,184 +6107,6 @@ describe Braintree::Transaction do
|
|
6048
6107
|
end
|
6049
6108
|
end
|
6050
6109
|
|
6051
|
-
describe "self.create_from_transparent_redirect" do
|
6052
|
-
it "returns a successful result if successful" do
|
6053
|
-
params = {
|
6054
|
-
:transaction => {
|
6055
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6056
|
-
:credit_card => {
|
6057
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6058
|
-
:expiration_date => "05/2009"
|
6059
|
-
}
|
6060
|
-
}
|
6061
|
-
}
|
6062
|
-
tr_data_params = {
|
6063
|
-
:transaction => {
|
6064
|
-
:type => "sale"
|
6065
|
-
}
|
6066
|
-
}
|
6067
|
-
tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
6068
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
|
6069
|
-
result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
|
6070
|
-
|
6071
|
-
result.success?.should == true
|
6072
|
-
transaction = result.transaction
|
6073
|
-
transaction.type.should == "sale"
|
6074
|
-
transaction.amount.should == BigDecimal("1000.00")
|
6075
|
-
transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
|
6076
|
-
transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
|
6077
|
-
transaction.credit_card_details.expiration_date.should == "05/2009"
|
6078
|
-
end
|
6079
|
-
|
6080
|
-
it "raises an error with a message if given invalid params" do
|
6081
|
-
params = {
|
6082
|
-
:transaction => {
|
6083
|
-
:bad => "value",
|
6084
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6085
|
-
:credit_card => {
|
6086
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6087
|
-
:expiration_date => "05/2009"
|
6088
|
-
}
|
6089
|
-
}
|
6090
|
-
}
|
6091
|
-
tr_data_params = {
|
6092
|
-
:transaction => {
|
6093
|
-
:type => "sale"
|
6094
|
-
}
|
6095
|
-
}
|
6096
|
-
tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
6097
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
|
6098
|
-
|
6099
|
-
expect do
|
6100
|
-
Braintree::Transaction.create_from_transparent_redirect(query_string_response)
|
6101
|
-
end.to raise_error(Braintree::AuthorizationError, "Invalid params: transaction[bad]")
|
6102
|
-
end
|
6103
|
-
|
6104
|
-
it "can put any param in tr_data" do
|
6105
|
-
params = {
|
6106
|
-
|
6107
|
-
}
|
6108
|
-
tr_data_params = {
|
6109
|
-
:transaction => {
|
6110
|
-
:amount => "100.00",
|
6111
|
-
:order_id => "123",
|
6112
|
-
:channel => "MyShoppingCartProvider",
|
6113
|
-
:type => "sale",
|
6114
|
-
:credit_card => {
|
6115
|
-
:cardholder_name => "The Cardholder",
|
6116
|
-
:number => "5105105105105100",
|
6117
|
-
:expiration_date => "05/2011",
|
6118
|
-
:cvv => "123"
|
6119
|
-
},
|
6120
|
-
:customer => {
|
6121
|
-
:first_name => "Dan",
|
6122
|
-
:last_name => "Smith",
|
6123
|
-
:company => "Braintree",
|
6124
|
-
:email => "dan@example.com",
|
6125
|
-
:phone => "419-555-1234",
|
6126
|
-
:fax => "419-555-1235",
|
6127
|
-
:website => "http://braintreepayments.com"
|
6128
|
-
},
|
6129
|
-
:billing => {
|
6130
|
-
:first_name => "Carl",
|
6131
|
-
:last_name => "Jones",
|
6132
|
-
:company => "Braintree",
|
6133
|
-
:street_address => "123 E Main St",
|
6134
|
-
:extended_address => "Suite 403",
|
6135
|
-
:locality => "Chicago",
|
6136
|
-
:region => "IL",
|
6137
|
-
:postal_code => "60622",
|
6138
|
-
:country_name => "United States of America"
|
6139
|
-
},
|
6140
|
-
:shipping => {
|
6141
|
-
:first_name => "Andrew",
|
6142
|
-
:last_name => "Mason",
|
6143
|
-
:company => "Braintree",
|
6144
|
-
:street_address => "456 W Main St",
|
6145
|
-
:extended_address => "Apt 2F",
|
6146
|
-
:locality => "Bartlett",
|
6147
|
-
:region => "IL",
|
6148
|
-
:postal_code => "60103",
|
6149
|
-
:country_name => "United States of America"
|
6150
|
-
}
|
6151
|
-
}
|
6152
|
-
}
|
6153
|
-
tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
6154
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
|
6155
|
-
result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
|
6156
|
-
|
6157
|
-
transaction = result.transaction
|
6158
|
-
transaction.id.should =~ /\A\w{6,}\z/
|
6159
|
-
transaction.type.should == "sale"
|
6160
|
-
transaction.status.should == Braintree::Transaction::Status::Authorized
|
6161
|
-
transaction.amount.should == BigDecimal("100.00")
|
6162
|
-
transaction.order_id.should == "123"
|
6163
|
-
transaction.channel.should == "MyShoppingCartProvider"
|
6164
|
-
transaction.processor_response_code.should == "1000"
|
6165
|
-
transaction.authorization_expires_at.between?(Time.now, Time.now + (60 * 60 * 24 * 60)).should == true
|
6166
|
-
transaction.created_at.between?(Time.now - 60, Time.now).should == true
|
6167
|
-
transaction.updated_at.between?(Time.now - 60, Time.now).should == true
|
6168
|
-
transaction.credit_card_details.bin.should == "510510"
|
6169
|
-
transaction.credit_card_details.last_4.should == "5100"
|
6170
|
-
transaction.credit_card_details.cardholder_name.should == "The Cardholder"
|
6171
|
-
transaction.credit_card_details.masked_number.should == "510510******5100"
|
6172
|
-
transaction.credit_card_details.card_type.should == "MasterCard"
|
6173
|
-
transaction.avs_error_response_code.should == nil
|
6174
|
-
transaction.avs_postal_code_response_code.should == "M"
|
6175
|
-
transaction.avs_street_address_response_code.should == "M"
|
6176
|
-
transaction.cvv_response_code.should == "M"
|
6177
|
-
transaction.customer_details.first_name.should == "Dan"
|
6178
|
-
transaction.customer_details.last_name.should == "Smith"
|
6179
|
-
transaction.customer_details.company.should == "Braintree"
|
6180
|
-
transaction.customer_details.email.should == "dan@example.com"
|
6181
|
-
transaction.customer_details.phone.should == "419-555-1234"
|
6182
|
-
transaction.customer_details.fax.should == "419-555-1235"
|
6183
|
-
transaction.customer_details.website.should == "http://braintreepayments.com"
|
6184
|
-
transaction.billing_details.first_name.should == "Carl"
|
6185
|
-
transaction.billing_details.last_name.should == "Jones"
|
6186
|
-
transaction.billing_details.company.should == "Braintree"
|
6187
|
-
transaction.billing_details.street_address.should == "123 E Main St"
|
6188
|
-
transaction.billing_details.extended_address.should == "Suite 403"
|
6189
|
-
transaction.billing_details.locality.should == "Chicago"
|
6190
|
-
transaction.billing_details.region.should == "IL"
|
6191
|
-
transaction.billing_details.postal_code.should == "60622"
|
6192
|
-
transaction.billing_details.country_name.should == "United States of America"
|
6193
|
-
transaction.shipping_details.first_name.should == "Andrew"
|
6194
|
-
transaction.shipping_details.last_name.should == "Mason"
|
6195
|
-
transaction.shipping_details.company.should == "Braintree"
|
6196
|
-
transaction.shipping_details.street_address.should == "456 W Main St"
|
6197
|
-
transaction.shipping_details.extended_address.should == "Apt 2F"
|
6198
|
-
transaction.shipping_details.locality.should == "Bartlett"
|
6199
|
-
transaction.shipping_details.region.should == "IL"
|
6200
|
-
transaction.shipping_details.postal_code.should == "60103"
|
6201
|
-
transaction.shipping_details.country_name.should == "United States of America"
|
6202
|
-
end
|
6203
|
-
|
6204
|
-
it "returns an error result if validations fail" do
|
6205
|
-
params = {
|
6206
|
-
:transaction => {
|
6207
|
-
:amount => "",
|
6208
|
-
:credit_card => {
|
6209
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6210
|
-
:expiration_date => "05/2009"
|
6211
|
-
}
|
6212
|
-
}
|
6213
|
-
}
|
6214
|
-
tr_data_params = {
|
6215
|
-
:transaction => {
|
6216
|
-
:type => "sale"
|
6217
|
-
}
|
6218
|
-
}
|
6219
|
-
tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
|
6220
|
-
query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
|
6221
|
-
result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
|
6222
|
-
|
6223
|
-
result.success?.should == false
|
6224
|
-
result.params[:transaction].should == {:amount => "", :type => "sale", :credit_card => {:expiration_date => "05/2009"}}
|
6225
|
-
result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
|
6226
|
-
end
|
6227
|
-
end
|
6228
|
-
|
6229
6110
|
describe "self.find" do
|
6230
6111
|
it "finds the transaction with the given id" do
|
6231
6112
|
result = Braintree::Transaction.create(
|
@@ -6267,6 +6148,12 @@ describe Braintree::Transaction do
|
|
6267
6148
|
end.to raise_error(Braintree::NotFoundError, 'transaction with id "invalid-id" not found')
|
6268
6149
|
end
|
6269
6150
|
|
6151
|
+
it "finds a transaction and returns an acquirer_reference_number if the transaction has one" do
|
6152
|
+
transaction = Braintree::Transaction.find("transactionwithacquirerreferencenumber")
|
6153
|
+
|
6154
|
+
transaction.acquirer_reference_number.should == "123456789 091019"
|
6155
|
+
end
|
6156
|
+
|
6270
6157
|
context "disbursement_details" do
|
6271
6158
|
it "includes disbursement_details on found transactions" do
|
6272
6159
|
found_transaction = Braintree::Transaction.find("deposittransaction")
|
@@ -6274,7 +6161,8 @@ describe Braintree::Transaction do
|
|
6274
6161
|
found_transaction.disbursed?.should == true
|
6275
6162
|
disbursement = found_transaction.disbursement_details
|
6276
6163
|
|
6277
|
-
disbursement.disbursement_date.
|
6164
|
+
expect(disbursement.disbursement_date).to be_a Date
|
6165
|
+
expect(disbursement.disbursement_date).to eq Date.parse("2013-04-10")
|
6278
6166
|
disbursement.settlement_amount.should == "100.00"
|
6279
6167
|
disbursement.settlement_currency_iso_code.should == "USD"
|
6280
6168
|
disbursement.settlement_currency_exchange_rate.should == "1"
|
@@ -6352,15 +6240,21 @@ describe Braintree::Transaction do
|
|
6352
6240
|
it "returns all the three_d_secure_info" do
|
6353
6241
|
transaction = Braintree::Transaction.find("threedsecuredtransaction")
|
6354
6242
|
|
6243
|
+
expect(transaction.three_d_secure_info.authentication).to have_key(:trans_status)
|
6244
|
+
expect(transaction.three_d_secure_info.authentication).to have_key(:trans_status_reason)
|
6245
|
+
expect(transaction.three_d_secure_info.lookup).to have_key(:trans_status)
|
6246
|
+
expect(transaction.three_d_secure_info.lookup).to have_key(:trans_status_reason)
|
6247
|
+
transaction.three_d_secure_info.cavv.should == "somebase64value"
|
6248
|
+
transaction.three_d_secure_info.ds_transaction_id.should == "dstxnid"
|
6249
|
+
transaction.three_d_secure_info.eci_flag.should == "07"
|
6355
6250
|
transaction.three_d_secure_info.enrolled.should == "Y"
|
6356
|
-
transaction.three_d_secure_info.should
|
6251
|
+
transaction.three_d_secure_info.pares_status.should == "Y"
|
6357
6252
|
transaction.three_d_secure_info.should be_liability_shift_possible
|
6253
|
+
transaction.three_d_secure_info.should be_liability_shifted
|
6358
6254
|
transaction.three_d_secure_info.status.should == "authenticate_successful"
|
6359
|
-
transaction.three_d_secure_info.
|
6360
|
-
transaction.three_d_secure_info.xid.should == "xidvalue"
|
6361
|
-
transaction.three_d_secure_info.eci_flag.should == "07"
|
6255
|
+
expect(transaction.three_d_secure_info.three_d_secure_authentication_id).to be
|
6362
6256
|
transaction.three_d_secure_info.three_d_secure_version.should == "1.0.2"
|
6363
|
-
transaction.three_d_secure_info.
|
6257
|
+
transaction.three_d_secure_info.xid.should == "xidvalue"
|
6364
6258
|
end
|
6365
6259
|
|
6366
6260
|
it "is nil if the transaction wasn't 3d secured" do
|
@@ -6519,151 +6413,6 @@ describe Braintree::Transaction do
|
|
6519
6413
|
end
|
6520
6414
|
end
|
6521
6415
|
|
6522
|
-
describe "refund" do
|
6523
|
-
context "partial refunds" do
|
6524
|
-
it "allows partial refunds" do
|
6525
|
-
transaction = create_transaction_to_refund
|
6526
|
-
result = transaction.refund(transaction.amount / 2)
|
6527
|
-
result.success?.should == true
|
6528
|
-
result.new_transaction.type.should == "credit"
|
6529
|
-
end
|
6530
|
-
end
|
6531
|
-
|
6532
|
-
it "returns a successful result if successful" do
|
6533
|
-
transaction = create_transaction_to_refund
|
6534
|
-
transaction.status.should == Braintree::Transaction::Status::Settled
|
6535
|
-
result = transaction.refund
|
6536
|
-
result.success?.should == true
|
6537
|
-
result.new_transaction.type.should == "credit"
|
6538
|
-
end
|
6539
|
-
|
6540
|
-
it "assigns the refund_id on the original transaction" do
|
6541
|
-
transaction = create_transaction_to_refund
|
6542
|
-
refund_transaction = transaction.refund.new_transaction
|
6543
|
-
transaction = Braintree::Transaction.find(transaction.id)
|
6544
|
-
|
6545
|
-
transaction.refund_id.should == refund_transaction.id
|
6546
|
-
end
|
6547
|
-
|
6548
|
-
it "assigns the refunded_transaction_id to the original transaction" do
|
6549
|
-
transaction = create_transaction_to_refund
|
6550
|
-
refund_transaction = transaction.refund.new_transaction
|
6551
|
-
|
6552
|
-
refund_transaction.refunded_transaction_id.should == transaction.id
|
6553
|
-
end
|
6554
|
-
|
6555
|
-
it "returns an error if already refunded" do
|
6556
|
-
transaction = create_transaction_to_refund
|
6557
|
-
result = transaction.refund
|
6558
|
-
result.success?.should == true
|
6559
|
-
result = transaction.refund
|
6560
|
-
result.success?.should == false
|
6561
|
-
result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::HasAlreadyBeenRefunded
|
6562
|
-
end
|
6563
|
-
|
6564
|
-
it "returns an error result if unsettled" do
|
6565
|
-
transaction = Braintree::Transaction.create!(
|
6566
|
-
:type => "sale",
|
6567
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6568
|
-
:credit_card => {
|
6569
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6570
|
-
:expiration_date => "05/2009"
|
6571
|
-
}
|
6572
|
-
)
|
6573
|
-
result = transaction.refund
|
6574
|
-
result.success?.should == false
|
6575
|
-
result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotRefundUnlessSettled
|
6576
|
-
end
|
6577
|
-
end
|
6578
|
-
|
6579
|
-
describe "submit_for_settlement" do
|
6580
|
-
it "returns a successful result if successful" do
|
6581
|
-
transaction = Braintree::Transaction.sale!(
|
6582
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6583
|
-
:credit_card => {
|
6584
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6585
|
-
:expiration_date => "06/2009"
|
6586
|
-
}
|
6587
|
-
)
|
6588
|
-
result = transaction.submit_for_settlement
|
6589
|
-
result.success?.should == true
|
6590
|
-
end
|
6591
|
-
|
6592
|
-
it "can submit a specific amount for settlement" do
|
6593
|
-
transaction = Braintree::Transaction.sale!(
|
6594
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6595
|
-
:credit_card => {
|
6596
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6597
|
-
:expiration_date => "06/2009"
|
6598
|
-
}
|
6599
|
-
)
|
6600
|
-
transaction.amount.should == BigDecimal("1000.00")
|
6601
|
-
result = transaction.submit_for_settlement("999.99")
|
6602
|
-
result.success?.should == true
|
6603
|
-
transaction.amount.should == BigDecimal("999.99")
|
6604
|
-
end
|
6605
|
-
|
6606
|
-
it "updates the transaction attributes" do
|
6607
|
-
transaction = Braintree::Transaction.sale!(
|
6608
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6609
|
-
:credit_card => {
|
6610
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6611
|
-
:expiration_date => "06/2009"
|
6612
|
-
}
|
6613
|
-
)
|
6614
|
-
transaction.amount.should == BigDecimal("1000.00")
|
6615
|
-
result = transaction.submit_for_settlement("999.99")
|
6616
|
-
result.success?.should == true
|
6617
|
-
transaction.amount.should == BigDecimal("999.99")
|
6618
|
-
transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
|
6619
|
-
transaction.updated_at.between?(Time.now - 60, Time.now).should == true
|
6620
|
-
end
|
6621
|
-
|
6622
|
-
it "returns an error result if unsuccessful" do
|
6623
|
-
transaction = Braintree::Transaction.sale!(
|
6624
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6625
|
-
:credit_card => {
|
6626
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6627
|
-
:expiration_date => "06/2009"
|
6628
|
-
}
|
6629
|
-
)
|
6630
|
-
transaction.amount.should == BigDecimal("1000.00")
|
6631
|
-
result = transaction.submit_for_settlement("1000.01")
|
6632
|
-
result.success?.should == false
|
6633
|
-
result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::SettlementAmountIsTooLarge
|
6634
|
-
result.params[:transaction][:amount].should == "1000.01"
|
6635
|
-
end
|
6636
|
-
end
|
6637
|
-
|
6638
|
-
describe "submit_for_settlement!" do
|
6639
|
-
it "returns the transaction if successful" do
|
6640
|
-
original_transaction = Braintree::Transaction.sale!(
|
6641
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6642
|
-
:credit_card => {
|
6643
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6644
|
-
:expiration_date => "06/2009"
|
6645
|
-
}
|
6646
|
-
)
|
6647
|
-
transaction = original_transaction.submit_for_settlement!
|
6648
|
-
transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
|
6649
|
-
transaction.id.should == original_transaction.id
|
6650
|
-
end
|
6651
|
-
|
6652
|
-
it "raises a ValidationsFailed if unsuccessful" do
|
6653
|
-
transaction = Braintree::Transaction.sale!(
|
6654
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6655
|
-
:credit_card => {
|
6656
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6657
|
-
:expiration_date => "06/2009"
|
6658
|
-
}
|
6659
|
-
)
|
6660
|
-
transaction.amount.should == BigDecimal("1000.00")
|
6661
|
-
expect do
|
6662
|
-
transaction.submit_for_settlement!("1000.01")
|
6663
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
6664
|
-
end
|
6665
|
-
end
|
6666
|
-
|
6667
6416
|
describe "status_history" do
|
6668
6417
|
it "returns an array of StatusDetail" do
|
6669
6418
|
transaction = Braintree::Transaction.sale!(
|
@@ -6673,10 +6422,10 @@ describe Braintree::Transaction do
|
|
6673
6422
|
:expiration_date => "05/2009"
|
6674
6423
|
}
|
6675
6424
|
)
|
6676
|
-
|
6677
|
-
|
6678
|
-
|
6679
|
-
|
6425
|
+
result = Braintree::Transaction.submit_for_settlement!(transaction.id)
|
6426
|
+
result.status_history.size.should == 2
|
6427
|
+
result.status_history[0].status.should == Braintree::Transaction::Status::Authorized
|
6428
|
+
result.status_history[1].status.should == Braintree::Transaction::Status::SubmittedForSettlement
|
6680
6429
|
end
|
6681
6430
|
end
|
6682
6431
|
|
@@ -6731,7 +6480,7 @@ describe Braintree::Transaction do
|
|
6731
6480
|
:expiration_date => "05/2010"
|
6732
6481
|
}
|
6733
6482
|
)
|
6734
|
-
transaction = customer.credit_cards[0].
|
6483
|
+
transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, {:amount => "100.00"}).transaction
|
6735
6484
|
transaction.vault_credit_card.should == customer.credit_cards[0]
|
6736
6485
|
end
|
6737
6486
|
|
@@ -6756,7 +6505,7 @@ describe Braintree::Transaction do
|
|
6756
6505
|
:expiration_date => "05/2010"
|
6757
6506
|
}
|
6758
6507
|
)
|
6759
|
-
transaction = customer.credit_cards[0].
|
6508
|
+
transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, :amount => "100.00").transaction
|
6760
6509
|
transaction.vault_customer.should == customer
|
6761
6510
|
end
|
6762
6511
|
|
@@ -6773,68 +6522,6 @@ describe Braintree::Transaction do
|
|
6773
6522
|
end
|
6774
6523
|
end
|
6775
6524
|
|
6776
|
-
describe "void" do
|
6777
|
-
it "returns a successful result if successful" do
|
6778
|
-
result = Braintree::Transaction.create(
|
6779
|
-
:type => "sale",
|
6780
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6781
|
-
:credit_card => {
|
6782
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6783
|
-
:expiration_date => "05/2009"
|
6784
|
-
}
|
6785
|
-
)
|
6786
|
-
result.success?.should == true
|
6787
|
-
transaction = result.transaction
|
6788
|
-
transaction.status.should == Braintree::Transaction::Status::Authorized
|
6789
|
-
void_result = transaction.void
|
6790
|
-
void_result.success?.should == true
|
6791
|
-
void_result.transaction.should == transaction
|
6792
|
-
transaction.status.should == void_result.transaction.status
|
6793
|
-
end
|
6794
|
-
|
6795
|
-
it "returns an error result if unsuccessful" do
|
6796
|
-
transaction = Braintree::Transaction.sale(
|
6797
|
-
:amount => Braintree::Test::TransactionAmounts::Decline,
|
6798
|
-
:credit_card => {
|
6799
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6800
|
-
:expiration_date => "05/2009"
|
6801
|
-
}
|
6802
|
-
).transaction
|
6803
|
-
transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
6804
|
-
result = transaction.void
|
6805
|
-
result.success?.should == false
|
6806
|
-
result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotBeVoided
|
6807
|
-
end
|
6808
|
-
end
|
6809
|
-
|
6810
|
-
describe "void!" do
|
6811
|
-
it "returns the transaction if successful" do
|
6812
|
-
transaction = Braintree::Transaction.sale!(
|
6813
|
-
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
6814
|
-
:credit_card => {
|
6815
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6816
|
-
:expiration_date => "05/2009"
|
6817
|
-
}
|
6818
|
-
)
|
6819
|
-
transaction.void!.should == transaction
|
6820
|
-
transaction.status.should == Braintree::Transaction::Status::Voided
|
6821
|
-
end
|
6822
|
-
|
6823
|
-
it "raises a ValidationsFailed if unsuccessful" do
|
6824
|
-
transaction = Braintree::Transaction.sale(
|
6825
|
-
:amount => Braintree::Test::TransactionAmounts::Decline,
|
6826
|
-
:credit_card => {
|
6827
|
-
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6828
|
-
:expiration_date => "05/2009"
|
6829
|
-
}
|
6830
|
-
).transaction
|
6831
|
-
transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
6832
|
-
expect do
|
6833
|
-
transaction.void!
|
6834
|
-
end.to raise_error(Braintree::ValidationsFailed)
|
6835
|
-
end
|
6836
|
-
end
|
6837
|
-
|
6838
6525
|
def create_transaction_to_refund
|
6839
6526
|
transaction = Braintree::Transaction.sale!(
|
6840
6527
|
:amount => Braintree::Test::TransactionAmounts::Authorize,
|
@@ -7194,4 +6881,91 @@ describe Braintree::Transaction do
|
|
7194
6881
|
transaction.processed_with_network_token?.should == false
|
7195
6882
|
end
|
7196
6883
|
end
|
6884
|
+
|
6885
|
+
describe "installments" do
|
6886
|
+
it "creates a transaction with an installment count" do
|
6887
|
+
result = Braintree::Transaction.create(
|
6888
|
+
:type => "sale",
|
6889
|
+
:merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
|
6890
|
+
:credit_card => {
|
6891
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6892
|
+
:expiration_date => "05/2009"
|
6893
|
+
},
|
6894
|
+
:amount => "100.01",
|
6895
|
+
:installments => {
|
6896
|
+
:count => 12,
|
6897
|
+
},
|
6898
|
+
)
|
6899
|
+
|
6900
|
+
expect(result.success?).to eq(true)
|
6901
|
+
expect(result.transaction.installment_count).to eq(12)
|
6902
|
+
end
|
6903
|
+
|
6904
|
+
it "creates a transaction with a installments during capture" do
|
6905
|
+
result = Braintree::Transaction.create(
|
6906
|
+
:type => "sale",
|
6907
|
+
:merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
|
6908
|
+
:credit_card => {
|
6909
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6910
|
+
:expiration_date => "05/2009"
|
6911
|
+
},
|
6912
|
+
:amount => "100.01",
|
6913
|
+
:installments => {
|
6914
|
+
:count => 12,
|
6915
|
+
},
|
6916
|
+
:options => {
|
6917
|
+
:submit_for_settlement => true,
|
6918
|
+
},
|
6919
|
+
)
|
6920
|
+
|
6921
|
+
expect(result.success?).to eq(true)
|
6922
|
+
transaction = result.transaction
|
6923
|
+
expect(transaction.installment_count).to eq(12)
|
6924
|
+
|
6925
|
+
installments = transaction.installments
|
6926
|
+
expect(installments.map(&:id)).to match_array((1..12).map { |i| "#{transaction.id}_INST_#{i}" })
|
6927
|
+
expect(installments.map(&:amount)).to match_array([BigDecimal("8.33")] * 11 + [BigDecimal("8.38")])
|
6928
|
+
end
|
6929
|
+
|
6930
|
+
it "can refund a transaction with installments" do
|
6931
|
+
sale_result = Braintree::Transaction.create(
|
6932
|
+
:type => "sale",
|
6933
|
+
:merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
|
6934
|
+
:credit_card => {
|
6935
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
6936
|
+
:expiration_date => "05/2009"
|
6937
|
+
},
|
6938
|
+
:amount => "100.01",
|
6939
|
+
:installments => {
|
6940
|
+
:count => 12,
|
6941
|
+
},
|
6942
|
+
:options => {
|
6943
|
+
:submit_for_settlement => true,
|
6944
|
+
},
|
6945
|
+
)
|
6946
|
+
|
6947
|
+
expect(sale_result.success?).to eq(true)
|
6948
|
+
sale_transaction = sale_result.transaction
|
6949
|
+
|
6950
|
+
refund_result = Braintree::Transaction.refund(sale_transaction.id, "49.99")
|
6951
|
+
|
6952
|
+
expect(refund_result.success?).to eq(true)
|
6953
|
+
refund_transaction = refund_result.transaction
|
6954
|
+
installments = refund_transaction.refunded_installments
|
6955
|
+
|
6956
|
+
(1..11).each do |i|
|
6957
|
+
installment = installments.find { |installment| installment.id == "#{sale_transaction.id}_INST_#{i}" }
|
6958
|
+
|
6959
|
+
expect(installment.amount).to eq(BigDecimal("8.33"))
|
6960
|
+
expect(installment.adjustments.map(&:amount)).to match_array([BigDecimal("-4.16")])
|
6961
|
+
expect(installment.adjustments.map(&:kind)).to match_array([Braintree::Transaction::Installment::Adjustment::Kind::Refund])
|
6962
|
+
end
|
6963
|
+
|
6964
|
+
installment = installments.find { |installment| installment.id == "#{sale_transaction.id}_INST_12" }
|
6965
|
+
|
6966
|
+
expect(installment.amount).to eq(BigDecimal("8.38"))
|
6967
|
+
expect(installment.adjustments.map(&:amount)).to match_array([BigDecimal("-4.23")])
|
6968
|
+
expect(installment.adjustments.map(&:kind)).to match_array([Braintree::Transaction::Installment::Adjustment::Kind::Refund])
|
6969
|
+
end
|
6970
|
+
end
|
7197
6971
|
end
|