braintree 2.104.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree.rb +7 -18
  5. data/lib/braintree/account_updater_daily_report.rb +1 -1
  6. data/lib/braintree/address.rb +1 -23
  7. data/lib/braintree/apple_pay.rb +1 -1
  8. data/lib/braintree/apple_pay_card.rb +1 -1
  9. data/lib/braintree/apple_pay_options.rb +1 -1
  10. data/lib/braintree/authorization_adjustment.rb +1 -1
  11. data/lib/braintree/base_module.rb +6 -0
  12. data/lib/braintree/bin_data.rb +9 -2
  13. data/lib/braintree/client_token.rb +1 -1
  14. data/lib/braintree/configuration.rb +12 -12
  15. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  16. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  17. data/lib/braintree/credit_card.rb +2 -77
  18. data/lib/braintree/credit_card_gateway.rb +7 -36
  19. data/lib/braintree/credit_card_verification.rb +18 -5
  20. data/lib/braintree/credit_card_verification_search.rb +1 -1
  21. data/lib/braintree/customer.rb +5 -76
  22. data/lib/braintree/customer_gateway.rb +0 -23
  23. data/lib/braintree/customer_search.rb +1 -1
  24. data/lib/braintree/disbursement.rb +1 -1
  25. data/lib/braintree/dispute.rb +2 -8
  26. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +2 -2
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/error_codes.rb +151 -170
  31. data/lib/braintree/exceptions.rb +5 -3
  32. data/lib/braintree/gateway.rb +0 -14
  33. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +2 -3
  34. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  35. data/lib/braintree/graphql_client.rb +7 -7
  36. data/lib/braintree/http.rb +3 -3
  37. data/lib/braintree/local_payment_completed.rb +1 -1
  38. data/lib/braintree/local_payment_reversed.rb +19 -0
  39. data/lib/braintree/merchant.rb +1 -1
  40. data/lib/braintree/merchant_account.rb +1 -1
  41. data/lib/braintree/merchant_account_gateway.rb +3 -1
  42. data/lib/braintree/merchant_gateway.rb +1 -1
  43. data/lib/braintree/modification.rb +1 -1
  44. data/lib/braintree/oauth_credentials.rb +1 -1
  45. data/lib/braintree/oauth_gateway.rb +5 -5
  46. data/lib/braintree/payment_instrument_type.rb +10 -14
  47. data/lib/braintree/payment_method_gateway.rb +8 -13
  48. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  49. data/lib/braintree/payment_method_parser.rb +1 -8
  50. data/lib/braintree/plan.rb +1 -1
  51. data/lib/braintree/processor_response_types.rb +3 -3
  52. data/lib/braintree/resource_collection.rb +8 -3
  53. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  54. data/lib/braintree/risk_data.rb +3 -1
  55. data/lib/braintree/samsung_pay_card.rb +1 -1
  56. data/lib/braintree/settlement_batch_summary.rb +2 -2
  57. data/lib/braintree/subscription.rb +11 -11
  58. data/lib/braintree/successful_result.rb +0 -1
  59. data/lib/braintree/test/credit_card.rb +1 -0
  60. data/lib/braintree/test/nonce.rb +4 -23
  61. data/lib/braintree/three_d_secure_info.rb +22 -12
  62. data/lib/braintree/transaction.rb +44 -104
  63. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  64. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  65. data/lib/braintree/transaction/installment.rb +28 -0
  66. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  67. data/lib/braintree/transaction/paypal_details.rb +1 -0
  68. data/lib/braintree/transaction/subscription_details.rb +2 -0
  69. data/lib/braintree/transaction_gateway.rb +37 -25
  70. data/lib/braintree/transaction_line_item.rb +1 -1
  71. data/lib/braintree/transaction_search.rb +3 -2
  72. data/lib/braintree/unknown_payment_method.rb +1 -1
  73. data/lib/braintree/us_bank_account.rb +3 -3
  74. data/lib/braintree/us_bank_account_verification.rb +1 -1
  75. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  76. data/lib/braintree/util.rb +21 -6
  77. data/lib/braintree/venmo_account.rb +1 -1
  78. data/lib/braintree/version.rb +3 -3
  79. data/lib/braintree/visa_checkout_card.rb +2 -2
  80. data/lib/braintree/webhook_notification.rb +28 -29
  81. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  82. data/lib/braintree/webhook_testing_gateway.rb +10 -43
  83. data/lib/braintree/xml/generator.rb +5 -4
  84. data/lib/braintree/xml/libxml.rb +1 -0
  85. data/lib/braintree/xml/parser.rb +21 -44
  86. data/spec/integration/braintree/add_on_spec.rb +1 -1
  87. data/spec/integration/braintree/address_spec.rb +26 -113
  88. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  89. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  90. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  91. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  92. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  93. data/spec/integration/braintree/credit_card_spec.rb +130 -593
  94. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  95. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  96. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  97. data/spec/integration/braintree/customer_spec.rb +336 -509
  98. data/spec/integration/braintree/dispute_search_spec.rb +6 -6
  99. data/spec/integration/braintree/dispute_spec.rb +6 -7
  100. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  101. data/spec/integration/braintree/http_spec.rb +2 -2
  102. data/spec/integration/braintree/merchant_account_spec.rb +25 -26
  103. data/spec/integration/braintree/merchant_spec.rb +14 -14
  104. data/spec/integration/braintree/oauth_spec.rb +11 -11
  105. data/spec/integration/braintree/payment_method_nonce_spec.rb +12 -12
  106. data/spec/integration/braintree/payment_method_spec.rb +403 -269
  107. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  108. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  109. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  110. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  111. data/spec/integration/braintree/subscription_spec.rb +144 -149
  112. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  113. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  114. data/spec/integration/braintree/transaction_search_spec.rb +96 -70
  115. data/spec/integration/braintree/transaction_spec.rb +832 -904
  116. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  117. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  118. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  119. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  120. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  121. data/spec/integration/spec_helper.rb +10 -7
  122. data/spec/oauth_test_helper.rb +1 -1
  123. data/spec/script/httpsd.rb +6 -6
  124. data/spec/spec_helper.rb +6 -14
  125. data/spec/unit/braintree/address_spec.rb +1 -9
  126. data/spec/unit/braintree/apple_pay_card_spec.rb +1 -1
  127. data/spec/unit/braintree/client_token_spec.rb +2 -2
  128. data/spec/unit/braintree/configuration_spec.rb +42 -42
  129. data/spec/unit/braintree/credit_card_spec.rb +9 -28
  130. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  131. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  132. data/spec/unit/braintree/customer_spec.rb +5 -16
  133. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  134. data/spec/unit/braintree/dispute_spec.rb +9 -20
  135. data/spec/unit/braintree/error_result_spec.rb +5 -5
  136. data/spec/unit/braintree/errors_spec.rb +8 -8
  137. data/spec/unit/braintree/http_spec.rb +8 -8
  138. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  139. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  140. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  141. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  142. data/spec/unit/braintree/risk_data_spec.rb +9 -5
  143. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  144. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  145. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  146. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  147. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  148. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  149. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  150. data/spec/unit/braintree/transaction/paypal_details_spec.rb +3 -1
  151. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  152. data/spec/unit/braintree/transaction_spec.rb +25 -51
  153. data/spec/unit/braintree/util_spec.rb +55 -21
  154. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  155. data/spec/unit/braintree/webhook_notification_spec.rb +73 -57
  156. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  157. data/spec/unit/braintree/xml_spec.rb +31 -31
  158. metadata +30 -31
  159. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  160. data/lib/braintree/coinbase_account.rb +0 -34
  161. data/lib/braintree/europe_bank_account.rb +0 -36
  162. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  163. data/lib/braintree/ideal_payment.rb +0 -61
  164. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  165. data/lib/braintree/masterpass_card.rb +0 -83
  166. data/lib/braintree/settlement_batch.rb +0 -0
  167. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  168. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  169. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  170. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  171. data/lib/braintree/transparent_redirect.rb +0 -40
  172. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  173. data/lib/braintree/xml/rexml.rb +0 -71
  174. data/spec/hacks/tcp_socket.rb +0 -18
  175. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  176. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  177. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  178. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  179. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -24,7 +24,7 @@ describe Braintree::Transaction do
24
24
  :country_code_alpha2 => "BT",
25
25
  :country_code_alpha3 => "BTN",
26
26
  :country_code_numeric => "064"
27
- }
27
+ },
28
28
  )
29
29
  result.success?.should == true
30
30
 
@@ -34,7 +34,7 @@ describe Braintree::Transaction do
34
34
  :channel => "MyShoppingCartProvider",
35
35
  :options => {
36
36
  :submit_for_settlement => false
37
- }
37
+ },
38
38
  )
39
39
  clone_result.success?.should == true
40
40
 
@@ -67,7 +67,7 @@ describe Braintree::Transaction do
67
67
  :credit_card => {
68
68
  :number => "5105105105105100",
69
69
  :expiration_date => "05/2012"
70
- }
70
+ },
71
71
  )
72
72
 
73
73
  result.success?.should be(true)
@@ -84,7 +84,7 @@ describe Braintree::Transaction do
84
84
  :credit_card => {
85
85
  :number => Braintree::Test::CreditCardNumbers::Visa,
86
86
  :expiration_date => "05/2009"
87
- }
87
+ },
88
88
  )
89
89
  result = Braintree::Transaction.clone_transaction(transaction.id, :amount => "112.44")
90
90
  result.success?.should be(false)
@@ -100,7 +100,7 @@ describe Braintree::Transaction do
100
100
  :credit_card => {
101
101
  :number => Braintree::Test::CreditCardNumbers::Visa,
102
102
  :expiration_date => "05/2009"
103
- }
103
+ },
104
104
  )
105
105
  clone_transaction = Braintree::Transaction.clone_transaction!(transaction.id, :amount => "112.44", :options => {:submit_for_settlement => false})
106
106
  clone_transaction.id.should_not == transaction.id
@@ -112,7 +112,7 @@ describe Braintree::Transaction do
112
112
  :credit_card => {
113
113
  :number => Braintree::Test::CreditCardNumbers::Visa,
114
114
  :expiration_date => "05/2009"
115
- }
115
+ },
116
116
  )
117
117
  expect do
118
118
  clone_transaction = Braintree::Transaction.clone_transaction!(transaction.id, :amount => "im not a number")
@@ -123,26 +123,28 @@ 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 id" do
127
- with_advanced_fraud_integration_merchant do
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,
131
131
  :credit_card => {
132
132
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Prepaid,
133
133
  :expiration_date => "05/2009"
134
- }
134
+ },
135
135
  )
136
136
  result.transaction.risk_data.should be_a(Braintree::RiskData)
137
- result.transaction.risk_data.should respond_to(:id)
138
- result.transaction.risk_data.should respond_to(:decision)
139
- result.transaction.risk_data.should respond_to(:device_data_captured)
140
- result.transaction.risk_data.should respond_to(:fraud_service_provider)
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
+ expect(result.transaction.risk_data).to respond_to(:device_data_captured)
141
+ expect(result.transaction.risk_data).to respond_to(:fraud_service_provider)
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
- with_advanced_fraud_integration_merchant do
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,
@@ -156,10 +158,9 @@ describe Braintree::Transaction do
156
158
  :customer_ip => "192.168.0.1",
157
159
  :customer_location_zip => "not-a-$#phone",
158
160
  :customer_tenure => "20#{"0" * 500}"
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
@@ -175,13 +176,49 @@ describe Braintree::Transaction do
175
176
  :credit_card => {
176
177
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Prepaid,
177
178
  :expiration_date => "05/2009"
178
- }
179
+ },
179
180
  )
180
181
  result.transaction.credit_card_details.prepaid.should == Braintree::CreditCard::Prepaid::Yes
181
182
  result.transaction.payment_instrument_type.should == Braintree::PaymentInstrumentType::CreditCard
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
@@ -215,7 +252,7 @@ describe Braintree::Transaction do
215
252
  },
216
253
  ],
217
254
  }
218
- }
255
+ },
219
256
  )
220
257
  result.success?.should be(true)
221
258
  end
@@ -242,15 +279,15 @@ describe Braintree::Transaction do
242
279
  },
243
280
  ],
244
281
  }
245
- }
282
+ },
246
283
  )
247
284
  result.success?.should be(false)
248
285
  invalid_folio = Braintree::ErrorCodes::Transaction::Industry::Lodging::FolioNumberIsInvalid
249
286
  check_out_date_must_follow_check_in_date = Braintree::ErrorCodes::Transaction::Industry::Lodging::CheckOutDateMustFollowCheckInDate
250
287
  room_rate_format_is_invalid = Braintree::ErrorCodes::Transaction::Industry::Lodging::RoomRateFormatIsInvalid
251
288
  invalid_additional_charge_kind = Braintree::ErrorCodes::Transaction::Industry::AdditionalCharge::KindIsInvalid
252
- result.errors.for(:transaction).for(:industry).map { |e| e.code }.sort.should include *[invalid_folio, check_out_date_must_follow_check_in_date, room_rate_format_is_invalid]
253
- result.errors.for(:transaction).for(:industry).for(:additional_charges).for(:index_0).on(:kind).map { |e| e.code }.sort.should include *[invalid_additional_charge_kind]
289
+ result.errors.for(:transaction).for(:industry).map { |e| e.code }.sort.should include(*[invalid_folio, check_out_date_must_follow_check_in_date, room_rate_format_is_invalid])
290
+ result.errors.for(:transaction).for(:industry).for(:additional_charges).for(:index_0).on(:kind).map { |e| e.code }.sort.should include(*[invalid_additional_charge_kind])
254
291
  end
255
292
  end
256
293
 
@@ -272,7 +309,7 @@ describe Braintree::Transaction do
272
309
  :lodging_check_out_date => "2014-07-07",
273
310
  :lodging_name => "Royal Caribbean",
274
311
  }
275
- }
312
+ },
276
313
  )
277
314
  result.success?.should be(true)
278
315
  end
@@ -290,7 +327,7 @@ describe Braintree::Transaction do
290
327
  :data => {
291
328
  :lodging_name => "Royal Caribbean"
292
329
  }
293
- }
330
+ },
294
331
  )
295
332
  result.success?.should be(false)
296
333
  result.errors.for(:transaction).for(:industry).map { |e| e.code }.sort.should == [Braintree::ErrorCodes::Transaction::Industry::TravelCruise::TravelPackageIsInvalid]
@@ -364,7 +401,7 @@ describe Braintree::Transaction do
364
401
  }
365
402
  ]
366
403
  }
367
- }
404
+ },
368
405
  )
369
406
  result.success?.should be(true)
370
407
  end
@@ -388,7 +425,7 @@ describe Braintree::Transaction do
388
425
  }
389
426
  ]
390
427
  }
391
- }
428
+ },
392
429
  )
393
430
  result.success?.should be(false)
394
431
  result.errors.for(:transaction).for(:industry).map { |e| e.code }.sort.should == [Braintree::ErrorCodes::Transaction::Industry::TravelFlight::FareAmountCannotBeNegative]
@@ -407,7 +444,7 @@ describe Braintree::Transaction do
407
444
  :number => Braintree::Test::CreditCardNumbers::Elo,
408
445
  :cvv => "737",
409
446
  :expiration_date => "10/2020"
410
- }
447
+ },
411
448
  )
412
449
  result.success?.should == true
413
450
  result.transaction.id.should =~ /^\w{6,}$/
@@ -429,7 +466,7 @@ describe Braintree::Transaction do
429
466
  :credit_card => {
430
467
  :number => Braintree::Test::CreditCardNumbers::Visa,
431
468
  :expiration_date => "05/2009"
432
- }
469
+ },
433
470
  )
434
471
  result.success?.should == true
435
472
  result.transaction.id.should =~ /^\w{6,}$/
@@ -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
@@ -454,7 +492,7 @@ describe Braintree::Transaction do
454
492
  :credit_card => {
455
493
  :number => Braintree::Test::CreditCardNumbers::Visa,
456
494
  :expiration_date => "05/2009"
457
- }
495
+ },
458
496
  )
459
497
  expect(result.success?).to eq(true)
460
498
  expect(result.transaction.type).to eq("sale")
@@ -476,7 +514,7 @@ describe Braintree::Transaction do
476
514
  oauth_gateway = Braintree::Gateway.new(
477
515
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
478
516
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
479
- :logger => Logger.new("/dev/null")
517
+ :logger => Logger.new("/dev/null"),
480
518
  )
481
519
  access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
482
520
  :merchant_public_id => "integration_merchant_id",
@@ -485,7 +523,7 @@ describe Braintree::Transaction do
485
523
 
486
524
  gateway = Braintree::Gateway.new(
487
525
  :access_token => access_token,
488
- :logger => Logger.new("/dev/null")
526
+ :logger => Logger.new("/dev/null"),
489
527
  )
490
528
 
491
529
  result = gateway.transaction.create(
@@ -494,7 +532,7 @@ describe Braintree::Transaction do
494
532
  :credit_card => {
495
533
  :number => Braintree::Test::CreditCardNumbers::Visa,
496
534
  :expiration_date => "05/2009"
497
- }
535
+ },
498
536
  )
499
537
 
500
538
  result.success?.should == true
@@ -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: device_session_id and fraud_merchant_id" do
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
- :device_session_id => "abc123",
521
- :fraud_merchant_id => "7"
558
+ :device_data => "device_data",
522
559
  )
523
560
 
524
561
  result.success?.should == true
@@ -538,7 +575,7 @@ describe Braintree::Transaction do
538
575
  :customer_ip => "192.168.0.1",
539
576
  :customer_location_zip => "91244",
540
577
  :customer_tenure => "20",
541
- }
578
+ },
542
579
  )
543
580
 
544
581
  result.success?.should == true
@@ -548,7 +585,7 @@ describe Braintree::Transaction do
548
585
  result = Braintree::Customer.create()
549
586
  address_result = Braintree::Address.create(
550
587
  :customer_id => result.customer.id,
551
- :country_code_alpha2 => "US"
588
+ :country_code_alpha2 => "US",
552
589
  )
553
590
 
554
591
  result = Braintree::Transaction.create(
@@ -559,7 +596,7 @@ describe Braintree::Transaction do
559
596
  :credit_card => {
560
597
  :number => Braintree::Test::CreditCardNumbers::Visa,
561
598
  :expiration_date => "05/2009"
562
- }
599
+ },
563
600
  )
564
601
 
565
602
  result.success?.should == true
@@ -572,7 +609,7 @@ describe Braintree::Transaction do
572
609
  :credit_card => {
573
610
  :number => Braintree::Test::CreditCardNumbers::Visa,
574
611
  :expiration_date => "05/2009"
575
- }
612
+ },
576
613
  )
577
614
  result.success?.should == false
578
615
  result.transaction.id.should =~ /^\w{6,}$/
@@ -591,7 +628,7 @@ describe Braintree::Transaction do
591
628
  :credit_card => {
592
629
  :number => Braintree::Test::CreditCardNumbers::Visa,
593
630
  :expiration_date => "05/2009"
594
- }
631
+ },
595
632
  )
596
633
  result.success?.should == false
597
634
  result.transaction.id.should =~ /^\w{6,}$/
@@ -628,7 +665,7 @@ describe Braintree::Transaction do
628
665
  :options => {
629
666
  :add_billing_address_to_payment_method => true,
630
667
  :store_in_vault => true
631
- }
668
+ },
632
669
  )
633
670
  result.success?.should == true
634
671
  transaction = result.transaction
@@ -658,7 +695,7 @@ describe Braintree::Transaction do
658
695
  :billing => {
659
696
  :country_name => "Botswana",
660
697
  :country_code_alpha2 => "US",
661
- }
698
+ },
662
699
  )
663
700
 
664
701
  result.success?.should == false
@@ -674,7 +711,7 @@ describe Braintree::Transaction do
674
711
  },
675
712
  :billing => {
676
713
  :country_code_alpha2 => "ZZ"
677
- }
714
+ },
678
715
  )
679
716
 
680
717
  result.success?.should == false
@@ -691,7 +728,7 @@ describe Braintree::Transaction do
691
728
  },
692
729
  :billing => {
693
730
  :country_code_alpha3 => "ZZZ"
694
- }
731
+ },
695
732
  )
696
733
 
697
734
  result.success?.should == false
@@ -708,7 +745,7 @@ describe Braintree::Transaction do
708
745
  },
709
746
  :billing => {
710
747
  :country_code_numeric => "FOO"
711
- }
748
+ },
712
749
  )
713
750
 
714
751
  result.success?.should == false
@@ -739,7 +776,7 @@ describe Braintree::Transaction do
739
776
  },
740
777
  :shipping => {
741
778
  :phone_number => "123-234-3456=098765"
742
- }
779
+ },
743
780
  )
744
781
 
745
782
  result.success?.should == false
@@ -755,7 +792,7 @@ describe Braintree::Transaction do
755
792
  },
756
793
  :shipping => {
757
794
  :shipping_method => "urgent"
758
- }
795
+ },
759
796
  )
760
797
 
761
798
  result.success?.should == false
@@ -771,7 +808,7 @@ describe Braintree::Transaction do
771
808
  },
772
809
  :billing => {
773
810
  :phone_number => "123-234-3456=098765"
774
- }
811
+ },
775
812
  )
776
813
 
777
814
  result.success?.should == false
@@ -795,7 +832,7 @@ describe Braintree::Transaction do
795
832
  :number => Braintree::Test::CreditCardNumbers::Visa,
796
833
  :expiration_date => "05/2009",
797
834
  :cvv => "200"
798
- }
835
+ },
799
836
  )
800
837
  result.success?.should == false
801
838
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::CVV
@@ -810,17 +847,17 @@ describe Braintree::Transaction do
810
847
  gateway = Braintree::Gateway.new(
811
848
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
812
849
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
813
- :logger => Logger.new("/dev/null")
850
+ :logger => Logger.new("/dev/null"),
814
851
  )
815
852
  result = gateway.merchant.create(
816
853
  :email => "name@email.com",
817
854
  :country_code_alpha3 => "USA",
818
- :payment_methods => ["credit_card", "paypal"]
855
+ :payment_methods => ["credit_card", "paypal"],
819
856
  )
820
857
 
821
858
  gateway = Braintree::Gateway.new(
822
859
  :access_token => result.credentials.access_token,
823
- :logger => Logger.new("/dev/null")
860
+ :logger => Logger.new("/dev/null"),
824
861
  )
825
862
 
826
863
  result = gateway.transaction.create(
@@ -829,7 +866,7 @@ describe Braintree::Transaction do
829
866
  :credit_card => {
830
867
  :number => Braintree::Test::CreditCardNumbers::Visa,
831
868
  :expiration_date => "05/2020"
832
- }
869
+ },
833
870
  )
834
871
  result.success?.should == false
835
872
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::ApplicationIncomplete
@@ -853,7 +890,7 @@ describe Braintree::Transaction do
853
890
  :credit_card => {
854
891
  :number => Braintree::Test::CreditCardNumbers::Visa,
855
892
  :expiration_date => "05/2009"
856
- }
893
+ },
857
894
  )
858
895
  result.success?.should == false
859
896
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::AVS
@@ -883,7 +920,7 @@ describe Braintree::Transaction do
883
920
  :number => Braintree::Test::CreditCardNumbers::Visa,
884
921
  :expiration_date => "05/2009",
885
922
  :cvv => "200"
886
- }
923
+ },
887
924
  )
888
925
  result.success?.should == false
889
926
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::AVSAndCVV
@@ -895,14 +932,14 @@ describe Braintree::Transaction do
895
932
  end
896
933
 
897
934
  it "exposes the fraud gateway rejection reason" do
898
- with_advanced_fraud_integration_merchant do
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 => {
902
939
  :number => Braintree::Test::CreditCardNumbers::Fraud,
903
940
  :expiration_date => "05/2017",
904
941
  :cvv => "333"
905
- }
942
+ },
906
943
  )
907
944
  result.success?.should == false
908
945
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::Fraud
@@ -910,14 +947,14 @@ 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
- with_advanced_fraud_integration_merchant do
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 => {
917
954
  :number => Braintree::Test::CreditCardNumbers::RiskThreshold,
918
955
  :expiration_date => "05/2017",
919
956
  :cvv => "333"
920
- }
957
+ },
921
958
  )
922
959
  result.success?.should == false
923
960
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::RiskThreshold
@@ -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
- with_advanced_fraud_integration_merchant do
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,
@@ -954,7 +991,7 @@ describe Braintree::Transaction do
954
991
  :number => Braintree::Test::CreditCardNumbers::Visa,
955
992
  :expiration_month => "05",
956
993
  :expiration_year => "2011"
957
- }
994
+ },
958
995
  )
959
996
  result.success?.should == true
960
997
  result.transaction.credit_card_details.expiration_month.should == "05"
@@ -966,7 +1003,7 @@ describe Braintree::Transaction do
966
1003
  result = Braintree::Transaction.create(
967
1004
  :type => "sale",
968
1005
  :amount => Braintree::Test::TransactionAmounts::Decline,
969
- :customer_id => 123456789
1006
+ :customer_id => 123456789,
970
1007
  )
971
1008
  result.success?.should == false
972
1009
  result.errors.for(:transaction).on(:customer_id)[0].code.should == "91510"
@@ -983,7 +1020,7 @@ describe Braintree::Transaction do
983
1020
  },
984
1021
  :custom_fields => {
985
1022
  :store_me => "custom value"
986
- }
1023
+ },
987
1024
  )
988
1025
  result.success?.should == true
989
1026
  result.transaction.custom_fields.should == {:store_me => "custom value"}
@@ -998,7 +1035,7 @@ describe Braintree::Transaction do
998
1035
  },
999
1036
  :custom_fields => {
1000
1037
  :store_me => ""
1001
- }
1038
+ },
1002
1039
  )
1003
1040
 
1004
1041
  result = Braintree::Transaction.find(create_result.transaction.id)
@@ -1016,7 +1053,7 @@ describe Braintree::Transaction do
1016
1053
  },
1017
1054
  :custom_fields => {
1018
1055
  :invalid_key => "custom value"
1019
- }
1056
+ },
1020
1057
  )
1021
1058
  result.success?.should == false
1022
1059
  result.errors.for(:transaction).on(:custom_fields)[0].message.should == "Custom field is invalid: invalid_key."
@@ -1035,7 +1072,7 @@ describe Braintree::Transaction do
1035
1072
  }
1036
1073
  result = Braintree::Transaction.create(params[:transaction])
1037
1074
  result.success?.should == false
1038
- result.params.should == {:transaction => {:type => 'sale', :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
1075
+ result.params.should == {:transaction => {:type => "sale", :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
1039
1076
  end
1040
1077
 
1041
1078
  it "returns errors if validations fail (tests many errors at once for spec speed)" do
@@ -1055,7 +1092,7 @@ describe Braintree::Transaction do
1055
1092
  }
1056
1093
  result = Braintree::Transaction.create(params[:transaction])
1057
1094
  result.success?.should == false
1058
- result.errors.for(:transaction).on(:base).map{|error| error.code}.should include(Braintree::ErrorCodes::Transaction::PaymentMethodDoesNotBelongToCustomer)
1095
+ result.errors.for(:transaction).on(:base).map { |error| error.code }.should include(Braintree::ErrorCodes::Transaction::PaymentMethodDoesNotBelongToCustomer)
1059
1096
  result.errors.for(:transaction).on(:customer_id)[0].code.should == Braintree::ErrorCodes::Transaction::CustomerIdIsInvalid
1060
1097
  result.errors.for(:transaction).on(:payment_method_token)[0].code.should == Braintree::ErrorCodes::Transaction::PaymentMethodTokenIsInvalid
1061
1098
  result.errors.for(:transaction).on(:type)[0].code.should == Braintree::ErrorCodes::Transaction::TypeIsInvalid
@@ -1086,7 +1123,7 @@ describe Braintree::Transaction do
1086
1123
  :credit_card => {
1087
1124
  :account_type => "credit",
1088
1125
  }
1089
- }
1126
+ },
1090
1127
  )
1091
1128
  result.success?.should == false
1092
1129
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountNotSupportedByProcessor
@@ -1130,13 +1167,13 @@ describe Braintree::Transaction do
1130
1167
  :credit_card => {
1131
1168
  :number => Braintree::Test::CreditCardNumbers::Visa,
1132
1169
  :expiration_date => "05/2010"
1133
- }
1170
+ },
1134
1171
  )
1135
1172
  result = Braintree::Transaction.create(
1136
1173
  :type => "sale",
1137
1174
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1138
1175
  :customer_id => customer.id,
1139
- :payment_method_token => customer.credit_cards[0].token + "x"
1176
+ :payment_method_token => customer.credit_cards[0].token + "x",
1140
1177
  )
1141
1178
  result.success?.should == false
1142
1179
  result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::PaymentMethodDoesNotBelongToCustomer
@@ -1148,7 +1185,7 @@ describe Braintree::Transaction do
1148
1185
  :credit_card => {
1149
1186
  :number => Braintree::Test::CreditCardNumbers::Visa,
1150
1187
  :expiration_date => "05/2010"
1151
- }
1188
+ },
1152
1189
  )
1153
1190
  result = Braintree::Transaction.create(
1154
1191
  :type => "sale",
@@ -1157,7 +1194,7 @@ describe Braintree::Transaction do
1157
1194
  :credit_card => {
1158
1195
  :number => Braintree::Test::CreditCardNumbers::Visa,
1159
1196
  :expiration_date => "12/12"
1160
- }
1197
+ },
1161
1198
  )
1162
1199
  result.success?.should == true
1163
1200
  result.transaction.credit_card_details.masked_number.should == "401288******1881"
@@ -1169,7 +1206,7 @@ describe Braintree::Transaction do
1169
1206
  :credit_card => {
1170
1207
  :number => Braintree::Test::CreditCardNumbers::Visa,
1171
1208
  :expiration_date => "05/2010"
1172
- }
1209
+ },
1173
1210
  )
1174
1211
  result = Braintree::Transaction.create(
1175
1212
  :type => "sale",
@@ -1179,7 +1216,7 @@ describe Braintree::Transaction do
1179
1216
  :number => Braintree::Test::CreditCardNumbers::Visa,
1180
1217
  :expiration_date => "12/12",
1181
1218
  },
1182
- :options => { :store_in_vault => true }
1219
+ :options => {:store_in_vault => true},
1183
1220
  )
1184
1221
  result.success?.should == true
1185
1222
  result.transaction.credit_card_details.masked_number.should == "401288******1881"
@@ -1193,7 +1230,7 @@ describe Braintree::Transaction do
1193
1230
  :credit_card => {
1194
1231
  :number => Braintree::Test::CreditCardNumbers::Visa,
1195
1232
  :expiration_date => "05/2010"
1196
- }
1233
+ },
1197
1234
  )
1198
1235
 
1199
1236
  result = Braintree::Subscription.create(
@@ -1224,7 +1261,7 @@ describe Braintree::Transaction do
1224
1261
  :never_expires => true
1225
1262
  }
1226
1263
  ]
1227
- }
1264
+ },
1228
1265
  )
1229
1266
 
1230
1267
  result.success?.should be(true)
@@ -1265,15 +1302,15 @@ describe Braintree::Transaction do
1265
1302
  :expiration_date => "05/2009"
1266
1303
  },
1267
1304
  :descriptor => {
1268
- :name => '123*123456789012345678',
1269
- :phone => '3334445555',
1305
+ :name => "123*123456789012345678",
1306
+ :phone => "3334445555",
1270
1307
  :url => "ebay.com"
1271
- }
1308
+ },
1272
1309
  )
1273
1310
  result.success?.should == true
1274
- result.transaction.descriptor.name.should == '123*123456789012345678'
1275
- result.transaction.descriptor.phone.should == '3334445555'
1276
- result.transaction.descriptor.url.should == 'ebay.com'
1311
+ result.transaction.descriptor.name.should == "123*123456789012345678"
1312
+ result.transaction.descriptor.phone.should == "3334445555"
1313
+ result.transaction.descriptor.url.should == "ebay.com"
1277
1314
  end
1278
1315
 
1279
1316
  it "has validation errors if format is invalid" do
@@ -1284,10 +1321,10 @@ describe Braintree::Transaction do
1284
1321
  :expiration_date => "05/2009"
1285
1322
  },
1286
1323
  :descriptor => {
1287
- :name => 'badcompanyname12*badproduct12',
1288
- :phone => '%bad4445555',
1289
- :url => '12345678901234'
1290
- }
1324
+ :name => "badcompanyname12*badproduct12",
1325
+ :phone => "%bad4445555",
1326
+ :url => "12345678901234"
1327
+ },
1291
1328
  )
1292
1329
  result.success?.should == false
1293
1330
  result.errors.for(:transaction).for(:descriptor).on(:name)[0].code.should == Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid
@@ -1304,14 +1341,14 @@ describe Braintree::Transaction do
1304
1341
  :number => Braintree::Test::CreditCardNumbers::Visa,
1305
1342
  :expiration_date => "05/2009"
1306
1343
  },
1307
- :tax_amount => '0.05',
1344
+ :tax_amount => "0.05",
1308
1345
  :tax_exempt => false,
1309
- :purchase_order_number => '12345678901234567'
1346
+ :purchase_order_number => "12345678901234567",
1310
1347
  )
1311
1348
  result.success?.should == true
1312
1349
  result.transaction.tax_amount.should == BigDecimal("0.05")
1313
1350
  result.transaction.tax_exempt.should == false
1314
- result.transaction.purchase_order_number.should == '12345678901234567'
1351
+ result.transaction.purchase_order_number.should == "12345678901234567"
1315
1352
  end
1316
1353
 
1317
1354
  it "accepts tax_amount as a BigDecimal" do
@@ -1321,8 +1358,8 @@ describe Braintree::Transaction do
1321
1358
  :number => Braintree::Test::CreditCardNumbers::Visa,
1322
1359
  :expiration_date => "05/2009"
1323
1360
  },
1324
- :tax_amount => BigDecimal('1.99'),
1325
- :tax_exempt => true
1361
+ :tax_amount => BigDecimal("1.99"),
1362
+ :tax_exempt => true,
1326
1363
  )
1327
1364
  result.success?.should == true
1328
1365
  result.transaction.tax_amount.should == BigDecimal("1.99")
@@ -1338,7 +1375,7 @@ describe Braintree::Transaction do
1338
1375
  :number => Braintree::Test::CreditCardNumbers::Visa,
1339
1376
  :expiration_date => "05/2009"
1340
1377
  },
1341
- :tax_amount => 'abcd'
1378
+ :tax_amount => "abcd",
1342
1379
  )
1343
1380
  result.success?.should == false
1344
1381
  result.errors.for(:transaction).on(:tax_amount)[0].code.should == Braintree::ErrorCodes::Transaction::TaxAmountFormatIsInvalid
@@ -1351,7 +1388,7 @@ describe Braintree::Transaction do
1351
1388
  :number => Braintree::Test::CreditCardNumbers::Visa,
1352
1389
  :expiration_date => "05/2009"
1353
1390
  },
1354
- :purchase_order_number => 'a' * 18
1391
+ :purchase_order_number => "a" * 18,
1355
1392
  )
1356
1393
  result.success?.should == false
1357
1394
  result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsTooLong
@@ -1364,7 +1401,7 @@ describe Braintree::Transaction do
1364
1401
  :number => Braintree::Test::CreditCardNumbers::Visa,
1365
1402
  :expiration_date => "05/2009"
1366
1403
  },
1367
- :purchase_order_number => "\303\237\303\245\342\210\202"
1404
+ :purchase_order_number => "\303\237\303\245\342\210\202",
1368
1405
  )
1369
1406
  result.success?.should == false
1370
1407
  result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsInvalid
@@ -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(
@@ -1397,7 +1418,7 @@ describe Braintree::Transaction do
1397
1418
  :number => Braintree::Test::CreditCardNumbers::Visa,
1398
1419
  :expiration_date => "12/12",
1399
1420
  },
1400
- :transaction_source => "recurring_first"
1421
+ :transaction_source => "recurring_first",
1401
1422
  )
1402
1423
  result.success?.should == true
1403
1424
  result.transaction.recurring.should == true
@@ -1411,7 +1432,7 @@ describe Braintree::Transaction do
1411
1432
  :number => Braintree::Test::CreditCardNumbers::Visa,
1412
1433
  :expiration_date => "12/12",
1413
1434
  },
1414
- :transaction_source => "recurring"
1435
+ :transaction_source => "recurring",
1415
1436
  )
1416
1437
  result.success?.should == true
1417
1438
  result.transaction.recurring.should == true
@@ -1425,7 +1446,7 @@ describe Braintree::Transaction do
1425
1446
  :number => Braintree::Test::CreditCardNumbers::Visa,
1426
1447
  :expiration_date => "12/12",
1427
1448
  },
1428
- :transaction_source => "merchant"
1449
+ :transaction_source => "merchant",
1429
1450
  )
1430
1451
  result.success?.should == true
1431
1452
  result.transaction.recurring.should == false
@@ -1439,7 +1460,7 @@ describe Braintree::Transaction do
1439
1460
  :number => Braintree::Test::CreditCardNumbers::Visa,
1440
1461
  :expiration_date => "12/12",
1441
1462
  },
1442
- :transaction_source => "moto"
1463
+ :transaction_source => "moto",
1443
1464
  )
1444
1465
  result.success?.should == true
1445
1466
  result.transaction.recurring.should == false
@@ -1453,7 +1474,7 @@ describe Braintree::Transaction do
1453
1474
  :number => Braintree::Test::CreditCardNumbers::Visa,
1454
1475
  :expiration_date => "12/12",
1455
1476
  },
1456
- :transaction_source => "invalid_value"
1477
+ :transaction_source => "invalid_value",
1457
1478
  )
1458
1479
  result.success?.should == false
1459
1480
  result.errors.for(:transaction).on(:transaction_source)[0].code.should == Braintree::ErrorCodes::Transaction::TransactionSourceIsInvalid
@@ -1473,7 +1494,7 @@ describe Braintree::Transaction do
1473
1494
  :number => Braintree::Test::CreditCardNumbers::Visa,
1474
1495
  :expiration_date => "12/12",
1475
1496
  },
1476
- :options => { :store_in_vault_on_success => true }
1497
+ :options => {:store_in_vault_on_success => true},
1477
1498
  )
1478
1499
  result.success?.should == true
1479
1500
  result.transaction.vault_customer.last_name.should == "Doe"
@@ -1492,7 +1513,7 @@ describe Braintree::Transaction do
1492
1513
  :number => Braintree::Test::CreditCardNumbers::Visa,
1493
1514
  :expiration_date => "12/12",
1494
1515
  },
1495
- :options => { :store_in_vault_on_success => true }
1516
+ :options => {:store_in_vault_on_success => true},
1496
1517
  )
1497
1518
  result.success?.should == false
1498
1519
  result.transaction.vault_customer.should be_nil
@@ -1512,7 +1533,7 @@ describe Braintree::Transaction do
1512
1533
  :number => Braintree::Test::CreditCardNumbers::Visa,
1513
1534
  :expiration_date => "12/12",
1514
1535
  },
1515
- :options => { :store_in_vault_on_success => false }
1536
+ :options => {:store_in_vault_on_success => false},
1516
1537
  )
1517
1538
  result.success?.should == true
1518
1539
  result.transaction.vault_customer.should be_nil
@@ -1530,7 +1551,7 @@ describe Braintree::Transaction do
1530
1551
  :number => Braintree::Test::CreditCardNumbers::Visa,
1531
1552
  :expiration_date => "12/12",
1532
1553
  },
1533
- :options => { :store_in_vault_on_success => false }
1554
+ :options => {:store_in_vault_on_success => false},
1534
1555
  )
1535
1556
  result.success?.should == false
1536
1557
  result.transaction.vault_customer.should be_nil
@@ -1549,7 +1570,7 @@ describe Braintree::Transaction do
1549
1570
  :number => Braintree::Test::CreditCardNumbers::Visa,
1550
1571
  :expiration_date => "12/12",
1551
1572
  },
1552
- :service_fee_amount => "1.00"
1573
+ :service_fee_amount => "1.00",
1553
1574
  )
1554
1575
  result.success?.should == true
1555
1576
  result.transaction.service_fee_amount.should == BigDecimal("1.00")
@@ -1564,7 +1585,7 @@ describe Braintree::Transaction do
1564
1585
  :number => Braintree::Test::CreditCardNumbers::Visa,
1565
1586
  :expiration_date => "12/12",
1566
1587
  },
1567
- :service_fee_amount => "1.00"
1588
+ :service_fee_amount => "1.00",
1568
1589
  )
1569
1590
  result.success?.should == false
1570
1591
  expected_error_code = Braintree::ErrorCodes::Transaction::ServiceFeeAmountNotAllowedOnMasterMerchantAccount
@@ -1579,7 +1600,7 @@ describe Braintree::Transaction do
1579
1600
  :credit_card => {
1580
1601
  :number => Braintree::Test::CreditCardNumbers::Visa,
1581
1602
  :expiration_date => "12/12",
1582
- }
1603
+ },
1583
1604
  )
1584
1605
  result.success?.should == false
1585
1606
  expected_error_code = Braintree::ErrorCodes::Transaction::SubMerchantAccountRequiresServiceFeeAmount
@@ -1589,7 +1610,7 @@ describe Braintree::Transaction do
1589
1610
  it "raises an error if service fee amount is negative" do
1590
1611
  result = Braintree::Transaction.create(
1591
1612
  :merchant_account_id => SpecHelper::NonDefaultSubMerchantAccountId,
1592
- :service_fee_amount => "-1.00"
1613
+ :service_fee_amount => "-1.00",
1593
1614
  )
1594
1615
  result.success?.should == false
1595
1616
  result.errors.for(:transaction).on(:service_fee_amount)[0].code.should == Braintree::ErrorCodes::Transaction::ServiceFeeAmountCannotBeNegative
@@ -1598,7 +1619,7 @@ describe Braintree::Transaction do
1598
1619
  it "raises an error if service fee amount is invalid" do
1599
1620
  result = Braintree::Transaction.create(
1600
1621
  :merchant_account_id => SpecHelper::NonDefaultSubMerchantAccountId,
1601
- :service_fee_amount => "invalid amount"
1622
+ :service_fee_amount => "invalid amount",
1602
1623
  )
1603
1624
  result.success?.should == false
1604
1625
  result.errors.for(:transaction).on(:service_fee_amount)[0].code.should == Braintree::ErrorCodes::Transaction::ServiceFeeAmountFormatIsInvalid
@@ -1616,7 +1637,7 @@ describe Braintree::Transaction do
1616
1637
  :expiration_date => "12/12",
1617
1638
  },
1618
1639
  :service_fee_amount => "10.00",
1619
- :options => {:hold_in_escrow => true}
1640
+ :options => {:hold_in_escrow => true},
1620
1641
  )
1621
1642
 
1622
1643
  result.success?.should == true
@@ -1633,7 +1654,7 @@ describe Braintree::Transaction do
1633
1654
  :expiration_date => "12/12",
1634
1655
  },
1635
1656
  :service_fee_amount => "1.00",
1636
- :options => {:hold_in_escrow => true}
1657
+ :options => {:hold_in_escrow => true},
1637
1658
  )
1638
1659
  result.success?.should == false
1639
1660
  expected_error_code = Braintree::ErrorCodes::Transaction::CannotHoldInEscrow
@@ -1646,7 +1667,7 @@ describe Braintree::Transaction do
1646
1667
  result = Braintree::Transaction.create(
1647
1668
  :type => "sale",
1648
1669
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1649
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode
1670
+ :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode,
1650
1671
  )
1651
1672
  result.success?.should == true
1652
1673
  result.transaction.credit_card_details.bin.should == "400934"
@@ -1663,7 +1684,7 @@ describe Braintree::Transaction do
1663
1684
  },
1664
1685
  :options => {
1665
1686
  :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
1666
- }
1687
+ },
1667
1688
  )
1668
1689
  result.success?.should == true
1669
1690
  result.transaction.credit_card_details.venmo_sdk?.should == false
@@ -1678,14 +1699,14 @@ describe Braintree::Transaction do
1678
1699
  :expiration_month => "11",
1679
1700
  :expiration_year => "2099",
1680
1701
  },
1681
- :share => true
1702
+ :share => true,
1682
1703
  )
1683
1704
  nonce.should_not be_nil
1684
1705
 
1685
1706
  result = Braintree::Transaction.create(
1686
1707
  :type => "sale",
1687
1708
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1688
- :payment_method_nonce => nonce
1709
+ :payment_method_nonce => nonce,
1689
1710
  )
1690
1711
  result.success?.should == true
1691
1712
  end
@@ -1700,14 +1721,14 @@ describe Braintree::Transaction do
1700
1721
  },
1701
1722
  :client_token_options => {
1702
1723
  :customer_id => customer.id,
1703
- }
1724
+ },
1704
1725
  )
1705
1726
  nonce.should_not be_nil
1706
1727
 
1707
1728
  result = Braintree::Transaction.create(
1708
1729
  :type => "sale",
1709
1730
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1710
- :payment_method_nonce => nonce
1731
+ :payment_method_nonce => nonce,
1711
1732
  )
1712
1733
  result.success?.should == true
1713
1734
  end
@@ -1720,14 +1741,14 @@ describe Braintree::Transaction do
1720
1741
  },
1721
1742
  :client_token_options => {
1722
1743
  :customer_id => customer.id,
1723
- }
1744
+ },
1724
1745
  )
1725
1746
  nonce.should_not be_nil
1726
1747
 
1727
1748
  result = Braintree::Transaction.create(
1728
1749
  :type => "sale",
1729
1750
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1730
- :payment_method_nonce => nonce
1751
+ :payment_method_nonce => nonce,
1731
1752
  )
1732
1753
  result.success?.should == true
1733
1754
  result.transaction.paypal_details.should_not be_nil
@@ -1739,14 +1760,14 @@ describe Braintree::Transaction do
1739
1760
  nonce = nonce_for_new_payment_method(
1740
1761
  :paypal_account => {
1741
1762
  :consent_code => "PAYPAL_CONSENT_CODE",
1742
- }
1763
+ },
1743
1764
  )
1744
1765
  nonce.should_not be_nil
1745
1766
 
1746
1767
  result = Braintree::Transaction.create(
1747
1768
  :type => "sale",
1748
1769
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1749
- :payment_method_nonce => nonce
1770
+ :payment_method_nonce => nonce,
1750
1771
  )
1751
1772
  result.success?.should == true
1752
1773
  result.transaction.paypal_details.should_not be_nil
@@ -1758,7 +1779,7 @@ describe Braintree::Transaction do
1758
1779
  result = Braintree::Transaction.create(
1759
1780
  :type => "sale",
1760
1781
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1761
- :payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa
1782
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa,
1762
1783
  )
1763
1784
  result.success?.should == true
1764
1785
  result.transaction.should_not be_nil
@@ -1788,7 +1809,7 @@ describe Braintree::Transaction do
1788
1809
  :type => "sale",
1789
1810
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1790
1811
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa,
1791
- :options => { :store_in_vault_on_success => true }
1812
+ :options => {:store_in_vault_on_success => true},
1792
1813
  )
1793
1814
  result.success?.should == true
1794
1815
  result.transaction.should_not be_nil
@@ -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 android pay proxy card nonce" do
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::AndroidPayDiscover
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
- android_pay_details = result.transaction.android_pay_details
1817
- android_pay_details.should_not be_nil
1818
- android_pay_details.bin.should_not be_nil
1819
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1820
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1821
- android_pay_details.last_4.should == "1117"
1822
- android_pay_details.virtual_card_last_4.should == "1117"
1823
- android_pay_details.source_description.should == "Discover 1111"
1824
- android_pay_details.expiration_month.to_i.should > 0
1825
- android_pay_details.expiration_year.to_i.should > 0
1826
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1827
- android_pay_details.image_url.should_not be_nil
1828
- android_pay_details.is_network_tokenized?.should == false
1829
- android_pay_details.token.should be_nil
1830
- android_pay_details.prepaid.should_not be_nil
1831
- android_pay_details.healthcare.should_not be_nil
1832
- android_pay_details.debit.should_not be_nil
1833
- android_pay_details.durbin_regulated.should_not be_nil
1834
- android_pay_details.commercial.should_not be_nil
1835
- android_pay_details.payroll.should_not be_nil
1836
- android_pay_details.product_id.should_not be_nil
1837
- end
1838
-
1839
- it "can create a vaulted transaction with a fake android pay proxy card nonce" do
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::AndroidPayDiscover,
1845
- :options => { :store_in_vault_on_success => true }
1865
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
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
- android_pay_details = result.transaction.android_pay_details
1850
- android_pay_details.should_not be_nil
1851
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1852
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1853
- android_pay_details.last_4.should == "1117"
1854
- android_pay_details.virtual_card_last_4.should == "1117"
1855
- android_pay_details.source_description.should == "Discover 1111"
1856
- android_pay_details.expiration_month.to_i.should > 0
1857
- android_pay_details.expiration_year.to_i.should > 0
1858
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1859
- android_pay_details.image_url.should_not be_nil
1860
- android_pay_details.is_network_tokenized?.should == false
1861
- android_pay_details.token.should_not be_nil
1862
- end
1863
-
1864
- it "can create a transaction with a fake android pay network token nonce" do
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::AndroidPayMasterCard
1870
- )
1871
- result.success?.should == true
1872
- result.transaction.should_not be_nil
1873
- android_pay_details = result.transaction.android_pay_details
1874
- android_pay_details.should_not be_nil
1875
- android_pay_details.card_type.should == Braintree::CreditCard::CardType::MasterCard
1876
- android_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1877
- android_pay_details.last_4.should == "4444"
1878
- android_pay_details.virtual_card_last_4.should == "4444"
1879
- android_pay_details.source_description.should == "MasterCard 4444"
1880
- android_pay_details.expiration_month.to_i.should > 0
1881
- android_pay_details.expiration_year.to_i.should > 0
1882
- android_pay_details.google_transaction_id.should == "google_transaction_id"
1883
- android_pay_details.is_network_tokenized?.should == true
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}
1890
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1893
1891
  )
1894
1892
  result.success?.should == true
1895
1893
  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
@@ -1912,7 +1910,7 @@ describe Braintree::Transaction do
1912
1910
  :merchant_account_id => SpecHelper::FakeVenmoAccountMerchantAccountId,
1913
1911
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1914
1912
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
1915
- :options => {:store_in_vault => true}
1913
+ :options => {:store_in_vault => true},
1916
1914
  )
1917
1915
  result.should be_success
1918
1916
 
@@ -1932,7 +1930,7 @@ describe Braintree::Transaction do
1932
1930
  :merchant_account_id => SpecHelper::FakeVenmoAccountMerchantAccountId,
1933
1931
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1934
1932
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
1935
- :options => {:store_in_vault => true, :venmo => {:profile_id => "integration_venmo_merchant_public_id" }}
1933
+ :options => {:store_in_vault => true, :venmo => {:profile_id => "integration_venmo_merchant_public_id"}},
1936
1934
  )
1937
1935
  result.should be_success
1938
1936
  end
@@ -1942,7 +1940,7 @@ describe Braintree::Transaction do
1942
1940
  result = Braintree::Transaction.create(
1943
1941
  :type => "sale",
1944
1942
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1945
- :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable
1943
+ :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
1946
1944
  )
1947
1945
  result.success?.should == true
1948
1946
  result.transaction.should_not be_nil
@@ -1957,7 +1955,7 @@ describe Braintree::Transaction do
1957
1955
  :paypal_account => {
1958
1956
  :payer_id => "PAYER-1234",
1959
1957
  :payment_id => "PAY-5678",
1960
- }
1958
+ },
1961
1959
  )
1962
1960
 
1963
1961
  result.success?.should == true
@@ -1971,7 +1969,7 @@ describe Braintree::Transaction do
1971
1969
  nonce = nonce_for_new_payment_method(
1972
1970
  :paypal_account => {
1973
1971
  :consent_code => "PAYPAL_CONSENT_CODE",
1974
- }
1972
+ },
1975
1973
  )
1976
1974
  nonce.should_not be_nil
1977
1975
 
@@ -1981,7 +1979,7 @@ describe Braintree::Transaction do
1981
1979
  :payment_method_nonce => nonce,
1982
1980
  :paypal_account => {
1983
1981
  :payee_id => "fake-payee-id"
1984
- }
1982
+ },
1985
1983
  )
1986
1984
 
1987
1985
  result.success?.should == true
@@ -1995,7 +1993,7 @@ describe Braintree::Transaction do
1995
1993
  nonce = nonce_for_new_payment_method(
1996
1994
  :paypal_account => {
1997
1995
  :consent_code => "PAYPAL_CONSENT_CODE",
1998
- }
1996
+ },
1999
1997
  )
2000
1998
  nonce.should_not be_nil
2001
1999
 
@@ -2006,7 +2004,7 @@ describe Braintree::Transaction do
2006
2004
  :paypal_account => {},
2007
2005
  :options => {
2008
2006
  :payee_id => "fake-payee-id"
2009
- }
2007
+ },
2010
2008
  )
2011
2009
 
2012
2010
  result.success?.should == true
@@ -2020,7 +2018,7 @@ describe Braintree::Transaction do
2020
2018
  nonce = nonce_for_new_payment_method(
2021
2019
  :paypal_account => {
2022
2020
  :consent_code => "PAYPAL_CONSENT_CODE",
2023
- }
2021
+ },
2024
2022
  )
2025
2023
  nonce.should_not be_nil
2026
2024
 
@@ -2032,7 +2030,7 @@ describe Braintree::Transaction do
2032
2030
  :paypal => {
2033
2031
  :payee_id => "fake-payee-id"
2034
2032
  }
2035
- }
2033
+ },
2036
2034
  )
2037
2035
 
2038
2036
  result.success?.should == true
@@ -2046,7 +2044,7 @@ describe Braintree::Transaction do
2046
2044
  nonce = nonce_for_new_payment_method(
2047
2045
  :paypal_account => {
2048
2046
  :consent_code => "PAYPAL_CONSENT_CODE",
2049
- }
2047
+ },
2050
2048
  )
2051
2049
  nonce.should_not be_nil
2052
2050
 
@@ -2056,7 +2054,7 @@ describe Braintree::Transaction do
2056
2054
  :payment_method_nonce => nonce,
2057
2055
  :paypal_account => {
2058
2056
  :payee_email => "bt_seller_us@paypal.com"
2059
- }
2057
+ },
2060
2058
  )
2061
2059
 
2062
2060
  result.success?.should == true
@@ -2070,7 +2068,7 @@ describe Braintree::Transaction do
2070
2068
  nonce = nonce_for_new_payment_method(
2071
2069
  :paypal_account => {
2072
2070
  :consent_code => "PAYPAL_CONSENT_CODE",
2073
- }
2071
+ },
2074
2072
  )
2075
2073
  nonce.should_not be_nil
2076
2074
 
@@ -2081,7 +2079,7 @@ describe Braintree::Transaction do
2081
2079
  :paypal_account => {},
2082
2080
  :options => {
2083
2081
  :payee_email => "bt_seller_us@paypal.com"
2084
- }
2082
+ },
2085
2083
  )
2086
2084
 
2087
2085
  result.success?.should == true
@@ -2095,7 +2093,7 @@ describe Braintree::Transaction do
2095
2093
  nonce = nonce_for_new_payment_method(
2096
2094
  :paypal_account => {
2097
2095
  :consent_code => "PAYPAL_CONSENT_CODE",
2098
- }
2096
+ },
2099
2097
  )
2100
2098
  nonce.should_not be_nil
2101
2099
 
@@ -2107,7 +2105,7 @@ describe Braintree::Transaction do
2107
2105
  :paypal => {
2108
2106
  :payee_email => "bt_seller_us@paypal.com"
2109
2107
  }
2110
- }
2108
+ },
2111
2109
  )
2112
2110
 
2113
2111
  result.success?.should == true
@@ -2121,7 +2119,7 @@ describe Braintree::Transaction do
2121
2119
  nonce = nonce_for_new_payment_method(
2122
2120
  :paypal_account => {
2123
2121
  :consent_code => "PAYPAL_CONSENT_CODE",
2124
- }
2122
+ },
2125
2123
  )
2126
2124
  nonce.should_not be_nil
2127
2125
 
@@ -2133,7 +2131,7 @@ describe Braintree::Transaction do
2133
2131
  :paypal => {
2134
2132
  :custom_field => "Additional info"
2135
2133
  }
2136
- }
2134
+ },
2137
2135
  )
2138
2136
 
2139
2137
  result.success?.should == true
@@ -2147,7 +2145,7 @@ describe Braintree::Transaction do
2147
2145
  nonce = nonce_for_new_payment_method(
2148
2146
  :paypal_account => {
2149
2147
  :consent_code => "PAYPAL_CONSENT_CODE",
2150
- }
2148
+ },
2151
2149
  )
2152
2150
  nonce.should_not be_nil
2153
2151
 
@@ -2159,7 +2157,7 @@ describe Braintree::Transaction do
2159
2157
  :paypal => {
2160
2158
  :description => "A great product"
2161
2159
  }
2162
- }
2160
+ },
2163
2161
  )
2164
2162
 
2165
2163
  result.success?.should == true
@@ -2173,7 +2171,7 @@ describe Braintree::Transaction do
2173
2171
  nonce = nonce_for_new_payment_method(
2174
2172
  :paypal_account => {
2175
2173
  :consent_code => "PAYPAL_CONSENT_CODE",
2176
- }
2174
+ },
2177
2175
  )
2178
2176
  nonce.should_not be_nil
2179
2177
 
@@ -2188,7 +2186,7 @@ describe Braintree::Transaction do
2188
2186
  :key2 => "value2",
2189
2187
  }
2190
2188
  }
2191
- }
2189
+ },
2192
2190
  )
2193
2191
 
2194
2192
  # note - supplementary data is not returned in response
@@ -2202,7 +2200,7 @@ describe Braintree::Transaction do
2202
2200
  SpecHelper::ThreeDSecureMerchantAccountId,
2203
2201
  :number => Braintree::Test::CreditCardNumbers::Visa,
2204
2202
  :expiration_month => "12",
2205
- :expiration_year => "2012"
2203
+ :expiration_year => "2012",
2206
2204
  )
2207
2205
 
2208
2206
  result = Braintree::Transaction.create(
@@ -2213,7 +2211,7 @@ describe Braintree::Transaction do
2213
2211
  :number => Braintree::Test::CreditCardNumbers::Visa,
2214
2212
  :expiration_date => "12/12",
2215
2213
  },
2216
- :three_d_secure_token => three_d_secure_token
2214
+ :three_d_secure_token => three_d_secure_token,
2217
2215
  )
2218
2216
 
2219
2217
  result.success?.should == true
@@ -2225,7 +2223,7 @@ describe Braintree::Transaction do
2225
2223
  :number => "4111111111111111",
2226
2224
  :expiration_month => "11",
2227
2225
  :expiration_year => "2099",
2228
- }
2226
+ },
2229
2227
  )
2230
2228
  nonce.should_not be_nil
2231
2229
  result = Braintree::Transaction.create(
@@ -2237,7 +2235,7 @@ describe Braintree::Transaction do
2237
2235
  :three_d_secure => {
2238
2236
  :required => true,
2239
2237
  }
2240
- }
2238
+ },
2241
2239
  )
2242
2240
 
2243
2241
  result.success?.should == false
@@ -2253,7 +2251,7 @@ describe Braintree::Transaction do
2253
2251
  :credit_card => {
2254
2252
  :number => Braintree::Test::CreditCardNumbers::Visa,
2255
2253
  :expiration_date => "12/12",
2256
- }
2254
+ },
2257
2255
  )
2258
2256
  result.success?.should == true
2259
2257
  end
@@ -2264,7 +2262,7 @@ describe Braintree::Transaction do
2264
2262
  SpecHelper::ThreeDSecureMerchantAccountId,
2265
2263
  :number => Braintree::Test::CreditCardNumbers::Visa,
2266
2264
  :expiration_month => "12",
2267
- :expiration_year => "2022"
2265
+ :expiration_year => "2022",
2268
2266
  )
2269
2267
 
2270
2268
  result = Braintree::Transaction.create(
@@ -2275,7 +2273,7 @@ describe Braintree::Transaction do
2275
2273
  :number => Braintree::Test::CreditCardNumbers::Visa,
2276
2274
  :expiration_date => "12/22",
2277
2275
  },
2278
- :three_d_secure_authentication_id => three_d_secure_authentication_id
2276
+ :three_d_secure_authentication_id => three_d_secure_authentication_id,
2279
2277
  )
2280
2278
 
2281
2279
  result.success?.should == true
@@ -2289,7 +2287,7 @@ describe Braintree::Transaction do
2289
2287
  :number => Braintree::Test::CreditCardNumbers::Visa,
2290
2288
  :expiration_date => "12/12",
2291
2289
  },
2292
- :three_d_secure_authentication_id => nil
2290
+ :three_d_secure_authentication_id => nil,
2293
2291
  )
2294
2292
  result.success?.should == false
2295
2293
  result.errors.for(:transaction).on(:three_d_secure_authentication_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureAuthenticationIdIsInvalid
@@ -2299,7 +2297,7 @@ describe Braintree::Transaction do
2299
2297
  SpecHelper::ThreeDSecureMerchantAccountId,
2300
2298
  :number => Braintree::Test::CreditCardNumbers::Visa,
2301
2299
  :expiration_month => "12",
2302
- :expiration_year => "2012"
2300
+ :expiration_year => "2012",
2303
2301
  )
2304
2302
 
2305
2303
  result = Braintree::Transaction.create(
@@ -2309,7 +2307,7 @@ describe Braintree::Transaction do
2309
2307
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
2310
2308
  :expiration_date => "12/12",
2311
2309
  },
2312
- :three_d_secure_authentication_id => three_d_secure_authentication_id
2310
+ :three_d_secure_authentication_id => three_d_secure_authentication_id,
2313
2311
  )
2314
2312
  result.success?.should == false
2315
2313
  result.errors.for(:transaction).on(:three_d_secure_authentication_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureTransactionPaymentMethodDoesntMatchThreeDSecureAuthenticationPaymentMethod
@@ -2319,7 +2317,7 @@ describe Braintree::Transaction do
2319
2317
  SpecHelper::ThreeDSecureMerchantAccountId,
2320
2318
  :number => Braintree::Test::CreditCardNumbers::Visa,
2321
2319
  :expiration_month => "12",
2322
- :expiration_year => "2012"
2320
+ :expiration_year => "2012",
2323
2321
  )
2324
2322
 
2325
2323
  result = Braintree::Transaction.create(
@@ -2330,7 +2328,7 @@ describe Braintree::Transaction do
2330
2328
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
2331
2329
  :expiration_date => "12/12",
2332
2330
  },
2333
- :three_d_secure_authentication_id => three_d_secure_authentication_id
2331
+ :three_d_secure_authentication_id => three_d_secure_authentication_id,
2334
2332
  )
2335
2333
  result.success?.should == false
2336
2334
  result.errors.for(:transaction).on(:three_d_secure_authentication_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureTransactionPaymentMethodDoesntMatchThreeDSecureAuthenticationPaymentMethod
@@ -2340,7 +2338,7 @@ describe Braintree::Transaction do
2340
2338
  SpecHelper::ThreeDSecureMerchantAccountId,
2341
2339
  :number => Braintree::Test::CreditCardNumbers::Visa,
2342
2340
  :expiration_month => "12",
2343
- :expiration_year => "2012"
2341
+ :expiration_year => "2012",
2344
2342
  )
2345
2343
  result = Braintree::Transaction.create(
2346
2344
  :merchant_account_id => SpecHelper::ThreeDSecureMerchantAccountId,
@@ -2360,7 +2358,7 @@ describe Braintree::Transaction do
2360
2358
  :directory_response => "Y",
2361
2359
  :cavv_algorithm => "2",
2362
2360
  :ds_transaction_id => "some_ds_id",
2363
- }
2361
+ },
2364
2362
  )
2365
2363
  result.success?.should == false
2366
2364
  result.errors.for(:transaction).on(:three_d_secure_authentication_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureAuthenticationIdWithThreeDSecurePassThruIsInvalid
@@ -2373,7 +2371,7 @@ describe Braintree::Transaction do
2373
2371
  SpecHelper::ThreeDSecureMerchantAccountId,
2374
2372
  :number => Braintree::Test::CreditCardNumbers::Visa,
2375
2373
  :expiration_month => "12",
2376
- :expiration_year => "2012"
2374
+ :expiration_year => "2012",
2377
2375
  )
2378
2376
 
2379
2377
  result = Braintree::Transaction.create(
@@ -2384,7 +2382,7 @@ describe Braintree::Transaction do
2384
2382
  :number => Braintree::Test::CreditCardNumbers::Visa,
2385
2383
  :expiration_date => "12/12",
2386
2384
  },
2387
- :three_d_secure_token => three_d_secure_token
2385
+ :three_d_secure_token => three_d_secure_token,
2388
2386
  )
2389
2387
 
2390
2388
  result.success?.should == true
@@ -2399,7 +2397,7 @@ describe Braintree::Transaction do
2399
2397
  :number => Braintree::Test::CreditCardNumbers::Visa,
2400
2398
  :expiration_date => "12/12",
2401
2399
  },
2402
- :three_d_secure_token => nil
2400
+ :three_d_secure_token => nil,
2403
2401
  )
2404
2402
  result.success?.should == false
2405
2403
  result.errors.for(:transaction).on(:three_d_secure_token)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureTokenIsInvalid
@@ -2410,7 +2408,7 @@ describe Braintree::Transaction do
2410
2408
  SpecHelper::ThreeDSecureMerchantAccountId,
2411
2409
  :number => Braintree::Test::CreditCardNumbers::Visa,
2412
2410
  :expiration_month => "12",
2413
- :expiration_year => "2012"
2411
+ :expiration_year => "2012",
2414
2412
  )
2415
2413
 
2416
2414
  result = Braintree::Transaction.create(
@@ -2421,7 +2419,7 @@ describe Braintree::Transaction do
2421
2419
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
2422
2420
  :expiration_date => "12/12",
2423
2421
  },
2424
- :three_d_secure_token => three_d_secure_token
2422
+ :three_d_secure_token => three_d_secure_token,
2425
2423
  )
2426
2424
  result.success?.should == false
2427
2425
  result.errors.for(:transaction).on(:three_d_secure_token)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureTransactionDataDoesntMatchVerify
@@ -2445,7 +2443,7 @@ describe Braintree::Transaction do
2445
2443
  :directory_response => "Y",
2446
2444
  :cavv_algorithm => "2",
2447
2445
  :ds_transaction_id => "some_ds_id",
2448
- }
2446
+ },
2449
2447
  )
2450
2448
 
2451
2449
  result.success?.should == true
@@ -2470,7 +2468,7 @@ describe Braintree::Transaction do
2470
2468
  :directory_response => "Y",
2471
2469
  :cavv_algorithm => "2",
2472
2470
  :ds_transaction_id => "some_ds_id",
2473
- }
2471
+ },
2474
2472
  )
2475
2473
  result.success?.should == false
2476
2474
  result.errors.for(:transaction).on(:merchant_account_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureMerchantAccountDoesNotSupportCardType
@@ -2488,7 +2486,7 @@ describe Braintree::Transaction do
2488
2486
  :eci_flag => "",
2489
2487
  :cavv => "some_cavv",
2490
2488
  :xid => "some_xid",
2491
- }
2489
+ },
2492
2490
  )
2493
2491
  result.success?.should == false
2494
2492
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:eci_flag)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureEciFlagIsRequired
@@ -2511,7 +2509,7 @@ describe Braintree::Transaction do
2511
2509
  :directory_response => "Y",
2512
2510
  :cavv_algorithm => "2",
2513
2511
  :ds_transaction_id => "some_ds_id",
2514
- }
2512
+ },
2515
2513
  )
2516
2514
  result.success?.should == false
2517
2515
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:cavv)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureCavvIsRequired
@@ -2534,7 +2532,7 @@ describe Braintree::Transaction do
2534
2532
  :directory_response => "Y",
2535
2533
  :cavv_algorithm => "2",
2536
2534
  :ds_transaction_id => "some_ds_id",
2537
- }
2535
+ },
2538
2536
  )
2539
2537
  result.success?.should == false
2540
2538
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:eci_flag)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureEciFlagIsInvalid
@@ -2557,7 +2555,7 @@ describe Braintree::Transaction do
2557
2555
  :directory_response => "Y",
2558
2556
  :cavv_algorithm => "2",
2559
2557
  :ds_transaction_id => "some_ds_id",
2560
- }
2558
+ },
2561
2559
  )
2562
2560
  result.success?.should == false
2563
2561
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:three_d_secure_version)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureThreeDSecureVersionIsInvalid
@@ -2581,7 +2579,7 @@ describe Braintree::Transaction do
2581
2579
  :directory_response => "Y",
2582
2580
  :cavv_algorithm => "2",
2583
2581
  :ds_transaction_id => "some_ds_id",
2584
- }
2582
+ },
2585
2583
  )
2586
2584
  result.success?.should == false
2587
2585
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:authentication_response)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureAuthenticationResponseIsInvalid
@@ -2605,7 +2603,7 @@ describe Braintree::Transaction do
2605
2603
  :directory_response => "abc",
2606
2604
  :cavv_algorithm => "2",
2607
2605
  :ds_transaction_id => "some_ds_id",
2608
- }
2606
+ },
2609
2607
  )
2610
2608
  result.success?.should == false
2611
2609
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:directory_response)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureDirectoryResponseIsInvalid
@@ -2629,7 +2627,7 @@ describe Braintree::Transaction do
2629
2627
  :directory_response => "Y",
2630
2628
  :cavv_algorithm => "bad_alg",
2631
2629
  :ds_transaction_id => "some_ds_id",
2632
- }
2630
+ },
2633
2631
  )
2634
2632
  result.success?.should == false
2635
2633
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:cavv_algorithm)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureCavvAlgorithmIsInvalid
@@ -2641,12 +2639,12 @@ describe Braintree::Transaction do
2641
2639
  it "can create a transaction" do
2642
2640
  payment_method_result = Braintree::PaymentMethod.create(
2643
2641
  :customer_id => Braintree::Customer.create.customer.id,
2644
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
2642
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
2645
2643
  )
2646
2644
  result = Braintree::Transaction.create(
2647
2645
  :type => "sale",
2648
2646
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2649
- :payment_method_token => payment_method_result.payment_method.token
2647
+ :payment_method_token => payment_method_result.payment_method.token,
2650
2648
  )
2651
2649
 
2652
2650
  result.should be_success
@@ -2661,13 +2659,13 @@ describe Braintree::Transaction do
2661
2659
  payment_method_token = rand(36**3).to_s(36)
2662
2660
  nonce = nonce_for_paypal_account(
2663
2661
  :consent_code => "PAYPAL_CONSENT_CODE",
2664
- :token => payment_method_token
2662
+ :token => payment_method_token,
2665
2663
  )
2666
2664
 
2667
2665
  result = Braintree::Transaction.create(
2668
2666
  :type => "sale",
2669
2667
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2670
- :payment_method_nonce => nonce
2668
+ :payment_method_nonce => nonce,
2671
2669
  )
2672
2670
 
2673
2671
  result.should be_success
@@ -2683,14 +2681,14 @@ describe Braintree::Transaction do
2683
2681
  payment_method_token = rand(36**3).to_s(36)
2684
2682
  nonce = nonce_for_paypal_account(
2685
2683
  :consent_code => "PAYPAL_CONSENT_CODE",
2686
- :token => payment_method_token
2684
+ :token => payment_method_token,
2687
2685
  )
2688
2686
 
2689
2687
  result = Braintree::Transaction.create(
2690
2688
  :type => "sale",
2691
2689
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2692
2690
  :payment_method_nonce => nonce,
2693
- :options => {:store_in_vault => true}
2691
+ :options => {:store_in_vault => true},
2694
2692
  )
2695
2693
 
2696
2694
  result.success?.should == true
@@ -2703,12 +2701,28 @@ 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(
2709
2723
  :type => "sale",
2710
2724
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2711
- :payment_method_nonce => Braintree::Test::Nonce::LocalPayment
2725
+ :payment_method_nonce => Braintree::Test::Nonce::LocalPayment,
2712
2726
  )
2713
2727
 
2714
2728
  result.should be_success
@@ -2726,7 +2740,7 @@ describe Braintree::Transaction do
2726
2740
  result = Braintree::Transaction.create(
2727
2741
  :type => "sale",
2728
2742
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2729
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
2743
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2730
2744
  )
2731
2745
 
2732
2746
  result.should be_success
@@ -2738,14 +2752,14 @@ describe Braintree::Transaction do
2738
2752
  payment_method_token = rand(36**3).to_s(36)
2739
2753
  nonce = nonce_for_paypal_account(
2740
2754
  :access_token => "PAYPAL_ACCESS_TOKEN",
2741
- :token => payment_method_token
2755
+ :token => payment_method_token,
2742
2756
  )
2743
2757
 
2744
2758
  result = Braintree::Transaction.create(
2745
2759
  :type => "sale",
2746
2760
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2747
2761
  :payment_method_nonce => nonce,
2748
- :options => {:store_in_vault => true}
2762
+ :options => {:store_in_vault => true},
2749
2763
  )
2750
2764
 
2751
2765
  result.success?.should == true
@@ -2765,7 +2779,7 @@ describe Braintree::Transaction do
2765
2779
  :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2766
2780
  :options => {
2767
2781
  :submit_for_settlement => true
2768
- }
2782
+ },
2769
2783
  )
2770
2784
  result.success?.should == true
2771
2785
  result.transaction.status.should == Braintree::Transaction::Status::Settling
@@ -2776,7 +2790,7 @@ describe Braintree::Transaction do
2776
2790
  it "successfully voids a paypal transaction that's been authorized" do
2777
2791
  sale_transaction = Braintree::Transaction.sale!(
2778
2792
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2779
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
2793
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2780
2794
  )
2781
2795
 
2782
2796
  void_transaction = Braintree::Transaction.void!(sale_transaction.id)
@@ -2787,7 +2801,7 @@ describe Braintree::Transaction do
2787
2801
  it "fails to void a paypal transaction that's been declined" do
2788
2802
  sale_transaction = Braintree::Transaction.sale(
2789
2803
  :amount => Braintree::Test::TransactionAmounts::Decline,
2790
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
2804
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2791
2805
  ).transaction
2792
2806
 
2793
2807
  expect do
@@ -2857,6 +2871,19 @@ describe Braintree::Transaction do
2857
2871
  result.transaction.amount.should == transaction.amount/2
2858
2872
  end
2859
2873
 
2874
+ it "allows merchant_account_id to be passed for the refund" do
2875
+ transaction = create_transaction_to_refund
2876
+
2877
+ result = Braintree::Transaction.refund(
2878
+ transaction.id,
2879
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
2880
+ )
2881
+
2882
+ result.success?.should == true
2883
+ result.transaction.type.should == "credit"
2884
+ result.transaction.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
2885
+ end
2886
+
2860
2887
  it "does not allow arbitrary options to be passed" do
2861
2888
  transaction = create_paypal_transaction_for_refund
2862
2889
 
@@ -2865,25 +2892,17 @@ describe Braintree::Transaction do
2865
2892
  }.to raise_error(ArgumentError)
2866
2893
  end
2867
2894
 
2868
- it "assigns the refund_id on the original transaction" do
2895
+ it "assigns the refunded_transaction_id to the original transaction" do
2869
2896
  transaction = create_paypal_transaction_for_refund
2870
2897
  refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
2871
- transaction = Braintree::Transaction.find(transaction.id)
2872
2898
 
2873
- transaction.refund_id.should == refund_transaction.id
2874
- end
2875
-
2876
- it "assigns the refunded_transaction_id to the original transaction" do
2877
- transaction = create_paypal_transaction_for_refund
2878
- refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
2879
-
2880
- refund_transaction.refunded_transaction_id.should == transaction.id
2899
+ refund_transaction.refunded_transaction_id.should == transaction.id
2881
2900
  end
2882
2901
 
2883
2902
  it "returns an error result if unsettled" do
2884
2903
  transaction = Braintree::Transaction.sale!(
2885
2904
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2886
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
2905
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2887
2906
  )
2888
2907
  result = Braintree::Transaction.refund(transaction.id)
2889
2908
  result.success?.should == false
@@ -2896,13 +2915,19 @@ describe Braintree::Transaction do
2896
2915
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
2897
2916
  :options => {
2898
2917
  :submit_for_settlement => true
2899
- }
2918
+ },
2900
2919
  )
2901
2920
  config = Braintree::Configuration.instantiate
2902
2921
  response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
2903
2922
  result = Braintree::Transaction.refund(transaction.id, :amount => "2046.00")
2904
2923
  result.success?.should == false
2905
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::RefundAuthSoftDeclined
2924
+ result.transaction.id.should =~ /^\w{6,}$/
2925
+ result.transaction.type.should == "credit"
2926
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
2927
+ result.transaction.processor_response_code.should == "2046"
2928
+ result.transaction.processor_response_text.should == "Declined"
2929
+ result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::SoftDeclined
2930
+ result.transaction.additional_processor_response.should == "2046 : Declined"
2906
2931
  end
2907
2932
 
2908
2933
  it "handles hard declined refund authorizations" do
@@ -2911,13 +2936,19 @@ describe Braintree::Transaction do
2911
2936
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
2912
2937
  :options => {
2913
2938
  :submit_for_settlement => true
2914
- }
2939
+ },
2915
2940
  )
2916
2941
  config = Braintree::Configuration.instantiate
2917
2942
  response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
2918
2943
  result = Braintree::Transaction.refund(transaction.id, :amount => "2009.00")
2919
2944
  result.success?.should == false
2920
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::RefundAuthHardDeclined
2945
+ result.transaction.id.should =~ /^\w{6,}$/
2946
+ result.transaction.type.should == "credit"
2947
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
2948
+ result.transaction.processor_response_code.should == "2009"
2949
+ result.transaction.processor_response_text.should == "No Such Issuer"
2950
+ result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::HardDeclined
2951
+ result.transaction.additional_processor_response.should == "2009 : No Such Issuer"
2921
2952
  end
2922
2953
  end
2923
2954
 
@@ -2925,13 +2956,13 @@ describe Braintree::Transaction do
2925
2956
  it "handles bad unvalidated nonces" do
2926
2957
  nonce = nonce_for_paypal_account(
2927
2958
  :access_token => "PAYPAL_ACCESS_TOKEN",
2928
- :consent_code => "PAYPAL_CONSENT_CODE"
2959
+ :consent_code => "PAYPAL_CONSENT_CODE",
2929
2960
  )
2930
2961
 
2931
2962
  result = Braintree::Transaction.create(
2932
2963
  :type => "sale",
2933
2964
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2934
- :payment_method_nonce => nonce
2965
+ :payment_method_nonce => nonce,
2935
2966
  )
2936
2967
 
2937
2968
  result.should_not be_success
@@ -2942,7 +2973,7 @@ describe Braintree::Transaction do
2942
2973
  result = Braintree::Transaction.create(
2943
2974
  :type => "sale",
2944
2975
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2945
- :payment_method_nonce => "NON_EXISTENT_NONCE"
2976
+ :payment_method_nonce => "NON_EXISTENT_NONCE",
2946
2977
  )
2947
2978
 
2948
2979
  result.should_not be_success
@@ -4070,7 +4101,7 @@ describe Braintree::Transaction do
4070
4101
  :unit_of_measure => "gallon",
4071
4102
  :total_amount => "10.1",
4072
4103
  },
4073
- ['Name #2'],
4104
+ ["Name #2"],
4074
4105
  {
4075
4106
  :quantity => "2.02",
4076
4107
  :name => "Name #3",
@@ -4256,7 +4287,7 @@ describe Braintree::Transaction do
4256
4287
  customer = Braintree::Customer.create!
4257
4288
  result = Braintree::PaymentMethod.create(
4258
4289
  :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
4259
- :customer_id => customer.id
4290
+ :customer_id => customer.id,
4260
4291
  )
4261
4292
  payment_method_token = result.payment_method.token
4262
4293
 
@@ -4289,7 +4320,7 @@ describe Braintree::Transaction do
4289
4320
  result.errors.for(:transaction).for(:external_vault).on(:status)[0].code.should == Braintree::ErrorCodes::Transaction::ExternalVault::StatusIsInvalid
4290
4321
  end
4291
4322
 
4292
- context "Visa/Mastercard/Discover" do
4323
+ context "Visa/Mastercard/Discover/AmEx" do
4293
4324
  it "accepts status" do
4294
4325
  result = Braintree::Transaction.create(
4295
4326
  :type => "sale",
@@ -4341,12 +4372,12 @@ describe Braintree::Transaction do
4341
4372
  end
4342
4373
  end
4343
4374
 
4344
- context "Non-(Visa/Mastercard/Discover) card types" do
4375
+ context "Non-(Visa/Mastercard/Discover/AmEx) card types" do
4345
4376
  it "accepts status" do
4346
4377
  result = Braintree::Transaction.create(
4347
4378
  :type => "sale",
4348
4379
  :credit_card => {
4349
- :number => Braintree::Test::CreditCardNumbers::AmExes[0],
4380
+ :number => Braintree::Test::CreditCardNumbers::JCBs[0],
4350
4381
  :expiration_date => "05/2009"
4351
4382
  },
4352
4383
  :external_vault => {
@@ -4362,7 +4393,7 @@ describe Braintree::Transaction do
4362
4393
  result = Braintree::Transaction.create(
4363
4394
  :type => "sale",
4364
4395
  :credit_card => {
4365
- :number => Braintree::Test::CreditCardNumbers::AmExes[0],
4396
+ :number => Braintree::Test::CreditCardNumbers::JCBs[0],
4366
4397
  :expiration_date => "05/2009"
4367
4398
  },
4368
4399
  :external_vault => {
@@ -4374,25 +4405,7 @@ describe Braintree::Transaction do
4374
4405
  result.success?.should == true
4375
4406
  result.transaction.network_transaction_id.should be_nil
4376
4407
  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
4408
  end
4395
-
4396
4409
  end
4397
4410
 
4398
4411
  context "account_type" do
@@ -4409,7 +4422,7 @@ describe Braintree::Transaction do
4409
4422
  :credit_card => {
4410
4423
  :account_type => "credit",
4411
4424
  }
4412
- }
4425
+ },
4413
4426
  )
4414
4427
  result.success?.should == true
4415
4428
  result.transaction.credit_card_details.account_type.should == "credit"
@@ -4428,7 +4441,7 @@ describe Braintree::Transaction do
4428
4441
  :credit_card => {
4429
4442
  :account_type => "credit",
4430
4443
  }
4431
- }
4444
+ },
4432
4445
  )
4433
4446
  result.success?.should == true
4434
4447
  result.transaction.credit_card_details.account_type.should == "credit"
@@ -4448,7 +4461,7 @@ describe Braintree::Transaction do
4448
4461
  :account_type => "debit",
4449
4462
  },
4450
4463
  :submit_for_settlement => true,
4451
- }
4464
+ },
4452
4465
  )
4453
4466
  result.success?.should == true
4454
4467
  result.transaction.credit_card_details.account_type.should == "debit"
@@ -4467,7 +4480,7 @@ describe Braintree::Transaction do
4467
4480
  :credit_card => {
4468
4481
  :account_type => "debit",
4469
4482
  },
4470
- }
4483
+ },
4471
4484
  )
4472
4485
  result.success?.should == false
4473
4486
  result.errors.for(:transaction).for(:options).for(:credit_card).on(:account_type)[0].code.should == Braintree::ErrorCodes::Transaction::Options::CreditCard::AccountTypeDebitDoesNotSupportAuths
@@ -4486,7 +4499,7 @@ describe Braintree::Transaction do
4486
4499
  :credit_card => {
4487
4500
  :account_type => "ach",
4488
4501
  },
4489
- }
4502
+ },
4490
4503
  )
4491
4504
  result.success?.should == false
4492
4505
  result.errors.for(:transaction).for(:options).for(:credit_card).on(:account_type)[0].code.should == Braintree::ErrorCodes::Transaction::Options::CreditCard::AccountTypeIsInvalid
@@ -4504,7 +4517,7 @@ describe Braintree::Transaction do
4504
4517
  :credit_card => {
4505
4518
  :account_type => "credit",
4506
4519
  },
4507
- }
4520
+ },
4508
4521
  )
4509
4522
  result.success?.should == false
4510
4523
  result.errors.for(:transaction).for(:options).for(:credit_card).on(:account_type)[0].code.should == Braintree::ErrorCodes::Transaction::Options::CreditCard::AccountTypeNotSupported
@@ -4520,7 +4533,7 @@ describe Braintree::Transaction do
4520
4533
  :credit_card => {
4521
4534
  :number => Braintree::Test::CreditCardNumbers::Visa,
4522
4535
  :expiration_date => "05/2009"
4523
- }
4536
+ },
4524
4537
  )
4525
4538
  transaction.id.should =~ /^\w{6,}$/
4526
4539
  transaction.type.should == "sale"
@@ -4538,7 +4551,7 @@ describe Braintree::Transaction do
4538
4551
  :credit_card => {
4539
4552
  :number => Braintree::Test::CreditCardNumbers::Visa,
4540
4553
  :expiration_date => "05/2009"
4541
- }
4554
+ },
4542
4555
  )
4543
4556
  end.to raise_error(Braintree::ValidationsFailed)
4544
4557
  end
@@ -4571,14 +4584,6 @@ describe Braintree::Transaction do
4571
4584
  result.transaction.type.should == "credit"
4572
4585
  end
4573
4586
 
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
4587
  it "assigns the refunded_transaction_id to the original transaction" do
4583
4588
  transaction = create_transaction_to_refund
4584
4589
  refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
@@ -4602,7 +4607,7 @@ describe Braintree::Transaction do
4602
4607
  :credit_card => {
4603
4608
  :number => Braintree::Test::CreditCardNumbers::Visa,
4604
4609
  :expiration_date => "05/2009"
4605
- }
4610
+ },
4606
4611
  )
4607
4612
  result = Braintree::Transaction.refund(transaction.id)
4608
4613
  result.success?.should == false
@@ -4639,7 +4644,7 @@ describe Braintree::Transaction do
4639
4644
  :credit_card => {
4640
4645
  :number => Braintree::Test::CreditCardNumbers::Visa,
4641
4646
  :expiration_date => "05/2009"
4642
- }
4647
+ },
4643
4648
  )
4644
4649
  result.success?.should == true
4645
4650
  result.transaction.id.should =~ /^\w{6,}$/
@@ -4695,7 +4700,7 @@ describe Braintree::Transaction do
4695
4700
  :postal_code => "60103",
4696
4701
  :country_name => "United States of America",
4697
4702
  :shipping_method => Braintree::Transaction::AddressDetails::ShippingMethod::Electronic
4698
- }
4703
+ },
4699
4704
  )
4700
4705
  result.success?.should == true
4701
4706
  transaction = result.transaction
@@ -4759,7 +4764,7 @@ describe Braintree::Transaction do
4759
4764
  :credit_card => {
4760
4765
  :number => Braintree::Test::CreditCardNumbers::Visa,
4761
4766
  :expiration_date => "05/2009"
4762
- }
4767
+ },
4763
4768
  )
4764
4769
  result.success?.should == true
4765
4770
  result.transaction.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
@@ -4771,7 +4776,7 @@ describe Braintree::Transaction do
4771
4776
  :credit_card => {
4772
4777
  :number => Braintree::Test::CreditCardNumbers::Visa,
4773
4778
  :expiration_date => "05/2009"
4774
- }
4779
+ },
4775
4780
  )
4776
4781
  result.success?.should == true
4777
4782
  result.transaction.merchant_account_id.should == SpecHelper::DefaultMerchantAccountId
@@ -4790,7 +4795,7 @@ describe Braintree::Transaction do
4790
4795
  },
4791
4796
  :options => {
4792
4797
  :store_in_vault => true
4793
- }
4798
+ },
4794
4799
  )
4795
4800
  result.success?.should == true
4796
4801
  transaction = result.transaction
@@ -4825,7 +4830,7 @@ describe Braintree::Transaction do
4825
4830
  :options => {
4826
4831
  :store_in_vault => true,
4827
4832
  :add_billing_address_to_payment_method => true,
4828
- }
4833
+ },
4829
4834
  )
4830
4835
  result.success?.should == true
4831
4836
  transaction = result.transaction
@@ -4870,7 +4875,7 @@ describe Braintree::Transaction do
4870
4875
  :options => {
4871
4876
  :store_in_vault => true,
4872
4877
  :store_shipping_address_in_vault => true,
4873
- }
4878
+ },
4874
4879
  )
4875
4880
  result.success?.should == true
4876
4881
  transaction = result.transaction
@@ -4896,7 +4901,7 @@ describe Braintree::Transaction do
4896
4901
  :number => "5105105105105100",
4897
4902
  :expiration_date => "05/2012"
4898
4903
  },
4899
- :options => { :store_in_vault => true }
4904
+ :options => {:store_in_vault => true},
4900
4905
  )
4901
4906
 
4902
4907
  result.success?.should == true
@@ -4914,7 +4919,7 @@ describe Braintree::Transaction do
4914
4919
  },
4915
4920
  :options => {
4916
4921
  :submit_for_settlement => true
4917
- }
4922
+ },
4918
4923
  )
4919
4924
  result.success?.should == true
4920
4925
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -4937,7 +4942,7 @@ describe Braintree::Transaction do
4937
4942
  },
4938
4943
  :options => {
4939
4944
  :store_in_vault => true
4940
- }
4945
+ },
4941
4946
  )
4942
4947
  result.success?.should == true
4943
4948
  transaction = result.transaction
@@ -4952,20 +4957,20 @@ describe Braintree::Transaction do
4952
4957
  :credit_card => {
4953
4958
  :number => Braintree::Test::CreditCardNumbers::Visa,
4954
4959
  :expiration_date => "05/2010"
4955
- }
4960
+ },
4956
4961
  )
4957
4962
  address = Braintree::Address.create!(
4958
4963
  :customer_id => customer.id,
4959
- :street_address => '123 Fake St.'
4964
+ :street_address => "123 Fake St.",
4960
4965
  )
4961
4966
  result = Braintree::Transaction.sale(
4962
4967
  :amount => "100",
4963
4968
  :customer_id => customer.id,
4964
- :shipping_address_id => address.id
4969
+ :shipping_address_id => address.id,
4965
4970
  )
4966
4971
  result.success?.should == true
4967
4972
  transaction = result.transaction
4968
- transaction.shipping_details.street_address.should == '123 Fake St.'
4973
+ transaction.shipping_details.street_address.should == "123 Fake St."
4969
4974
  transaction.customer_details.id.should == customer.id
4970
4975
  transaction.shipping_details.id.should == address.id
4971
4976
  end
@@ -4982,12 +4987,79 @@ describe Braintree::Transaction do
4982
4987
  }
4983
4988
  result = Braintree::Transaction.sale(params[:transaction])
4984
4989
  result.success?.should == false
4985
- result.params.should == {:transaction => {:type => 'sale', :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
4990
+ result.params.should == {:transaction => {:type => "sale", :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
4986
4991
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
4987
4992
  end
4988
4993
 
4994
+ it "validates currency_iso_code and creates transaction" do
4995
+ params = {
4996
+ :transaction => {
4997
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
4998
+ :currency_iso_code => "USD",
4999
+ :credit_card => {
5000
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5001
+ :expiration_date => "05/2009"
5002
+ }
5003
+ }
5004
+ }
5005
+ result = Braintree::Transaction.sale(params[:transaction])
5006
+ result.success?.should == true
5007
+ result.transaction.currency_iso_code == "USD"
5008
+ end
5009
+
5010
+ it "validates currency_iso_code and returns error" do
5011
+ params = {
5012
+ :transaction => {
5013
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5014
+ :currency_iso_code => "CAD",
5015
+ :credit_card => {
5016
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5017
+ :expiration_date => "05/2009"
5018
+ }
5019
+ }
5020
+ }
5021
+ result = Braintree::Transaction.sale(params[:transaction])
5022
+ result.success?.should == false
5023
+ result.errors.for(:transaction).on(:currency_iso_code)[0].code.should == Braintree::ErrorCodes::Transaction::CurrencyCodeNotSupportedByMerchantAccount
5024
+ end
5025
+
5026
+ it "validates currency_iso_code and creates transaction with specified merchant account" do
5027
+ params = {
5028
+ :transaction => {
5029
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5030
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
5031
+ :currency_iso_code => "USD",
5032
+ :credit_card => {
5033
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5034
+ :expiration_date => "05/2009"
5035
+ }
5036
+ }
5037
+ }
5038
+ result = Braintree::Transaction.sale(params[:transaction])
5039
+ result.success?.should == true
5040
+ result.transaction.currency_iso_code == "USD"
5041
+ result.transaction.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
5042
+ end
5043
+
5044
+ it "validates currency_iso_code and returns error with specified merchant account" do
5045
+ params = {
5046
+ :transaction => {
5047
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5048
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
5049
+ :currency_iso_code => "CAD",
5050
+ :credit_card => {
5051
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5052
+ :expiration_date => "05/2009"
5053
+ }
5054
+ }
5055
+ }
5056
+ result = Braintree::Transaction.sale(params[:transaction])
5057
+ result.success?.should == false
5058
+ result.errors.for(:transaction).on(:currency_iso_code)[0].code.should == Braintree::ErrorCodes::Transaction::CurrencyCodeNotSupportedByMerchantAccount
5059
+ end
5060
+
4989
5061
  it "skips advanced fraud checking if transaction[options][skip_advanced_fraud_checking] is set to true" do
4990
- with_advanced_fraud_integration_merchant do
5062
+ with_advanced_fraud_kount_integration_merchant do
4991
5063
  result = Braintree::Transaction.sale(
4992
5064
  :amount => Braintree::Test::TransactionAmounts::Authorize,
4993
5065
  :credit_card => {
@@ -4996,7 +5068,7 @@ describe Braintree::Transaction do
4996
5068
  },
4997
5069
  :options => {
4998
5070
  :skip_advanced_fraud_checking => true
4999
- }
5071
+ },
5000
5072
  )
5001
5073
  result.success?.should == true
5002
5074
  result.transaction.risk_data.should be_nil
@@ -5020,11 +5092,11 @@ describe Braintree::Transaction do
5020
5092
  result.transaction.status.should == Braintree::Transaction::Status::Authorized
5021
5093
  end
5022
5094
 
5023
- context "Android Pay params" do
5095
+ context "Google Pay params" do
5024
5096
  it "works with full params" do
5025
5097
  params = {
5026
5098
  :amount => "3.12",
5027
- :android_pay_card => {
5099
+ :google_pay_card => {
5028
5100
  :number => "4012888888881881",
5029
5101
  :cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
5030
5102
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
@@ -5043,7 +5115,7 @@ describe Braintree::Transaction do
5043
5115
  it "works with only number, cryptogram, expiration and transaction ID (network tokenized card)" do
5044
5116
  params = {
5045
5117
  :amount => "3.12",
5046
- :android_pay_card => {
5118
+ :google_pay_card => {
5047
5119
  :number => "4012888888881881",
5048
5120
  :cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
5049
5121
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
@@ -5059,7 +5131,7 @@ describe Braintree::Transaction do
5059
5131
  it "works with only number, expiration and transaction ID (non-tokenized card)" do
5060
5132
  params = {
5061
5133
  :amount => "3.12",
5062
- :android_pay_card => {
5134
+ :google_pay_card => {
5063
5135
  :number => "4012888888881881",
5064
5136
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
5065
5137
  :expiration_month => "10",
@@ -5090,7 +5162,7 @@ describe Braintree::Transaction do
5090
5162
  :currency_amount => "10.00",
5091
5163
  :currency_iso_code => "USD"
5092
5164
  }
5093
- }
5165
+ },
5094
5166
  )
5095
5167
  result.success?.should == true
5096
5168
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -5112,7 +5184,7 @@ describe Braintree::Transaction do
5112
5184
  :currency_amount => "10.00",
5113
5185
  :currency_iso_code => "USD"
5114
5186
  }
5115
- }
5187
+ },
5116
5188
  )
5117
5189
  result.success?.should == true
5118
5190
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -5134,7 +5206,7 @@ describe Braintree::Transaction do
5134
5206
  :currency_amount => "10.00",
5135
5207
  :currency_iso_code => "USD"
5136
5208
  }
5137
- }
5209
+ },
5138
5210
  )
5139
5211
  result.success?.should == true
5140
5212
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -5157,7 +5229,7 @@ describe Braintree::Transaction do
5157
5229
  :currency_amount => "10.00",
5158
5230
  :currency_iso_code => "USD"
5159
5231
  }
5160
- }
5232
+ },
5161
5233
  )
5162
5234
  result.success?.should == true
5163
5235
 
@@ -5181,7 +5253,7 @@ describe Braintree::Transaction do
5181
5253
  :currency_amount => "10.00",
5182
5254
  :currency_iso_code => "USD"
5183
5255
  }
5184
- }
5256
+ },
5185
5257
  )
5186
5258
  result.success?.should == true
5187
5259
  result.transaction.status.should == Braintree::Transaction::Status::Authorized
@@ -5206,7 +5278,7 @@ describe Braintree::Transaction do
5206
5278
  :currency_amount => "10.00",
5207
5279
  :currency_iso_code => "USD"
5208
5280
  }
5209
- }
5281
+ },
5210
5282
  )
5211
5283
  result.success?.should == true
5212
5284
  result.transaction.status.should == Braintree::Transaction::Status::Authorized
@@ -5226,7 +5298,7 @@ describe Braintree::Transaction do
5226
5298
  :credit_card => {
5227
5299
  :number => Braintree::Test::CreditCardNumbers::Visa,
5228
5300
  :expiration_date => "05/2009"
5229
- }
5301
+ },
5230
5302
  )
5231
5303
  transaction.id.should =~ /^\w{6,}$/
5232
5304
  transaction.type.should == "sale"
@@ -5243,7 +5315,7 @@ describe Braintree::Transaction do
5243
5315
  :credit_card => {
5244
5316
  :number => Braintree::Test::CreditCardNumbers::Visa,
5245
5317
  :expiration_date => "05/2009"
5246
- }
5318
+ },
5247
5319
  )
5248
5320
  end.to raise_error(Braintree::ValidationsFailed)
5249
5321
  end
@@ -5256,7 +5328,7 @@ describe Braintree::Transaction do
5256
5328
  :credit_card => {
5257
5329
  :number => Braintree::Test::CreditCardNumbers::Visa,
5258
5330
  :expiration_date => "06/2009"
5259
- }
5331
+ },
5260
5332
  )
5261
5333
  result = Braintree::Transaction.submit_for_settlement(transaction.id)
5262
5334
  result.success?.should == true
@@ -5268,7 +5340,7 @@ describe Braintree::Transaction do
5268
5340
  :credit_card => {
5269
5341
  :number => Braintree::Test::CreditCardNumbers::Visa,
5270
5342
  :expiration_date => "06/2009"
5271
- }
5343
+ },
5272
5344
  )
5273
5345
  transaction.amount.should == BigDecimal("1000.00")
5274
5346
  result = Braintree::Transaction.submit_for_settlement(transaction.id, "999.99")
@@ -5284,9 +5356,9 @@ describe Braintree::Transaction do
5284
5356
  :credit_card => {
5285
5357
  :number => Braintree::Test::CreditCardNumbers::Visa,
5286
5358
  :expiration_date => "06/2009"
5287
- }
5359
+ },
5288
5360
  )
5289
- options = { :order_id => "ABC123" }
5361
+ options = {:order_id => "ABC123"}
5290
5362
  result = Braintree::Transaction.submit_for_settlement(transaction.id, nil, options)
5291
5363
  result.success?.should == true
5292
5364
  result.transaction.order_id.should == "ABC123"
@@ -5299,13 +5371,13 @@ describe Braintree::Transaction do
5299
5371
  :credit_card => {
5300
5372
  :number => Braintree::Test::CreditCardNumbers::Visa,
5301
5373
  :expiration_date => "06/2009"
5302
- }
5374
+ },
5303
5375
  )
5304
5376
 
5305
5377
  options = {
5306
5378
  :descriptor => {
5307
- :name => '123*123456789012345678',
5308
- :phone => '3334445555',
5379
+ :name => "123*123456789012345678",
5380
+ :phone => "3334445555",
5309
5381
  :url => "ebay.com"
5310
5382
  }
5311
5383
  }
@@ -5313,9 +5385,9 @@ describe Braintree::Transaction do
5313
5385
  result = Braintree::Transaction.submit_for_settlement(transaction.id, nil, options)
5314
5386
  result.success?.should == true
5315
5387
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
5316
- result.transaction.descriptor.name.should == '123*123456789012345678'
5317
- result.transaction.descriptor.phone.should == '3334445555'
5318
- result.transaction.descriptor.url.should == 'ebay.com'
5388
+ result.transaction.descriptor.name.should == "123*123456789012345678"
5389
+ result.transaction.descriptor.phone.should == "3334445555"
5390
+ result.transaction.descriptor.url.should == "ebay.com"
5319
5391
  end
5320
5392
 
5321
5393
  it "raises an error if an invalid option is passed in" do
@@ -5324,10 +5396,10 @@ describe Braintree::Transaction do
5324
5396
  :credit_card => {
5325
5397
  :number => Braintree::Test::CreditCardNumbers::Visa,
5326
5398
  :expiration_date => "06/2009"
5327
- }
5399
+ },
5328
5400
  )
5329
5401
 
5330
- options = { :order_id => "ABC123", :invalid_option => "i'm invalid" }
5402
+ options = {:order_id => "ABC123", :invalid_option => "i'm invalid"}
5331
5403
 
5332
5404
  expect do
5333
5405
  Braintree::Transaction.submit_for_settlement(transaction.id, nil, options)
@@ -5337,10 +5409,11 @@ describe Braintree::Transaction do
5337
5409
  it "returns an error result if settlement is too large" do
5338
5410
  transaction = Braintree::Transaction.sale!(
5339
5411
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5412
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
5340
5413
  :credit_card => {
5341
5414
  :number => Braintree::Test::CreditCardNumbers::Visa,
5342
5415
  :expiration_date => "06/2009"
5343
- }
5416
+ },
5344
5417
  )
5345
5418
  transaction.amount.should == BigDecimal("1000.00")
5346
5419
  result = Braintree::Transaction.submit_for_settlement(transaction.id, "1000.01")
@@ -5355,7 +5428,7 @@ describe Braintree::Transaction do
5355
5428
  :credit_card => {
5356
5429
  :number => Braintree::Test::CreditCardNumbers::Visa,
5357
5430
  :expiration_date => "06/2009"
5358
- }
5431
+ },
5359
5432
  ).transaction
5360
5433
  result = Braintree::Transaction.submit_for_settlement(transaction.id)
5361
5434
  result.success?.should == false
@@ -5372,7 +5445,7 @@ describe Braintree::Transaction do
5372
5445
  :number => Braintree::Test::CreditCardNumbers::Visa,
5373
5446
  :expiration_date => "06/2009"
5374
5447
  },
5375
- :service_fee_amount => "1.00"
5448
+ :service_fee_amount => "1.00",
5376
5449
  ).transaction
5377
5450
  result = Braintree::Transaction.submit_for_settlement(transaction.id, "0.01")
5378
5451
  result.success?.should == false
@@ -5395,7 +5468,7 @@ describe Braintree::Transaction do
5395
5468
  :currency_amount => "10.00",
5396
5469
  :currency_iso_code => "USD"
5397
5470
  }
5398
- }
5471
+ },
5399
5472
  )
5400
5473
  result.success?.should == true
5401
5474
 
@@ -5419,7 +5492,7 @@ describe Braintree::Transaction do
5419
5492
  :currency_amount => "10.00",
5420
5493
  :currency_iso_code => "USD"
5421
5494
  }
5422
- }
5495
+ },
5423
5496
  )
5424
5497
  result.success?.should == true
5425
5498
 
@@ -5439,7 +5512,7 @@ describe Braintree::Transaction do
5439
5512
  :discount_amount => "12.00",
5440
5513
  :tax_amount => "0",
5441
5514
  },
5442
- ]
5515
+ ],
5443
5516
  )
5444
5517
  result.success?.should == true
5445
5518
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -5453,9 +5526,9 @@ describe Braintree::Transaction do
5453
5526
  :credit_card => {
5454
5527
  :number => Braintree::Test::CreditCardNumbers::Visa,
5455
5528
  :expiration_date => "06/2009"
5456
- }
5529
+ },
5457
5530
  )
5458
- options = { :order_id => "ABC123" }
5531
+ options = {:order_id => "ABC123"}
5459
5532
  transaction = Braintree::Transaction.submit_for_settlement!(original_transaction.id, "0.01", options)
5460
5533
  transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
5461
5534
  transaction.id.should == original_transaction.id
@@ -5465,10 +5538,11 @@ describe Braintree::Transaction do
5465
5538
  it "raises a ValidationsFailed if unsuccessful" do
5466
5539
  transaction = Braintree::Transaction.sale!(
5467
5540
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5541
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
5468
5542
  :credit_card => {
5469
5543
  :number => Braintree::Test::CreditCardNumbers::Visa,
5470
5544
  :expiration_date => "06/2009"
5471
- }
5545
+ },
5472
5546
  )
5473
5547
  transaction.amount.should == BigDecimal("1000.00")
5474
5548
  expect do
@@ -5484,18 +5558,18 @@ describe Braintree::Transaction do
5484
5558
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5485
5559
  :merchant_account_id => SpecHelper::DefaultMerchantAccountId,
5486
5560
  :descriptor => {
5487
- :name => '123*123456789012345678',
5488
- :phone => '3334445555',
5561
+ :name => "123*123456789012345678",
5562
+ :phone => "3334445555",
5489
5563
  :url => "ebay.com"
5490
5564
  },
5491
- :order_id => '123',
5565
+ :order_id => "123",
5492
5566
  :credit_card => {
5493
5567
  :number => Braintree::Test::CreditCardNumbers::Visa,
5494
5568
  :expiration_date => "06/2009"
5495
5569
  },
5496
5570
  :options => {
5497
5571
  :submit_for_settlement => true
5498
- }
5572
+ },
5499
5573
  )
5500
5574
  end
5501
5575
 
@@ -5503,16 +5577,16 @@ describe Braintree::Transaction do
5503
5577
  result = Braintree::Transaction.update_details(transaction.id, {
5504
5578
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5505
5579
  :descriptor => {
5506
- :name => '456*123456789012345678',
5507
- :phone => '3334445555',
5580
+ :name => "456*123456789012345678",
5581
+ :phone => "3334445555",
5508
5582
  :url => "ebay.com",
5509
5583
  },
5510
- :order_id => '456'
5584
+ :order_id => "456"
5511
5585
  })
5512
5586
  result.success?.should == true
5513
5587
  result.transaction.amount.should == BigDecimal(Braintree::Test::TransactionAmounts::Authorize) - 1
5514
- result.transaction.order_id.should == '456'
5515
- result.transaction.descriptor.name.should == '456*123456789012345678'
5588
+ result.transaction.order_id.should == "456"
5589
+ result.transaction.descriptor.name.should == "456*123456789012345678"
5516
5590
  end
5517
5591
 
5518
5592
  it "raises an error when a key is invalid" do
@@ -5520,11 +5594,11 @@ describe Braintree::Transaction do
5520
5594
  Braintree::Transaction.update_details(transaction.id, {
5521
5595
  :invalid_key => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5522
5596
  :descriptor => {
5523
- :name => '456*123456789012345678',
5524
- :phone => '3334445555',
5597
+ :name => "456*123456789012345678",
5598
+ :phone => "3334445555",
5525
5599
  :url => "ebay.com",
5526
5600
  },
5527
- :order_id => '456'
5601
+ :order_id => "456"
5528
5602
  })
5529
5603
  end.to raise_error(ArgumentError)
5530
5604
  end
@@ -5534,11 +5608,11 @@ describe Braintree::Transaction do
5534
5608
  result = Braintree::Transaction.update_details(transaction.id, {
5535
5609
  :amount => "10000",
5536
5610
  :descriptor => {
5537
- :name => '456*123456789012345678',
5538
- :phone => '3334445555',
5611
+ :name => "456*123456789012345678",
5612
+ :phone => "3334445555",
5539
5613
  :url => "ebay.com",
5540
5614
  },
5541
- :order_id => '456'
5615
+ :order_id => "456"
5542
5616
  })
5543
5617
  result.success?.should == false
5544
5618
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::SettlementAmountIsTooLarge
@@ -5548,11 +5622,11 @@ describe Braintree::Transaction do
5548
5622
  result = Braintree::Transaction.update_details(transaction.id, {
5549
5623
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5550
5624
  :descriptor => {
5551
- :name => 'invalid descriptor name',
5552
- :phone => 'invalid phone',
5553
- :url => '12345678901234'
5625
+ :name => "invalid descriptor name",
5626
+ :phone => "invalid phone",
5627
+ :url => "12345678901234"
5554
5628
  },
5555
- :order_id => '456'
5629
+ :order_id => "456"
5556
5630
  })
5557
5631
  result.success?.should == false
5558
5632
  result.errors.for(:transaction).for(:descriptor).on(:name)[0].code.should == Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid
@@ -5564,11 +5638,11 @@ describe Braintree::Transaction do
5564
5638
  result = Braintree::Transaction.update_details(transaction.id, {
5565
5639
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5566
5640
  :descriptor => {
5567
- :name => '456*123456789012345678',
5568
- :phone => '3334445555',
5641
+ :name => "456*123456789012345678",
5642
+ :phone => "3334445555",
5569
5643
  :url => "ebay.com",
5570
5644
  },
5571
- :order_id => 'x' * 256
5645
+ :order_id => "x" * 256
5572
5646
  })
5573
5647
  result.success?.should == false
5574
5648
  result.errors.for(:transaction).on(:order_id)[0].code.should == Braintree::ErrorCodes::Transaction::OrderIdIsTooLong
@@ -5579,27 +5653,27 @@ describe Braintree::Transaction do
5579
5653
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5580
5654
  :merchant_account_id => SpecHelper::FakeAmexDirectMerchantAccountId,
5581
5655
  :descriptor => {
5582
- :name => '123*123456789012345678',
5583
- :phone => '3334445555',
5656
+ :name => "123*123456789012345678",
5657
+ :phone => "3334445555",
5584
5658
  :url => "ebay.com"
5585
5659
  },
5586
- :order_id => '123',
5660
+ :order_id => "123",
5587
5661
  :credit_card => {
5588
5662
  :number => Braintree::Test::CreditCardNumbers::AmexPayWithPoints::Success,
5589
5663
  :expiration_date => "05/2009"
5590
5664
  },
5591
5665
  :options => {
5592
5666
  :submit_for_settlement => true
5593
- }
5667
+ },
5594
5668
  )
5595
5669
  result = Braintree::Transaction.update_details(transaction.id, {
5596
5670
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5597
5671
  :descriptor => {
5598
- :name => '456*123456789012345678',
5599
- :phone => '3334445555',
5672
+ :name => "456*123456789012345678",
5673
+ :phone => "3334445555",
5600
5674
  :url => "ebay.com",
5601
5675
  },
5602
- :order_id => '456'
5676
+ :order_id => "456"
5603
5677
  })
5604
5678
  result.success?.should == false
5605
5679
  result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::ProcessorDoesNotSupportUpdatingTransactionDetails
@@ -5613,24 +5687,24 @@ describe Braintree::Transaction do
5613
5687
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5614
5688
  :merchant_account_id => SpecHelper::DefaultMerchantAccountId,
5615
5689
  :descriptor => {
5616
- :name => '123*123456789012345678',
5617
- :phone => '3334445555',
5690
+ :name => "123*123456789012345678",
5691
+ :phone => "3334445555",
5618
5692
  :url => "ebay.com"
5619
5693
  },
5620
- :order_id => '123',
5694
+ :order_id => "123",
5621
5695
  :credit_card => {
5622
5696
  :number => Braintree::Test::CreditCardNumbers::Visa,
5623
5697
  :expiration_date => "06/2009"
5624
- }
5698
+ },
5625
5699
  )
5626
5700
  result = Braintree::Transaction.update_details(transaction.id, {
5627
5701
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5628
5702
  :descriptor => {
5629
- :name => '456*123456789012345678',
5630
- :phone => '3334445555',
5703
+ :name => "456*123456789012345678",
5704
+ :phone => "3334445555",
5631
5705
  :url => "ebay.com",
5632
5706
  },
5633
- :order_id => '456'
5707
+ :order_id => "456"
5634
5708
  })
5635
5709
  result.success?.should == false
5636
5710
  result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotUpdateTransactionDetailsNotSubmittedForSettlement
@@ -5647,7 +5721,7 @@ describe Braintree::Transaction do
5647
5721
  :credit_card => {
5648
5722
  :number => Braintree::Test::CreditCardNumbers::Visa,
5649
5723
  :expiration_date => "06/2009"
5650
- }
5724
+ },
5651
5725
  )
5652
5726
 
5653
5727
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100)
@@ -5682,7 +5756,7 @@ describe Braintree::Transaction do
5682
5756
  :credit_card => {
5683
5757
  :number => Braintree::Test::CreditCardNumbers::Visa,
5684
5758
  :expiration_date => "05/2009"
5685
- }
5759
+ },
5686
5760
  )
5687
5761
 
5688
5762
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100, :order_id => 1234)
@@ -5698,7 +5772,7 @@ describe Braintree::Transaction do
5698
5772
  :credit_card => {
5699
5773
  :number => Braintree::Test::CreditCardNumbers::Visa,
5700
5774
  :expiration_date => "05/2009"
5701
- }
5775
+ },
5702
5776
  )
5703
5777
 
5704
5778
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100, :order_id => "1"*256)
@@ -5713,13 +5787,13 @@ describe Braintree::Transaction do
5713
5787
  :credit_card => {
5714
5788
  :number => Braintree::Test::CreditCardNumbers::Visa,
5715
5789
  :expiration_date => "05/2009"
5716
- }
5790
+ },
5717
5791
  )
5718
5792
 
5719
5793
  result = Braintree::Transaction.submit_for_partial_settlement(
5720
5794
  authorized_transaction.id,
5721
5795
  100,
5722
- :descriptor => { :name => "123*123456789012345678", :phone => "5555551234", :url => "url.com" }
5796
+ :descriptor => {:name => "123*123456789012345678", :phone => "5555551234", :url => "url.com"},
5723
5797
  )
5724
5798
  result.success?.should == true
5725
5799
  partial_settlement_transaction = result.transaction
@@ -5735,7 +5809,7 @@ describe Braintree::Transaction do
5735
5809
  :credit_card => {
5736
5810
  :number => Braintree::Test::CreditCardNumbers::Visa,
5737
5811
  :expiration_date => "05/2009"
5738
- }
5812
+ },
5739
5813
  )
5740
5814
 
5741
5815
  result = Braintree::Transaction.submit_for_partial_settlement(
@@ -5743,9 +5817,9 @@ describe Braintree::Transaction do
5743
5817
  100,
5744
5818
  :descriptor => {
5745
5819
  :name => "invalid_format",
5746
- :phone => '%bad4445555',
5747
- :url => '12345678901234'
5748
- }
5820
+ :phone => "%bad4445555",
5821
+ :url => "12345678901234"
5822
+ },
5749
5823
  )
5750
5824
  result.success?.should == false
5751
5825
  result.errors.for(:transaction).for(:descriptor).on(:name)[0].code.should == Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid
@@ -5760,7 +5834,7 @@ describe Braintree::Transaction do
5760
5834
  :credit_card => {
5761
5835
  :number => Braintree::Test::CreditCardNumbers::AmexPayWithPoints::Success,
5762
5836
  :expiration_date => "05/2009"
5763
- }
5837
+ },
5764
5838
  )
5765
5839
 
5766
5840
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100)
@@ -5772,7 +5846,7 @@ describe Braintree::Transaction do
5772
5846
  authorized_transaction = Braintree::Transaction.sale!(
5773
5847
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5774
5848
  :merchant_account_id => SpecHelper::FakeVenmoAccountMerchantAccountId,
5775
- :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount
5849
+ :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
5776
5850
  )
5777
5851
 
5778
5852
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100)
@@ -5787,7 +5861,7 @@ describe Braintree::Transaction do
5787
5861
  :credit_card => {
5788
5862
  :number => Braintree::Test::CreditCardNumbers::Visa,
5789
5863
  :expiration_date => "06/2009"
5790
- }
5864
+ },
5791
5865
  )
5792
5866
 
5793
5867
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100)
@@ -5805,7 +5879,7 @@ describe Braintree::Transaction do
5805
5879
  :credit_card => {
5806
5880
  :number => Braintree::Test::CreditCardNumbers::Visa,
5807
5881
  :expiration_date => "06/2009"
5808
- }
5882
+ },
5809
5883
  )
5810
5884
 
5811
5885
  result = Braintree::Transaction.void(authorized_transaction.id)
@@ -5824,9 +5898,9 @@ describe Braintree::Transaction do
5824
5898
  :credit_card => {
5825
5899
  :number => Braintree::Test::CreditCardNumbers::Visa,
5826
5900
  :expiration_date => "06/2009"
5827
- }
5901
+ },
5828
5902
  )
5829
- options = { :order_id => "ABC123" }
5903
+ options = {:order_id => "ABC123"}
5830
5904
  transaction = Braintree::Transaction.submit_for_partial_settlement!(original_transaction.id, "0.01", options)
5831
5905
  transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
5832
5906
  transaction.order_id.should == options[:order_id]
@@ -5838,7 +5912,7 @@ describe Braintree::Transaction do
5838
5912
  :credit_card => {
5839
5913
  :number => Braintree::Test::CreditCardNumbers::Visa,
5840
5914
  :expiration_date => "06/2009"
5841
- }
5915
+ },
5842
5916
  )
5843
5917
  transaction.amount.should == BigDecimal("1000.00")
5844
5918
  expect do
@@ -5863,7 +5937,7 @@ describe Braintree::Transaction do
5863
5937
  :number => Braintree::Test::CreditCardNumbers::Visa,
5864
5938
  :expiration_date => "05/2009"
5865
5939
  },
5866
- :service_fee_amount => '1.00'
5940
+ :service_fee_amount => "1.00",
5867
5941
  )
5868
5942
 
5869
5943
  transaction.escrow_status.should be_nil
@@ -5889,7 +5963,7 @@ describe Braintree::Transaction do
5889
5963
  :number => Braintree::Test::CreditCardNumbers::Visa,
5890
5964
  :expiration_date => "05/2009"
5891
5965
  },
5892
- :service_fee_amount => '1.00'
5966
+ :service_fee_amount => "1.00",
5893
5967
  )
5894
5968
 
5895
5969
  transaction.escrow_status.should be_nil
@@ -5949,7 +6023,7 @@ describe Braintree::Transaction do
5949
6023
  :credit_card => {
5950
6024
  :number => Braintree::Test::CreditCardNumbers::Visa,
5951
6025
  :expiration_date => "05/2009"
5952
- }
6026
+ },
5953
6027
  )
5954
6028
  result.success?.should == true
5955
6029
  result.transaction.id.should =~ /^\w{6,}$/
@@ -5972,7 +6046,7 @@ describe Braintree::Transaction do
5972
6046
  }
5973
6047
  result = Braintree::Transaction.credit(params[:transaction])
5974
6048
  result.success?.should == false
5975
- result.params.should == {:transaction => {:type => 'credit', :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
6049
+ result.params.should == {:transaction => {:type => "credit", :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
5976
6050
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
5977
6051
  end
5978
6052
 
@@ -5983,7 +6057,7 @@ describe Braintree::Transaction do
5983
6057
  :credit_card => {
5984
6058
  :number => Braintree::Test::CreditCardNumbers::Visa,
5985
6059
  :expiration_date => "05/2009"
5986
- }
6060
+ },
5987
6061
  )
5988
6062
  result.success?.should == true
5989
6063
  result.transaction.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
@@ -5995,7 +6069,7 @@ describe Braintree::Transaction do
5995
6069
  :credit_card => {
5996
6070
  :number => Braintree::Test::CreditCardNumbers::Visa,
5997
6071
  :expiration_date => "05/2009"
5998
- }
6072
+ },
5999
6073
  )
6000
6074
  result.success?.should == true
6001
6075
  result.transaction.merchant_account_id.should == SpecHelper::DefaultMerchantAccountId
@@ -6025,7 +6099,7 @@ describe Braintree::Transaction do
6025
6099
  :credit_card => {
6026
6100
  :number => Braintree::Test::CreditCardNumbers::Visa,
6027
6101
  :expiration_date => "05/2009"
6028
- }
6102
+ },
6029
6103
  )
6030
6104
  transaction.id.should =~ /^\w{6,}$/
6031
6105
  transaction.type.should == "credit"
@@ -6042,205 +6116,27 @@ describe Braintree::Transaction do
6042
6116
  :credit_card => {
6043
6117
  :number => Braintree::Test::CreditCardNumbers::Visa,
6044
6118
  :expiration_date => "05/2009"
6045
- }
6119
+ },
6046
6120
  )
6047
6121
  end.to raise_error(Braintree::ValidationsFailed)
6048
6122
  end
6049
6123
  end
6050
6124
 
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
-
6125
+ describe "self.find" do
6126
+ it "finds the transaction with the given id" do
6127
+ result = Braintree::Transaction.create(
6128
+ :type => "sale",
6129
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
6130
+ :credit_card => {
6131
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6132
+ :expiration_date => "05/2009"
6133
+ },
6134
+ )
6071
6135
  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
- describe "self.find" do
6230
- it "finds the transaction with the given id" do
6231
- result = Braintree::Transaction.create(
6232
- :type => "sale",
6233
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6234
- :credit_card => {
6235
- :number => Braintree::Test::CreditCardNumbers::Visa,
6236
- :expiration_date => "05/2009"
6237
- }
6238
- )
6239
- result.success?.should == true
6240
- created_transaction = result.transaction
6241
- found_transaction = Braintree::Transaction.find(created_transaction.id)
6242
- found_transaction.should == created_transaction
6243
- found_transaction.graphql_id.should_not be_nil
6136
+ created_transaction = result.transaction
6137
+ found_transaction = Braintree::Transaction.find(created_transaction.id)
6138
+ found_transaction.should == created_transaction
6139
+ found_transaction.graphql_id.should_not be_nil
6244
6140
  end
6245
6141
 
6246
6142
  it "finds the vaulted transaction with the given id" do
@@ -6251,7 +6147,7 @@ describe Braintree::Transaction do
6251
6147
  :number => Braintree::Test::CreditCardNumbers::Visa,
6252
6148
  :expiration_date => "05/2009"
6253
6149
  },
6254
- :options => { :store_in_vault => true }
6150
+ :options => {:store_in_vault => true},
6255
6151
  )
6256
6152
  result.success?.should == true
6257
6153
  created_transaction = result.transaction
@@ -6267,6 +6163,12 @@ describe Braintree::Transaction do
6267
6163
  end.to raise_error(Braintree::NotFoundError, 'transaction with id "invalid-id" not found')
6268
6164
  end
6269
6165
 
6166
+ it "finds a transaction and returns an acquirer_reference_number if the transaction has one" do
6167
+ transaction = Braintree::Transaction.find("transactionwithacquirerreferencenumber")
6168
+
6169
+ transaction.acquirer_reference_number.should == "123456789 091019"
6170
+ end
6171
+
6270
6172
  context "disbursement_details" do
6271
6173
  it "includes disbursement_details on found transactions" do
6272
6174
  found_transaction = Braintree::Transaction.find("deposittransaction")
@@ -6274,7 +6176,8 @@ describe Braintree::Transaction do
6274
6176
  found_transaction.disbursed?.should == true
6275
6177
  disbursement = found_transaction.disbursement_details
6276
6178
 
6277
- disbursement.disbursement_date.should == "2013-04-10"
6179
+ expect(disbursement.disbursement_date).to be_a Date
6180
+ expect(disbursement.disbursement_date).to eq Date.parse("2013-04-10")
6278
6181
  disbursement.settlement_amount.should == "100.00"
6279
6182
  disbursement.settlement_currency_iso_code.should == "USD"
6280
6183
  disbursement.settlement_currency_exchange_rate.should == "1"
@@ -6289,7 +6192,7 @@ describe Braintree::Transaction do
6289
6192
  :credit_card => {
6290
6193
  :number => Braintree::Test::CreditCardNumbers::Visa,
6291
6194
  :expiration_date => "05/2009"
6292
- }
6195
+ },
6293
6196
  )
6294
6197
  result.success?.should == true
6295
6198
  created_transaction = result.transaction
@@ -6339,7 +6242,7 @@ describe Braintree::Transaction do
6339
6242
  :credit_card => {
6340
6243
  :number => Braintree::Test::CreditCardNumbers::Visa,
6341
6244
  :expiration_date => "05/2009"
6342
- }
6245
+ },
6343
6246
  )
6344
6247
  result.success?.should == true
6345
6248
  created_transaction = result.transaction
@@ -6352,15 +6255,21 @@ describe Braintree::Transaction do
6352
6255
  it "returns all the three_d_secure_info" do
6353
6256
  transaction = Braintree::Transaction.find("threedsecuredtransaction")
6354
6257
 
6258
+ expect(transaction.three_d_secure_info.authentication).to have_key(:trans_status)
6259
+ expect(transaction.three_d_secure_info.authentication).to have_key(:trans_status_reason)
6260
+ expect(transaction.three_d_secure_info.lookup).to have_key(:trans_status)
6261
+ expect(transaction.three_d_secure_info.lookup).to have_key(:trans_status_reason)
6262
+ transaction.three_d_secure_info.cavv.should == "somebase64value"
6263
+ transaction.three_d_secure_info.ds_transaction_id.should == "dstxnid"
6264
+ transaction.three_d_secure_info.eci_flag.should == "07"
6355
6265
  transaction.three_d_secure_info.enrolled.should == "Y"
6356
- transaction.three_d_secure_info.should be_liability_shifted
6266
+ transaction.three_d_secure_info.pares_status.should == "Y"
6357
6267
  transaction.three_d_secure_info.should be_liability_shift_possible
6268
+ transaction.three_d_secure_info.should be_liability_shifted
6358
6269
  transaction.three_d_secure_info.status.should == "authenticate_successful"
6359
- transaction.three_d_secure_info.cavv.should == "somebase64value"
6360
- transaction.three_d_secure_info.xid.should == "xidvalue"
6361
- transaction.three_d_secure_info.eci_flag.should == "07"
6270
+ expect(transaction.three_d_secure_info.three_d_secure_authentication_id).to be
6362
6271
  transaction.three_d_secure_info.three_d_secure_version.should == "1.0.2"
6363
- transaction.three_d_secure_info.ds_transaction_id.should == "dstxnid"
6272
+ transaction.three_d_secure_info.xid.should == "xidvalue"
6364
6273
  end
6365
6274
 
6366
6275
  it "is nil if the transaction wasn't 3d secured" do
@@ -6402,7 +6311,7 @@ describe Braintree::Transaction do
6402
6311
  :number => Braintree::Test::CreditCardNumbers::Visa,
6403
6312
  :expiration_date => "12/12",
6404
6313
  },
6405
- :service_fee_amount => "10.00"
6314
+ :service_fee_amount => "10.00",
6406
6315
  )
6407
6316
 
6408
6317
  result.transaction.escrow_status.should be_nil
@@ -6419,7 +6328,7 @@ describe Braintree::Transaction do
6419
6328
  :credit_card => {
6420
6329
  :number => Braintree::Test::CreditCardNumbers::Visa,
6421
6330
  :expiration_date => "05/2009"
6422
- }
6331
+ },
6423
6332
  )
6424
6333
 
6425
6334
  result = Braintree::Transaction.hold_in_escrow(transaction.id)
@@ -6437,7 +6346,7 @@ describe Braintree::Transaction do
6437
6346
  :number => Braintree::Test::CreditCardNumbers::Visa,
6438
6347
  :expiration_date => "12/12",
6439
6348
  },
6440
- :service_fee_amount => "10.00"
6349
+ :service_fee_amount => "10.00",
6441
6350
  )
6442
6351
 
6443
6352
  result.transaction.escrow_status.should be_nil
@@ -6453,7 +6362,7 @@ describe Braintree::Transaction do
6453
6362
  :credit_card => {
6454
6363
  :number => Braintree::Test::CreditCardNumbers::Visa,
6455
6364
  :expiration_date => "05/2009"
6456
- }
6365
+ },
6457
6366
  )
6458
6367
 
6459
6368
  expect do
@@ -6469,7 +6378,7 @@ describe Braintree::Transaction do
6469
6378
  :credit_card => {
6470
6379
  :number => Braintree::Test::CreditCardNumbers::Visa,
6471
6380
  :expiration_date => "05/2009"
6472
- }
6381
+ },
6473
6382
  )
6474
6383
  result = Braintree::Transaction.void(transaction.id)
6475
6384
  result.success?.should == true
@@ -6483,7 +6392,7 @@ describe Braintree::Transaction do
6483
6392
  :credit_card => {
6484
6393
  :number => Braintree::Test::CreditCardNumbers::Visa,
6485
6394
  :expiration_date => "05/2009"
6486
- }
6395
+ },
6487
6396
  ).transaction
6488
6397
  result = Braintree::Transaction.void(transaction.id)
6489
6398
  result.success?.should == false
@@ -6498,7 +6407,7 @@ describe Braintree::Transaction do
6498
6407
  :credit_card => {
6499
6408
  :number => Braintree::Test::CreditCardNumbers::Visa,
6500
6409
  :expiration_date => "05/2009"
6501
- }
6410
+ },
6502
6411
  )
6503
6412
  returned_transaction = Braintree::Transaction.void!(transaction.id)
6504
6413
  returned_transaction.should == transaction
@@ -6511,7 +6420,7 @@ describe Braintree::Transaction do
6511
6420
  :credit_card => {
6512
6421
  :number => Braintree::Test::CreditCardNumbers::Visa,
6513
6422
  :expiration_date => "05/2009"
6514
- }
6423
+ },
6515
6424
  ).transaction
6516
6425
  expect do
6517
6426
  Braintree::Transaction.void!(transaction.id)
@@ -6519,151 +6428,6 @@ describe Braintree::Transaction do
6519
6428
  end
6520
6429
  end
6521
6430
 
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
6431
  describe "status_history" do
6668
6432
  it "returns an array of StatusDetail" do
6669
6433
  transaction = Braintree::Transaction.sale!(
@@ -6671,12 +6435,12 @@ describe Braintree::Transaction do
6671
6435
  :credit_card => {
6672
6436
  :number => Braintree::Test::CreditCardNumbers::Visa,
6673
6437
  :expiration_date => "05/2009"
6674
- }
6438
+ },
6675
6439
  )
6676
- transaction.submit_for_settlement!
6677
- transaction.status_history.size.should == 2
6678
- transaction.status_history[0].status.should == Braintree::Transaction::Status::Authorized
6679
- transaction.status_history[1].status.should == Braintree::Transaction::Status::SubmittedForSettlement
6440
+ result = Braintree::Transaction.submit_for_settlement!(transaction.id)
6441
+ result.status_history.size.should == 2
6442
+ result.status_history[0].status.should == Braintree::Transaction::Status::Authorized
6443
+ result.status_history[1].status.should == Braintree::Transaction::Status::SubmittedForSettlement
6680
6444
  end
6681
6445
  end
6682
6446
 
@@ -6729,9 +6493,9 @@ describe Braintree::Transaction do
6729
6493
  :credit_card => {
6730
6494
  :number => Braintree::Test::CreditCardNumbers::Visa,
6731
6495
  :expiration_date => "05/2010"
6732
- }
6496
+ },
6733
6497
  )
6734
- transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
6498
+ transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, {:amount => "100.00"}).transaction
6735
6499
  transaction.vault_credit_card.should == customer.credit_cards[0]
6736
6500
  end
6737
6501
 
@@ -6742,7 +6506,7 @@ describe Braintree::Transaction do
6742
6506
  :credit_card => {
6743
6507
  :number => Braintree::Test::CreditCardNumbers::Visa,
6744
6508
  :expiration_date => "05/2010"
6745
- }
6509
+ },
6746
6510
  )
6747
6511
  transaction.vault_credit_card.should == nil
6748
6512
  end
@@ -6754,9 +6518,9 @@ describe Braintree::Transaction do
6754
6518
  :credit_card => {
6755
6519
  :number => Braintree::Test::CreditCardNumbers::Visa,
6756
6520
  :expiration_date => "05/2010"
6757
- }
6521
+ },
6758
6522
  )
6759
- transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
6523
+ transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, :amount => "100.00").transaction
6760
6524
  transaction.vault_customer.should == customer
6761
6525
  end
6762
6526
 
@@ -6767,74 +6531,12 @@ describe Braintree::Transaction do
6767
6531
  :credit_card => {
6768
6532
  :number => Braintree::Test::CreditCardNumbers::Visa,
6769
6533
  :expiration_date => "05/2010"
6770
- }
6534
+ },
6771
6535
  )
6772
6536
  transaction.vault_customer.should == nil
6773
6537
  end
6774
6538
  end
6775
6539
 
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
6540
  def create_transaction_to_refund
6839
6541
  transaction = Braintree::Transaction.sale!(
6840
6542
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -6844,7 +6546,7 @@ describe Braintree::Transaction do
6844
6546
  },
6845
6547
  :options => {
6846
6548
  :submit_for_settlement => true
6847
- }
6549
+ },
6848
6550
  )
6849
6551
 
6850
6552
  config = Braintree::Configuration.instantiate
@@ -6858,7 +6560,7 @@ describe Braintree::Transaction do
6858
6560
  :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
6859
6561
  :options => {
6860
6562
  :submit_for_settlement => true
6861
- }
6563
+ },
6862
6564
  )
6863
6565
 
6864
6566
  config = Braintree::Configuration.instantiate
@@ -6874,8 +6576,8 @@ describe Braintree::Transaction do
6874
6576
  :number => Braintree::Test::CreditCardNumbers::Visa,
6875
6577
  :expiration_date => "05/2009"
6876
6578
  },
6877
- :service_fee_amount => '1.00',
6878
- :options => { :hold_in_escrow => true }
6579
+ :service_fee_amount => "1.00",
6580
+ :options => {:hold_in_escrow => true},
6879
6581
  )
6880
6582
 
6881
6583
  config = Braintree::Configuration.instantiate
@@ -6889,7 +6591,7 @@ describe Braintree::Transaction do
6889
6591
  it "can create a transaction with venmo_sdk_payment_method_code" do
6890
6592
  result = Braintree::Transaction.sale(
6891
6593
  :amount => "10.00",
6892
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK.generate_test_payment_method_code(Braintree::Test::CreditCardNumbers::Visa)
6594
+ :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK.generate_test_payment_method_code(Braintree::Test::CreditCardNumbers::Visa),
6893
6595
  )
6894
6596
  result.success?.should == true
6895
6597
  result.transaction.credit_card_details.venmo_sdk?.should == false
@@ -6898,7 +6600,7 @@ describe Braintree::Transaction do
6898
6600
  it "errors when an invalid payment method code is passed" do
6899
6601
  result = Braintree::Transaction.sale(
6900
6602
  :amount => "10.00",
6901
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::InvalidPaymentMethodCode
6603
+ :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::InvalidPaymentMethodCode,
6902
6604
  )
6903
6605
  result.success?.should == false
6904
6606
  result.message.should include("Invalid VenmoSDK payment method code")
@@ -6916,7 +6618,7 @@ describe Braintree::Transaction do
6916
6618
  },
6917
6619
  :options => {
6918
6620
  :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
6919
- }
6621
+ },
6920
6622
  )
6921
6623
  result.success?.should == true
6922
6624
  result.transaction.credit_card_details.venmo_sdk?.should == false
@@ -6931,7 +6633,7 @@ describe Braintree::Transaction do
6931
6633
  },
6932
6634
  :options => {
6933
6635
  :venmo_sdk_session => Braintree::Test::VenmoSDK::InvalidSession
6934
- }
6636
+ },
6935
6637
  )
6936
6638
  result.success?.should == true
6937
6639
  result.transaction.credit_card_details.venmo_sdk?.should == false
@@ -6943,7 +6645,7 @@ describe Braintree::Transaction do
6943
6645
  it "can create a transaction for a paypal account" do
6944
6646
  result = Braintree::Transaction.sale(
6945
6647
  :amount => "10.00",
6946
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
6648
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
6947
6649
  )
6948
6650
  result.success?.should == true
6949
6651
  result.transaction.paypal_details.payer_email.should == "payer@example.com"
@@ -6958,7 +6660,7 @@ describe Braintree::Transaction do
6958
6660
  :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
6959
6661
  :options => {
6960
6662
  :store_in_vault => true
6961
- }
6663
+ },
6962
6664
  )
6963
6665
  result.success?.should == true
6964
6666
  result.transaction.paypal_details.token.should_not be_nil
@@ -6971,7 +6673,7 @@ describe Braintree::Transaction do
6971
6673
  customer = Braintree::Customer.create!
6972
6674
  result = Braintree::PaymentMethod.create(
6973
6675
  :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
6974
- :customer_id => customer.id
6676
+ :customer_id => customer.id,
6975
6677
  )
6976
6678
 
6977
6679
  result.should be_success
@@ -6981,7 +6683,7 @@ describe Braintree::Transaction do
6981
6683
  result = Braintree::Transaction.sale(
6982
6684
  :amount => "100",
6983
6685
  :customer_id => customer.id,
6984
- :payment_method_token => payment_method_token
6686
+ :payment_method_token => payment_method_token,
6985
6687
  )
6986
6688
 
6987
6689
  result.should be_success
@@ -6996,7 +6698,7 @@ describe Braintree::Transaction do
6996
6698
  nonce = nonce_for_paypal_account(:token => "TOKEN")
6997
6699
  result = Braintree::Transaction.sale(
6998
6700
  :amount => "10.00",
6999
- :payment_method_nonce => nonce
6701
+ :payment_method_nonce => nonce,
7000
6702
  )
7001
6703
  result.should_not be_success
7002
6704
  result.errors.for(:transaction).for(:paypal_account).first.code.should == Braintree::ErrorCodes::PayPalAccount::IncompletePayPalAccount
@@ -7011,7 +6713,7 @@ describe Braintree::Transaction do
7011
6713
  :public_key => "oauth_app_partner_user_public_key",
7012
6714
  :private_key => "oauth_app_partner_user_private_key",
7013
6715
  :environment => Braintree::Configuration.environment,
7014
- :logger => Logger.new("/dev/null")
6716
+ :logger => Logger.new("/dev/null"),
7015
6717
  )
7016
6718
  @customer = @partner_merchant_gateway.customer.create(
7017
6719
  :first_name => "Joe",
@@ -7020,12 +6722,12 @@ describe Braintree::Transaction do
7020
6722
  :email => "joe@example.com",
7021
6723
  :phone => "312.555.1234",
7022
6724
  :fax => "614.555.5678",
7023
- :website => "www.example.com"
6725
+ :website => "www.example.com",
7024
6726
  ).customer
7025
6727
  @address = @partner_merchant_gateway.address.create(
7026
6728
  :customer_id => @customer.id,
7027
6729
  :first_name => "Testy",
7028
- :last_name => "McTesterson"
6730
+ :last_name => "McTesterson",
7029
6731
  ).address
7030
6732
  @credit_card = @partner_merchant_gateway.credit_card.create(
7031
6733
  :customer_id => @customer.id,
@@ -7036,13 +6738,13 @@ describe Braintree::Transaction do
7036
6738
  :first_name => "Adam",
7037
6739
  :last_name => "Davis",
7038
6740
  :postal_code => "95131"
7039
- }
6741
+ },
7040
6742
  ).credit_card
7041
6743
 
7042
6744
  oauth_gateway = Braintree::Gateway.new(
7043
6745
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
7044
6746
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
7045
- :logger => Logger.new("/dev/null")
6747
+ :logger => Logger.new("/dev/null"),
7046
6748
  )
7047
6749
  access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
7048
6750
  :merchant_public_id => "integration_merchant_id",
@@ -7051,7 +6753,7 @@ describe Braintree::Transaction do
7051
6753
 
7052
6754
  @granting_gateway = Braintree::Gateway.new(
7053
6755
  :access_token => access_token,
7054
- :logger => Logger.new("/dev/null")
6756
+ :logger => Logger.new("/dev/null"),
7055
6757
  )
7056
6758
 
7057
6759
  end
@@ -7061,7 +6763,7 @@ describe Braintree::Transaction do
7061
6763
 
7062
6764
  result = Braintree::Transaction.sale(
7063
6765
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
7064
- :amount => Braintree::Test::TransactionAmounts::Authorize
6766
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7065
6767
  )
7066
6768
  result.transaction.facilitated_details.merchant_id.should == "integration_merchant_id"
7067
6769
  result.transaction.facilitated_details.merchant_name.should == "14ladders"
@@ -7077,7 +6779,7 @@ describe Braintree::Transaction do
7077
6779
 
7078
6780
  result = Braintree::Transaction.sale(
7079
6781
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
7080
- :amount => Braintree::Test::TransactionAmounts::Authorize
6782
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7081
6783
  )
7082
6784
 
7083
6785
  result.transaction.billing_details.postal_code == "95131"
@@ -7089,7 +6791,7 @@ describe Braintree::Transaction do
7089
6791
  :shared_customer_id => @customer.id,
7090
6792
  :shared_shipping_address_id => @address.id,
7091
6793
  :shared_billing_address_id => @address.id,
7092
- :amount => Braintree::Test::TransactionAmounts::Authorize
6794
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7093
6795
  )
7094
6796
  result.success?.should == true
7095
6797
  result.transaction.shipping_details.first_name.should == @address.first_name
@@ -7099,7 +6801,7 @@ describe Braintree::Transaction do
7099
6801
  it "facilitated details are returned on transaction created via a shared_payment_method_token" do
7100
6802
  result = @granting_gateway.transaction.sale(
7101
6803
  :shared_payment_method_token => @credit_card.token,
7102
- :amount => Braintree::Test::TransactionAmounts::Authorize
6804
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7103
6805
  )
7104
6806
  result.transaction.facilitated_details.merchant_id.should == "integration_merchant_id"
7105
6807
  result.transaction.facilitated_details.merchant_name.should == "14ladders"
@@ -7111,12 +6813,12 @@ describe Braintree::Transaction do
7111
6813
 
7112
6814
  it "facilitated details are returned on transaction created via a shared_payment_method_nonce" do
7113
6815
  shared_nonce = @partner_merchant_gateway.payment_method_nonce.create(
7114
- @credit_card.token
6816
+ @credit_card.token,
7115
6817
  ).payment_method_nonce.nonce
7116
6818
 
7117
6819
  result = @granting_gateway.transaction.sale(
7118
6820
  :shared_payment_method_nonce => shared_nonce,
7119
- :amount => Braintree::Test::TransactionAmounts::Authorize
6821
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7120
6822
  )
7121
6823
  result.transaction.facilitated_details.merchant_id.should == "integration_merchant_id"
7122
6824
  result.transaction.facilitated_details.merchant_name.should == "14ladders"
@@ -7129,7 +6831,7 @@ describe Braintree::Transaction do
7129
6831
 
7130
6832
  context "paypal here" do
7131
6833
  it "gets the details of an auth/capture transaction" do
7132
- result = Braintree::Transaction.find('paypal_here_auth_capture_id')
6834
+ result = Braintree::Transaction.find("paypal_here_auth_capture_id")
7133
6835
  result.payment_instrument_type.should eq(Braintree::PaymentInstrumentType::PayPalHere)
7134
6836
  result.paypal_here_details.should_not be_nil
7135
6837
 
@@ -7146,7 +6848,7 @@ describe Braintree::Transaction do
7146
6848
  end
7147
6849
 
7148
6850
  it "gets the details of a sale transaction" do
7149
- result = Braintree::Transaction.find('paypal_here_sale_id')
6851
+ result = Braintree::Transaction.find("paypal_here_sale_id")
7150
6852
  result.paypal_here_details.should_not be_nil
7151
6853
 
7152
6854
  details = result.paypal_here_details
@@ -7154,7 +6856,7 @@ describe Braintree::Transaction do
7154
6856
  end
7155
6857
 
7156
6858
  it "gets the details of a refunded sale transaction" do
7157
- result = Braintree::Transaction.find('paypal_here_refund_id')
6859
+ result = Braintree::Transaction.find("paypal_here_refund_id")
7158
6860
  result.paypal_here_details.should_not be_nil
7159
6861
 
7160
6862
  details = result.paypal_here_details
@@ -7179,7 +6881,7 @@ describe Braintree::Transaction do
7179
6881
  customer = Braintree::Customer.create!
7180
6882
  result = Braintree::PaymentMethod.create(
7181
6883
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
7182
- :customer_id => customer.id
6884
+ :customer_id => customer.id,
7183
6885
  )
7184
6886
  payment_method_token = result.payment_method.token
7185
6887
 
@@ -7194,4 +6896,230 @@ describe Braintree::Transaction do
7194
6896
  transaction.processed_with_network_token?.should == false
7195
6897
  end
7196
6898
  end
6899
+
6900
+ describe "installments" do
6901
+ it "creates a transaction with an installment count" do
6902
+ result = Braintree::Transaction.create(
6903
+ :type => "sale",
6904
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
6905
+ :credit_card => {
6906
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6907
+ :expiration_date => "05/2009"
6908
+ },
6909
+ :amount => "100.01",
6910
+ :installments => {
6911
+ :count => 12,
6912
+ },
6913
+ )
6914
+
6915
+ expect(result.success?).to eq(true)
6916
+ expect(result.transaction.installment_count).to eq(12)
6917
+ end
6918
+
6919
+ it "creates a transaction with a installments during capture" do
6920
+ result = Braintree::Transaction.create(
6921
+ :type => "sale",
6922
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
6923
+ :credit_card => {
6924
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6925
+ :expiration_date => "05/2009"
6926
+ },
6927
+ :amount => "100.01",
6928
+ :installments => {
6929
+ :count => 12,
6930
+ },
6931
+ :options => {
6932
+ :submit_for_settlement => true,
6933
+ },
6934
+ )
6935
+
6936
+ expect(result.success?).to eq(true)
6937
+ transaction = result.transaction
6938
+ expect(transaction.installment_count).to eq(12)
6939
+
6940
+ installments = transaction.installments
6941
+ expect(installments.map(&:id)).to match_array((1..12).map { |i| "#{transaction.id}_INST_#{i}" })
6942
+ expect(installments.map(&:amount)).to match_array([BigDecimal("8.33")] * 11 + [BigDecimal("8.38")])
6943
+ end
6944
+
6945
+ it "can refund a transaction with installments" do
6946
+ sale_result = Braintree::Transaction.create(
6947
+ :type => "sale",
6948
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
6949
+ :credit_card => {
6950
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6951
+ :expiration_date => "05/2009"
6952
+ },
6953
+ :amount => "100.01",
6954
+ :installments => {
6955
+ :count => 12,
6956
+ },
6957
+ :options => {
6958
+ :submit_for_settlement => true,
6959
+ },
6960
+ )
6961
+
6962
+ expect(sale_result.success?).to eq(true)
6963
+ sale_transaction = sale_result.transaction
6964
+
6965
+ refund_result = Braintree::Transaction.refund(sale_transaction.id, "49.99")
6966
+
6967
+ expect(refund_result.success?).to eq(true)
6968
+ refund_transaction = refund_result.transaction
6969
+ installments = refund_transaction.refunded_installments
6970
+
6971
+ (1..11).each do |i|
6972
+ installment = installments.find { |installment| installment.id == "#{sale_transaction.id}_INST_#{i}" }
6973
+
6974
+ expect(installment.amount).to eq(BigDecimal("8.33"))
6975
+ expect(installment.adjustments.map(&:amount)).to match_array([BigDecimal("-4.16")])
6976
+ expect(installment.adjustments.map(&:kind)).to match_array([Braintree::Transaction::Installment::Adjustment::Kind::Refund])
6977
+ end
6978
+
6979
+ installment = installments.find { |installment| installment.id == "#{sale_transaction.id}_INST_12" }
6980
+
6981
+ expect(installment.amount).to eq(BigDecimal("8.38"))
6982
+ expect(installment.adjustments.map(&:amount)).to match_array([BigDecimal("-4.23")])
6983
+ expect(installment.adjustments.map(&:kind)).to match_array([Braintree::Transaction::Installment::Adjustment::Kind::Refund])
6984
+ end
6985
+ end
6986
+
6987
+ describe "Adjust Authorization" do
6988
+ let(:first_data_master_transaction_params) do
6989
+ {
6990
+ :merchant_account_id => SpecHelper::FakeFirstDataMerchantAccountId,
6991
+ :amount => "75.50",
6992
+ :credit_card => {
6993
+ :number => "5105105105105100",
6994
+ :expiration_date => "05/2012"
6995
+ }
6996
+ }
6997
+ end
6998
+ let(:first_data_visa_transaction_params) do
6999
+ {
7000
+ :merchant_account_id => SpecHelper::FakeFirstDataMerchantAccountId,
7001
+ :amount => "75.50",
7002
+ :credit_card => {
7003
+ :number => Braintree::Test::CreditCardNumbers::Visa,
7004
+ :expiration_date => "06/2009"
7005
+ }
7006
+ }
7007
+ end
7008
+ context "successful authorization" do
7009
+ it "returns success response" do
7010
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params)
7011
+ expect(initial_transaction.success?).to eq(true)
7012
+
7013
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7014
+ initial_transaction.transaction.id, "85.50"
7015
+ )
7016
+
7017
+ expect(adjustment_transaction.success?).to eq(true)
7018
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("85.50"))
7019
+ end
7020
+ end
7021
+
7022
+ context "unsuccessful authorization" do
7023
+ it "returns failure, when processor does not support multi auth adjustment" do
7024
+ initial_transaction = Braintree::Transaction.sale(
7025
+ :merchant_account_id => SpecHelper::DefaultMerchantAccountId,
7026
+ :amount => "75.50",
7027
+ :credit_card => {
7028
+ :number => Braintree::Test::CreditCardNumbers::Visa,
7029
+ :expiration_date => "06/2009"
7030
+ },
7031
+ )
7032
+ expect(initial_transaction.success?).to eq(true)
7033
+
7034
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7035
+ initial_transaction.transaction.id, "85.50"
7036
+ )
7037
+
7038
+
7039
+ expect(adjustment_transaction.success?).to eq(false)
7040
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7041
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::ProcessorDoesNotSupportAuthAdjustment)
7042
+ end
7043
+
7044
+ it "returns failure response, when adjusted amount submitted is zero" do
7045
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params)
7046
+ expect(initial_transaction.success?).to eq(true)
7047
+
7048
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7049
+ initial_transaction.transaction.id, "0.0"
7050
+ )
7051
+
7052
+ expect(adjustment_transaction.success?).to eq(false)
7053
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7054
+ expect(adjustment_transaction.errors.for(:authorization_adjustment).on(:amount).first.code).to eq(Braintree::ErrorCodes::Transaction::AdjustmentAmountMustBeGreaterThanZero)
7055
+ end
7056
+
7057
+ it "returns failure response, when adjusted amount submitted same as authorized amount" do
7058
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params)
7059
+ expect(initial_transaction.success?).to eq(true)
7060
+
7061
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7062
+ initial_transaction.transaction.id, "75.50"
7063
+ )
7064
+
7065
+ expect(adjustment_transaction.success?).to eq(false)
7066
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7067
+ expect(adjustment_transaction.errors.for(:authorization_adjustment).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::NoNetAmountToPerformAuthAdjustment)
7068
+ end
7069
+
7070
+ it "returns failure, when transaction status is not authorized" do
7071
+ additional_params = {:options => {:submit_for_settlement => true}}
7072
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params.merge(additional_params))
7073
+ expect(initial_transaction.success?).to eq(true)
7074
+
7075
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7076
+ initial_transaction.transaction.id, "85.50"
7077
+ )
7078
+
7079
+ expect(adjustment_transaction.success?).to eq(false)
7080
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7081
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::TransactionMustBeInStateAuthorized)
7082
+ end
7083
+
7084
+ it "returns failure, when transaction authorization type final or undefined" do
7085
+ additional_params = {:transaction_source => "recurring_first"}
7086
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params.merge(additional_params))
7087
+ expect(initial_transaction.success?).to eq(true)
7088
+
7089
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7090
+ initial_transaction.transaction.id, "85.50"
7091
+ )
7092
+
7093
+ expect(adjustment_transaction.success?).to eq(false)
7094
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7095
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::TransactionIsNotEligibleForAdjustment)
7096
+ end
7097
+
7098
+ it "returns failure, when processor does not support incremental auth" do
7099
+ initial_transaction = Braintree::Transaction.sale(first_data_visa_transaction_params)
7100
+ expect(initial_transaction.success?).to eq(true)
7101
+
7102
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7103
+ initial_transaction.transaction.id, "85.50"
7104
+ )
7105
+
7106
+ expect(adjustment_transaction.success?).to eq(false)
7107
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7108
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::ProcessorDoesNotSupportIncrementalAuth)
7109
+ end
7110
+
7111
+ it "returns failure, when processor does not support auth reversal" do
7112
+ initial_transaction = Braintree::Transaction.sale(first_data_visa_transaction_params)
7113
+ expect(initial_transaction.success?).to eq(true)
7114
+
7115
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7116
+ initial_transaction.transaction.id, "65.50"
7117
+ )
7118
+
7119
+ expect(adjustment_transaction.success?).to eq(false)
7120
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7121
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::ProcessorDoesNotSupportPartialAuthReversal)
7122
+ end
7123
+ end
7124
+ end
7197
7125
  end