braintree 2.104.0 → 4.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree/account_updater_daily_report.rb +1 -1
  5. data/lib/braintree/address.rb +2 -23
  6. data/lib/braintree/apple_pay.rb +1 -1
  7. data/lib/braintree/apple_pay_card.rb +11 -1
  8. data/lib/braintree/apple_pay_options.rb +1 -1
  9. data/lib/braintree/authorization_adjustment.rb +1 -1
  10. data/lib/braintree/base_module.rb +6 -0
  11. data/lib/braintree/bin_data.rb +9 -2
  12. data/lib/braintree/client_token.rb +1 -1
  13. data/lib/braintree/configuration.rb +12 -12
  14. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  15. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  16. data/lib/braintree/credit_card.rb +2 -77
  17. data/lib/braintree/credit_card_gateway.rb +17 -36
  18. data/lib/braintree/credit_card_verification.rb +18 -5
  19. data/lib/braintree/credit_card_verification_search.rb +1 -1
  20. data/lib/braintree/customer.rb +9 -78
  21. data/lib/braintree/customer_gateway.rb +2 -23
  22. data/lib/braintree/customer_search.rb +1 -1
  23. data/lib/braintree/disbursement.rb +1 -1
  24. data/lib/braintree/{transaction/coinbase_details.rb → dispute/paypal_message.rb} +5 -6
  25. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  26. data/lib/braintree/dispute.rb +32 -8
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +6 -3
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/enriched_customer_data.rb +21 -0
  31. data/lib/braintree/error_codes.rb +150 -171
  32. data/lib/braintree/exceptions.rb +5 -3
  33. data/lib/braintree/exchange_rate.rb +13 -0
  34. data/lib/braintree/exchange_rate_quote.rb +24 -0
  35. data/lib/braintree/exchange_rate_quote_gateway.rb +35 -0
  36. data/lib/braintree/exchange_rate_quote_input.rb +21 -0
  37. data/lib/braintree/exchange_rate_quote_request.rb +18 -0
  38. data/lib/braintree/exchange_rate_quote_response.rb +18 -0
  39. data/lib/braintree/gateway.rb +4 -14
  40. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +11 -3
  41. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  42. data/lib/braintree/graphql_client.rb +7 -7
  43. data/lib/braintree/http.rb +4 -3
  44. data/lib/braintree/local_payment_completed.rb +2 -2
  45. data/lib/braintree/local_payment_expired.rb +21 -0
  46. data/lib/braintree/local_payment_funded.rb +22 -0
  47. data/lib/braintree/local_payment_reversed.rb +19 -0
  48. data/lib/braintree/merchant.rb +1 -1
  49. data/lib/braintree/merchant_account.rb +1 -1
  50. data/lib/braintree/merchant_account_gateway.rb +3 -1
  51. data/lib/braintree/merchant_gateway.rb +1 -1
  52. data/lib/braintree/modification.rb +1 -1
  53. data/lib/braintree/oauth_credentials.rb +1 -1
  54. data/lib/braintree/oauth_gateway.rb +5 -5
  55. data/lib/braintree/payment_instrument_type.rb +10 -14
  56. data/lib/braintree/payment_method_customer_data_updated_metadata.rb +24 -0
  57. data/lib/braintree/payment_method_gateway.rb +15 -17
  58. data/lib/braintree/payment_method_nonce.rb +7 -4
  59. data/lib/braintree/payment_method_nonce_details.rb +37 -0
  60. data/lib/braintree/payment_method_nonce_details_payer_info.rb +32 -0
  61. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  62. data/lib/braintree/payment_method_parser.rb +1 -8
  63. data/lib/braintree/plan.rb +21 -1
  64. data/lib/braintree/plan_gateway.rb +100 -0
  65. data/lib/braintree/processor_response_types.rb +3 -3
  66. data/lib/braintree/resource_collection.rb +8 -3
  67. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  68. data/lib/braintree/risk_data/liability_shift.rb +22 -0
  69. data/lib/braintree/risk_data.rb +5 -1
  70. data/lib/braintree/samsung_pay_card.rb +1 -1
  71. data/lib/braintree/settlement_batch_summary.rb +2 -2
  72. data/lib/braintree/subscription.rb +11 -11
  73. data/lib/braintree/successful_result.rb +3 -2
  74. data/lib/braintree/test/credit_card.rb +1 -0
  75. data/lib/braintree/test/nonce.rb +4 -23
  76. data/lib/braintree/three_d_secure_info.rb +22 -12
  77. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  78. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  79. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  80. data/lib/braintree/transaction/installment.rb +28 -0
  81. data/lib/braintree/transaction/paypal_details.rb +3 -0
  82. data/lib/braintree/transaction/subscription_details.rb +2 -0
  83. data/lib/braintree/transaction.rb +65 -120
  84. data/lib/braintree/transaction_gateway.rb +39 -27
  85. data/lib/braintree/transaction_line_item.rb +1 -1
  86. data/lib/braintree/transaction_review.rb +18 -0
  87. data/lib/braintree/transaction_search.rb +5 -3
  88. data/lib/braintree/unknown_payment_method.rb +1 -1
  89. data/lib/braintree/us_bank_account.rb +3 -3
  90. data/lib/braintree/us_bank_account_verification.rb +1 -1
  91. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  92. data/lib/braintree/util.rb +21 -6
  93. data/lib/braintree/venmo_account.rb +1 -1
  94. data/lib/braintree/venmo_profile_data.rb +23 -0
  95. data/lib/braintree/version.rb +2 -2
  96. data/lib/braintree/visa_checkout_card.rb +2 -2
  97. data/lib/braintree/webhook_notification.rb +44 -30
  98. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  99. data/lib/braintree/webhook_testing_gateway.rb +104 -43
  100. data/lib/braintree/xml/generator.rb +5 -4
  101. data/lib/braintree/xml/parser.rb +22 -35
  102. data/lib/braintree/xml/rexml.rb +4 -5
  103. data/lib/braintree.rb +28 -23
  104. data/spec/integration/braintree/add_on_spec.rb +1 -1
  105. data/spec/integration/braintree/address_spec.rb +30 -113
  106. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  107. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  108. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  109. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  110. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  111. data/spec/integration/braintree/credit_card_spec.rb +219 -593
  112. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  113. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  114. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  115. data/spec/integration/braintree/customer_spec.rb +484 -513
  116. data/spec/integration/braintree/dispute_search_spec.rb +35 -6
  117. data/spec/integration/braintree/dispute_spec.rb +6 -7
  118. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  119. data/spec/integration/braintree/exchange_rate_quote_spec.rb +97 -0
  120. data/spec/integration/braintree/graphql_client_spec.rb +0 -2
  121. data/spec/integration/braintree/http_spec.rb +2 -2
  122. data/spec/integration/braintree/merchant_account_spec.rb +28 -29
  123. data/spec/integration/braintree/merchant_spec.rb +14 -14
  124. data/spec/integration/braintree/oauth_spec.rb +11 -11
  125. data/spec/integration/braintree/payment_method_nonce_spec.rb +29 -35
  126. data/spec/integration/braintree/payment_method_spec.rb +535 -270
  127. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  128. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  129. data/spec/integration/braintree/plan_spec.rb +82 -0
  130. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  131. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  132. data/spec/integration/braintree/subscription_spec.rb +144 -149
  133. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  134. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  135. data/spec/integration/braintree/transaction_search_spec.rb +175 -70
  136. data/spec/integration/braintree/transaction_spec.rb +955 -894
  137. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  138. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  139. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  140. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  141. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  142. data/spec/integration/spec_helper.rb +16 -7
  143. data/spec/oauth_test_helper.rb +1 -1
  144. data/spec/script/httpsd.rb +6 -6
  145. data/spec/spec_helper.rb +8 -14
  146. data/spec/unit/braintree/address_spec.rb +1 -9
  147. data/spec/unit/braintree/apple_pay_card_spec.rb +7 -1
  148. data/spec/unit/braintree/client_token_spec.rb +2 -2
  149. data/spec/unit/braintree/configuration_spec.rb +42 -42
  150. data/spec/unit/braintree/credit_card_spec.rb +13 -32
  151. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  152. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  153. data/spec/unit/braintree/customer_spec.rb +21 -22
  154. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  155. data/spec/unit/braintree/dispute_search_spec.rb +3 -0
  156. data/spec/unit/braintree/dispute_spec.rb +75 -21
  157. data/spec/unit/braintree/enriched_customer_data_spec.rb +32 -0
  158. data/spec/unit/braintree/error_result_spec.rb +5 -5
  159. data/spec/unit/braintree/errors_spec.rb +8 -8
  160. data/spec/unit/braintree/exchange_rate_quote_input_spec.rb +42 -0
  161. data/spec/unit/braintree/exchange_rate_quote_request_spec.rb +82 -0
  162. data/spec/unit/braintree/exchange_rate_quote_response_spec.rb +52 -0
  163. data/spec/unit/braintree/exchange_rate_quote_spec.rb +42 -0
  164. data/spec/unit/braintree/exchange_rate_spec.rb +23 -0
  165. data/spec/unit/braintree/http_spec.rb +10 -8
  166. data/spec/unit/braintree/local_payment_completed_spec.rb +14 -0
  167. data/spec/unit/braintree/local_payment_expired_spec.rb +24 -0
  168. data/spec/unit/braintree/local_payment_funded_spec.rb +34 -0
  169. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  170. data/spec/unit/braintree/payment_method_customer_data_updated_metadata_spec.rb +45 -0
  171. data/spec/unit/braintree/payment_method_nonce_details_payer_info_spec.rb +31 -0
  172. data/spec/unit/braintree/payment_method_nonce_details_spec.rb +43 -0
  173. data/spec/unit/braintree/payment_method_nonce_spec.rb +40 -0
  174. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  175. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  176. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  177. data/spec/unit/braintree/risk_data/liability_shift.rb +26 -0
  178. data/spec/unit/braintree/risk_data_spec.rb +38 -8
  179. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  180. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  181. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  182. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  183. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  184. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  185. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  186. data/spec/unit/braintree/transaction/paypal_details_spec.rb +7 -1
  187. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  188. data/spec/unit/braintree/transaction_spec.rb +36 -54
  189. data/spec/unit/braintree/util_spec.rb +55 -21
  190. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  191. data/spec/unit/braintree/venmo_profile_data_spec.rb +32 -0
  192. data/spec/unit/braintree/webhook_notification_spec.rb +166 -57
  193. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  194. data/spec/unit/braintree/xml_spec.rb +31 -31
  195. metadata +62 -30
  196. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  197. data/lib/braintree/coinbase_account.rb +0 -34
  198. data/lib/braintree/europe_bank_account.rb +0 -36
  199. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  200. data/lib/braintree/ideal_payment.rb +0 -61
  201. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  202. data/lib/braintree/masterpass_card.rb +0 -83
  203. data/lib/braintree/settlement_batch.rb +0 -0
  204. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  205. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  206. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  207. data/lib/braintree/transparent_redirect.rb +0 -40
  208. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  209. data/spec/hacks/tcp_socket.rb +0 -18
  210. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  211. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  212. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  213. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
@@ -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,48 @@ 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
+ )
136
+ expect(result.transaction.risk_data).to be_a(Braintree::RiskData)
137
+ expect(result.transaction.risk_data.id).not_to be_nil
138
+ expect(result.transaction.risk_data.decision).not_to be_nil
139
+ expect(result.transaction.risk_data.decision_reasons).not_to 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)
143
+ end
144
+ end
145
+
146
+ it "returns decision, device_data_captured, id, liability_shift, and decision_reasons" do
147
+ with_chargeback_protection_merchant do
148
+ result = Braintree::Transaction.create(
149
+ :type => "sale",
150
+ :amount => 1_00,
151
+ :credit_card => {
152
+ :number => "4111111111111111",
153
+ :expiration_date => "05/2009"
154
+ },
135
155
  )
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)
156
+ expect(result.transaction.risk_data).to be_a(Braintree::RiskData)
157
+ expect(result.transaction.risk_data.id).not_to be_nil
158
+ expect(result.transaction.risk_data.decision).not_to be_nil
159
+ expect(result.transaction.risk_data.decision_reasons).not_to be_nil
160
+ expect(result.transaction.risk_data).to respond_to(:device_data_captured)
161
+ expect(result.transaction.risk_data).to respond_to(:fraud_service_provider)
162
+ expect(result.transaction.risk_data).to respond_to(:liability_shift)
141
163
  end
142
164
  end
143
165
 
144
166
  it "handles validation errors for invalid risk data attributes" do
145
- with_advanced_fraud_integration_merchant do
167
+ with_advanced_fraud_kount_integration_merchant do
146
168
  result = Braintree::Transaction.create(
147
169
  :type => "sale",
148
170
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -156,10 +178,9 @@ describe Braintree::Transaction do
156
178
  :customer_ip => "192.168.0.1",
157
179
  :customer_location_zip => "not-a-$#phone",
158
180
  :customer_tenure => "20#{"0" * 500}"
159
- }
181
+ },
160
182
  )
161
- 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
183
+ expect(result.success?).to eq(false)
163
184
  result.errors.for(:transaction).for(:risk_data).on(:customer_device_id).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerDeviceIdIsTooLong
164
185
  result.errors.for(:transaction).for(:risk_data).on(:customer_location_zip).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerLocationZipInvalidCharacters
165
186
  result.errors.for(:transaction).for(:risk_data).on(:customer_tenure).map { |e| e.code }.should include Braintree::ErrorCodes::RiskData::CustomerTenureIsTooLong
@@ -175,13 +196,49 @@ describe Braintree::Transaction do
175
196
  :credit_card => {
176
197
  :number => Braintree::Test::CreditCardNumbers::CardTypeIndicators::Prepaid,
177
198
  :expiration_date => "05/2009"
178
- }
199
+ },
179
200
  )
180
201
  result.transaction.credit_card_details.prepaid.should == Braintree::CreditCard::Prepaid::Yes
181
202
  result.transaction.payment_instrument_type.should == Braintree::PaymentInstrumentType::CreditCard
182
203
  end
183
204
  end
184
205
 
206
+ describe "sca_exemption" do
207
+ context "with a valid request" do
208
+ it "succeeds" do
209
+ requested_exemption = "low_value"
210
+ result = Braintree::Transaction.create(
211
+ :type => "sale",
212
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
213
+ :credit_card => {
214
+ :number => Braintree::Test::CreditCardNumbers::VisaCountryOfIssuanceIE,
215
+ :expiration_date => "05/2009"
216
+ },
217
+ :sca_exemption => requested_exemption,
218
+ )
219
+ expect(result).to be_success
220
+ expect(result.transaction.sca_exemption_requested).to eq(requested_exemption)
221
+ end
222
+ end
223
+
224
+ context "with an invalid request" do
225
+ it "returns an error" do
226
+ result = Braintree::Transaction.create(
227
+ :type => "sale",
228
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
229
+ :credit_card => {
230
+ :number => Braintree::Test::CreditCardNumbers::Visa,
231
+ :expiration_date => "05/2009"
232
+ },
233
+ :sca_exemption => "invalid_sca_exemption_value",
234
+ )
235
+ sca_exemption_invalid = Braintree::ErrorCodes::Transaction::ScaExemptionInvalid
236
+ expect(result).not_to be_success
237
+ expect(result.errors.for(:transaction).map(&:code)).to eq([sca_exemption_invalid])
238
+ end
239
+ end
240
+ end
241
+
185
242
  describe "industry data" do
186
243
  context "for lodging" do
187
244
  it "accepts valid industry data" do
@@ -215,7 +272,7 @@ describe Braintree::Transaction do
215
272
  },
216
273
  ],
217
274
  }
218
- }
275
+ },
219
276
  )
220
277
  result.success?.should be(true)
221
278
  end
@@ -242,15 +299,15 @@ describe Braintree::Transaction do
242
299
  },
243
300
  ],
244
301
  }
245
- }
302
+ },
246
303
  )
247
304
  result.success?.should be(false)
248
305
  invalid_folio = Braintree::ErrorCodes::Transaction::Industry::Lodging::FolioNumberIsInvalid
249
306
  check_out_date_must_follow_check_in_date = Braintree::ErrorCodes::Transaction::Industry::Lodging::CheckOutDateMustFollowCheckInDate
250
307
  room_rate_format_is_invalid = Braintree::ErrorCodes::Transaction::Industry::Lodging::RoomRateFormatIsInvalid
251
308
  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]
309
+ 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])
310
+ 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
311
  end
255
312
  end
256
313
 
@@ -272,7 +329,7 @@ describe Braintree::Transaction do
272
329
  :lodging_check_out_date => "2014-07-07",
273
330
  :lodging_name => "Royal Caribbean",
274
331
  }
275
- }
332
+ },
276
333
  )
277
334
  result.success?.should be(true)
278
335
  end
@@ -290,7 +347,7 @@ describe Braintree::Transaction do
290
347
  :data => {
291
348
  :lodging_name => "Royal Caribbean"
292
349
  }
293
- }
350
+ },
294
351
  )
295
352
  result.success?.should be(false)
296
353
  result.errors.for(:transaction).for(:industry).map { |e| e.code }.sort.should == [Braintree::ErrorCodes::Transaction::Industry::TravelCruise::TravelPackageIsInvalid]
@@ -364,7 +421,7 @@ describe Braintree::Transaction do
364
421
  }
365
422
  ]
366
423
  }
367
- }
424
+ },
368
425
  )
369
426
  result.success?.should be(true)
370
427
  end
@@ -388,7 +445,7 @@ describe Braintree::Transaction do
388
445
  }
389
446
  ]
390
447
  }
391
- }
448
+ },
392
449
  )
393
450
  result.success?.should be(false)
394
451
  result.errors.for(:transaction).for(:industry).map { |e| e.code }.sort.should == [Braintree::ErrorCodes::Transaction::Industry::TravelFlight::FareAmountCannotBeNegative]
@@ -407,7 +464,7 @@ describe Braintree::Transaction do
407
464
  :number => Braintree::Test::CreditCardNumbers::Elo,
408
465
  :cvv => "737",
409
466
  :expiration_date => "10/2020"
410
- }
467
+ },
411
468
  )
412
469
  result.success?.should == true
413
470
  result.transaction.id.should =~ /^\w{6,}$/
@@ -429,7 +486,7 @@ describe Braintree::Transaction do
429
486
  :credit_card => {
430
487
  :number => Braintree::Test::CreditCardNumbers::Visa,
431
488
  :expiration_date => "05/2009"
432
- }
489
+ },
433
490
  )
434
491
  result.success?.should == true
435
492
  result.transaction.id.should =~ /^\w{6,}$/
@@ -445,6 +502,7 @@ describe Braintree::Transaction do
445
502
  result.transaction.credit_card_details.expiration_date.should == "05/2009"
446
503
  result.transaction.credit_card_details.customer_location.should == "US"
447
504
  result.transaction.retrieval_reference_number.should_not be_nil
505
+ result.transaction.acquirer_reference_number.should be_nil
448
506
  end
449
507
 
450
508
  it "returns a successful network response code if successful" do
@@ -454,7 +512,7 @@ describe Braintree::Transaction do
454
512
  :credit_card => {
455
513
  :number => Braintree::Test::CreditCardNumbers::Visa,
456
514
  :expiration_date => "05/2009"
457
- }
515
+ },
458
516
  )
459
517
  expect(result.success?).to eq(true)
460
518
  expect(result.transaction.type).to eq("sale")
@@ -476,7 +534,7 @@ describe Braintree::Transaction do
476
534
  oauth_gateway = Braintree::Gateway.new(
477
535
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
478
536
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
479
- :logger => Logger.new("/dev/null")
537
+ :logger => Logger.new("/dev/null"),
480
538
  )
481
539
  access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
482
540
  :merchant_public_id => "integration_merchant_id",
@@ -485,7 +543,7 @@ describe Braintree::Transaction do
485
543
 
486
544
  gateway = Braintree::Gateway.new(
487
545
  :access_token => access_token,
488
- :logger => Logger.new("/dev/null")
546
+ :logger => Logger.new("/dev/null"),
489
547
  )
490
548
 
491
549
  result = gateway.transaction.create(
@@ -494,7 +552,7 @@ describe Braintree::Transaction do
494
552
  :credit_card => {
495
553
  :number => Braintree::Test::CreditCardNumbers::Visa,
496
554
  :expiration_date => "05/2009"
497
- }
555
+ },
498
556
  )
499
557
 
500
558
  result.success?.should == true
@@ -509,7 +567,7 @@ describe Braintree::Transaction do
509
567
  result.transaction.credit_card_details.customer_location.should == "US"
510
568
  end
511
569
 
512
- it "accepts additional security parameters: device_session_id and fraud_merchant_id" do
570
+ it "accepts additional security parameters: device_data" do
513
571
  result = Braintree::Transaction.create(
514
572
  :type => "sale",
515
573
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -517,8 +575,7 @@ describe Braintree::Transaction do
517
575
  :number => Braintree::Test::CreditCardNumbers::Visa,
518
576
  :expiration_date => "05/2009"
519
577
  },
520
- :device_session_id => "abc123",
521
- :fraud_merchant_id => "7"
578
+ :device_data => "device_data",
522
579
  )
523
580
 
524
581
  result.success?.should == true
@@ -538,7 +595,7 @@ describe Braintree::Transaction do
538
595
  :customer_ip => "192.168.0.1",
539
596
  :customer_location_zip => "91244",
540
597
  :customer_tenure => "20",
541
- }
598
+ },
542
599
  )
543
600
 
544
601
  result.success?.should == true
@@ -548,7 +605,7 @@ describe Braintree::Transaction do
548
605
  result = Braintree::Customer.create()
549
606
  address_result = Braintree::Address.create(
550
607
  :customer_id => result.customer.id,
551
- :country_code_alpha2 => "US"
608
+ :country_code_alpha2 => "US",
552
609
  )
553
610
 
554
611
  result = Braintree::Transaction.create(
@@ -559,7 +616,7 @@ describe Braintree::Transaction do
559
616
  :credit_card => {
560
617
  :number => Braintree::Test::CreditCardNumbers::Visa,
561
618
  :expiration_date => "05/2009"
562
- }
619
+ },
563
620
  )
564
621
 
565
622
  result.success?.should == true
@@ -572,7 +629,7 @@ describe Braintree::Transaction do
572
629
  :credit_card => {
573
630
  :number => Braintree::Test::CreditCardNumbers::Visa,
574
631
  :expiration_date => "05/2009"
575
- }
632
+ },
576
633
  )
577
634
  result.success?.should == false
578
635
  result.transaction.id.should =~ /^\w{6,}$/
@@ -591,7 +648,7 @@ describe Braintree::Transaction do
591
648
  :credit_card => {
592
649
  :number => Braintree::Test::CreditCardNumbers::Visa,
593
650
  :expiration_date => "05/2009"
594
- }
651
+ },
595
652
  )
596
653
  result.success?.should == false
597
654
  result.transaction.id.should =~ /^\w{6,}$/
@@ -628,7 +685,7 @@ describe Braintree::Transaction do
628
685
  :options => {
629
686
  :add_billing_address_to_payment_method => true,
630
687
  :store_in_vault => true
631
- }
688
+ },
632
689
  )
633
690
  result.success?.should == true
634
691
  transaction = result.transaction
@@ -658,7 +715,7 @@ describe Braintree::Transaction do
658
715
  :billing => {
659
716
  :country_name => "Botswana",
660
717
  :country_code_alpha2 => "US",
661
- }
718
+ },
662
719
  )
663
720
 
664
721
  result.success?.should == false
@@ -674,7 +731,7 @@ describe Braintree::Transaction do
674
731
  },
675
732
  :billing => {
676
733
  :country_code_alpha2 => "ZZ"
677
- }
734
+ },
678
735
  )
679
736
 
680
737
  result.success?.should == false
@@ -691,7 +748,7 @@ describe Braintree::Transaction do
691
748
  },
692
749
  :billing => {
693
750
  :country_code_alpha3 => "ZZZ"
694
- }
751
+ },
695
752
  )
696
753
 
697
754
  result.success?.should == false
@@ -708,7 +765,7 @@ describe Braintree::Transaction do
708
765
  },
709
766
  :billing => {
710
767
  :country_code_numeric => "FOO"
711
- }
768
+ },
712
769
  )
713
770
 
714
771
  result.success?.should == false
@@ -739,7 +796,7 @@ describe Braintree::Transaction do
739
796
  },
740
797
  :shipping => {
741
798
  :phone_number => "123-234-3456=098765"
742
- }
799
+ },
743
800
  )
744
801
 
745
802
  result.success?.should == false
@@ -755,7 +812,7 @@ describe Braintree::Transaction do
755
812
  },
756
813
  :shipping => {
757
814
  :shipping_method => "urgent"
758
- }
815
+ },
759
816
  )
760
817
 
761
818
  result.success?.should == false
@@ -771,7 +828,7 @@ describe Braintree::Transaction do
771
828
  },
772
829
  :billing => {
773
830
  :phone_number => "123-234-3456=098765"
774
- }
831
+ },
775
832
  )
776
833
 
777
834
  result.success?.should == false
@@ -795,7 +852,7 @@ describe Braintree::Transaction do
795
852
  :number => Braintree::Test::CreditCardNumbers::Visa,
796
853
  :expiration_date => "05/2009",
797
854
  :cvv => "200"
798
- }
855
+ },
799
856
  )
800
857
  result.success?.should == false
801
858
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::CVV
@@ -810,17 +867,17 @@ describe Braintree::Transaction do
810
867
  gateway = Braintree::Gateway.new(
811
868
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
812
869
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
813
- :logger => Logger.new("/dev/null")
870
+ :logger => Logger.new("/dev/null"),
814
871
  )
815
872
  result = gateway.merchant.create(
816
873
  :email => "name@email.com",
817
874
  :country_code_alpha3 => "USA",
818
- :payment_methods => ["credit_card", "paypal"]
875
+ :payment_methods => ["credit_card", "paypal"],
819
876
  )
820
877
 
821
878
  gateway = Braintree::Gateway.new(
822
879
  :access_token => result.credentials.access_token,
823
- :logger => Logger.new("/dev/null")
880
+ :logger => Logger.new("/dev/null"),
824
881
  )
825
882
 
826
883
  result = gateway.transaction.create(
@@ -829,7 +886,7 @@ describe Braintree::Transaction do
829
886
  :credit_card => {
830
887
  :number => Braintree::Test::CreditCardNumbers::Visa,
831
888
  :expiration_date => "05/2020"
832
- }
889
+ },
833
890
  )
834
891
  result.success?.should == false
835
892
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::ApplicationIncomplete
@@ -853,7 +910,7 @@ describe Braintree::Transaction do
853
910
  :credit_card => {
854
911
  :number => Braintree::Test::CreditCardNumbers::Visa,
855
912
  :expiration_date => "05/2009"
856
- }
913
+ },
857
914
  )
858
915
  result.success?.should == false
859
916
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::AVS
@@ -883,7 +940,7 @@ describe Braintree::Transaction do
883
940
  :number => Braintree::Test::CreditCardNumbers::Visa,
884
941
  :expiration_date => "05/2009",
885
942
  :cvv => "200"
886
- }
943
+ },
887
944
  )
888
945
  result.success?.should == false
889
946
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::AVSAndCVV
@@ -895,14 +952,14 @@ describe Braintree::Transaction do
895
952
  end
896
953
 
897
954
  it "exposes the fraud gateway rejection reason" do
898
- with_advanced_fraud_integration_merchant do
955
+ with_advanced_fraud_kount_integration_merchant do
899
956
  result = Braintree::Transaction.sale(
900
957
  :amount => Braintree::Test::TransactionAmounts::Authorize,
901
958
  :credit_card => {
902
959
  :number => Braintree::Test::CreditCardNumbers::Fraud,
903
960
  :expiration_date => "05/2017",
904
961
  :cvv => "333"
905
- }
962
+ },
906
963
  )
907
964
  result.success?.should == false
908
965
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::Fraud
@@ -910,14 +967,14 @@ describe Braintree::Transaction do
910
967
  end
911
968
 
912
969
  it "exposes the risk_threshold gateway rejection reason (via test cc num)" do
913
- with_advanced_fraud_integration_merchant do
970
+ with_advanced_fraud_kount_integration_merchant do
914
971
  result = Braintree::Transaction.sale(
915
972
  :amount => Braintree::Test::TransactionAmounts::Authorize,
916
973
  :credit_card => {
917
974
  :number => Braintree::Test::CreditCardNumbers::RiskThreshold,
918
975
  :expiration_date => "05/2017",
919
976
  :cvv => "333"
920
- }
977
+ },
921
978
  )
922
979
  result.success?.should == false
923
980
  result.transaction.gateway_rejection_reason.should == Braintree::Transaction::GatewayRejectionReason::RiskThreshold
@@ -925,7 +982,7 @@ describe Braintree::Transaction do
925
982
  end
926
983
 
927
984
  it "exposes the risk_threshold gateway rejection reason (via test test nonce)" do
928
- with_advanced_fraud_integration_merchant do
985
+ with_advanced_fraud_kount_integration_merchant do
929
986
  result = Braintree::Transaction.sale(
930
987
  :amount => Braintree::Test::TransactionAmounts::Authorize,
931
988
  :payment_method_nonce => Braintree::Test::Nonce::GatewayRejectedRiskThresholds,
@@ -954,7 +1011,7 @@ describe Braintree::Transaction do
954
1011
  :number => Braintree::Test::CreditCardNumbers::Visa,
955
1012
  :expiration_month => "05",
956
1013
  :expiration_year => "2011"
957
- }
1014
+ },
958
1015
  )
959
1016
  result.success?.should == true
960
1017
  result.transaction.credit_card_details.expiration_month.should == "05"
@@ -962,11 +1019,39 @@ describe Braintree::Transaction do
962
1019
  result.transaction.credit_card_details.expiration_date.should == "05/2011"
963
1020
  end
964
1021
 
1022
+ it "accepts exchange_rate_quote_id" do
1023
+ result = Braintree::Transaction.create(
1024
+ :type => "sale",
1025
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1026
+ :credit_card => {
1027
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1028
+ :expiration_date => "05/2009"
1029
+ },
1030
+ :exchange_rate_quote_id => "dummyExchangeRateQuoteId-Brainree-Ruby",
1031
+ )
1032
+ result.success?.should == true
1033
+ result.transaction.credit_card_details.expiration_date.should == "05/2009"
1034
+ end
1035
+
1036
+ it "returns an error if provided invalid exchange_rate_quote_id" do
1037
+ result = Braintree::Transaction.create(
1038
+ :type => "sale",
1039
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
1040
+ :credit_card => {
1041
+ :number => Braintree::Test::CreditCardNumbers::Visa,
1042
+ :expiration_date => "05/2009"
1043
+ },
1044
+ :exchange_rate_quote_id => "a" * 4010,
1045
+ )
1046
+ result.success?.should == false
1047
+ result.errors.for(:transaction).on(:exchange_rate_quote_id)[0].code.should == Braintree::ErrorCodes::Transaction::ExchangeRateQuoteIdTooLong
1048
+ end
1049
+
965
1050
  it "returns some error if customer_id is invalid" do
966
1051
  result = Braintree::Transaction.create(
967
1052
  :type => "sale",
968
1053
  :amount => Braintree::Test::TransactionAmounts::Decline,
969
- :customer_id => 123456789
1054
+ :customer_id => 123456789,
970
1055
  )
971
1056
  result.success?.should == false
972
1057
  result.errors.for(:transaction).on(:customer_id)[0].code.should == "91510"
@@ -983,7 +1068,7 @@ describe Braintree::Transaction do
983
1068
  },
984
1069
  :custom_fields => {
985
1070
  :store_me => "custom value"
986
- }
1071
+ },
987
1072
  )
988
1073
  result.success?.should == true
989
1074
  result.transaction.custom_fields.should == {:store_me => "custom value"}
@@ -998,7 +1083,7 @@ describe Braintree::Transaction do
998
1083
  },
999
1084
  :custom_fields => {
1000
1085
  :store_me => ""
1001
- }
1086
+ },
1002
1087
  )
1003
1088
 
1004
1089
  result = Braintree::Transaction.find(create_result.transaction.id)
@@ -1016,7 +1101,7 @@ describe Braintree::Transaction do
1016
1101
  },
1017
1102
  :custom_fields => {
1018
1103
  :invalid_key => "custom value"
1019
- }
1104
+ },
1020
1105
  )
1021
1106
  result.success?.should == false
1022
1107
  result.errors.for(:transaction).on(:custom_fields)[0].message.should == "Custom field is invalid: invalid_key."
@@ -1035,7 +1120,7 @@ describe Braintree::Transaction do
1035
1120
  }
1036
1121
  result = Braintree::Transaction.create(params[:transaction])
1037
1122
  result.success?.should == false
1038
- result.params.should == {:transaction => {:type => 'sale', :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
1123
+ result.params.should == {:transaction => {:type => "sale", :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
1039
1124
  end
1040
1125
 
1041
1126
  it "returns errors if validations fail (tests many errors at once for spec speed)" do
@@ -1055,7 +1140,7 @@ describe Braintree::Transaction do
1055
1140
  }
1056
1141
  result = Braintree::Transaction.create(params[:transaction])
1057
1142
  result.success?.should == false
1058
- result.errors.for(:transaction).on(:base).map{|error| error.code}.should include(Braintree::ErrorCodes::Transaction::PaymentMethodDoesNotBelongToCustomer)
1143
+ result.errors.for(:transaction).on(:base).map { |error| error.code }.should include(Braintree::ErrorCodes::Transaction::PaymentMethodDoesNotBelongToCustomer)
1059
1144
  result.errors.for(:transaction).on(:customer_id)[0].code.should == Braintree::ErrorCodes::Transaction::CustomerIdIsInvalid
1060
1145
  result.errors.for(:transaction).on(:payment_method_token)[0].code.should == Braintree::ErrorCodes::Transaction::PaymentMethodTokenIsInvalid
1061
1146
  result.errors.for(:transaction).on(:type)[0].code.should == Braintree::ErrorCodes::Transaction::TypeIsInvalid
@@ -1086,7 +1171,7 @@ describe Braintree::Transaction do
1086
1171
  :credit_card => {
1087
1172
  :account_type => "credit",
1088
1173
  }
1089
- }
1174
+ },
1090
1175
  )
1091
1176
  result.success?.should == false
1092
1177
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountNotSupportedByProcessor
@@ -1130,13 +1215,13 @@ describe Braintree::Transaction do
1130
1215
  :credit_card => {
1131
1216
  :number => Braintree::Test::CreditCardNumbers::Visa,
1132
1217
  :expiration_date => "05/2010"
1133
- }
1218
+ },
1134
1219
  )
1135
1220
  result = Braintree::Transaction.create(
1136
1221
  :type => "sale",
1137
1222
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1138
1223
  :customer_id => customer.id,
1139
- :payment_method_token => customer.credit_cards[0].token + "x"
1224
+ :payment_method_token => customer.credit_cards[0].token + "x",
1140
1225
  )
1141
1226
  result.success?.should == false
1142
1227
  result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::PaymentMethodDoesNotBelongToCustomer
@@ -1148,7 +1233,7 @@ describe Braintree::Transaction do
1148
1233
  :credit_card => {
1149
1234
  :number => Braintree::Test::CreditCardNumbers::Visa,
1150
1235
  :expiration_date => "05/2010"
1151
- }
1236
+ },
1152
1237
  )
1153
1238
  result = Braintree::Transaction.create(
1154
1239
  :type => "sale",
@@ -1157,7 +1242,7 @@ describe Braintree::Transaction do
1157
1242
  :credit_card => {
1158
1243
  :number => Braintree::Test::CreditCardNumbers::Visa,
1159
1244
  :expiration_date => "12/12"
1160
- }
1245
+ },
1161
1246
  )
1162
1247
  result.success?.should == true
1163
1248
  result.transaction.credit_card_details.masked_number.should == "401288******1881"
@@ -1169,7 +1254,7 @@ describe Braintree::Transaction do
1169
1254
  :credit_card => {
1170
1255
  :number => Braintree::Test::CreditCardNumbers::Visa,
1171
1256
  :expiration_date => "05/2010"
1172
- }
1257
+ },
1173
1258
  )
1174
1259
  result = Braintree::Transaction.create(
1175
1260
  :type => "sale",
@@ -1179,7 +1264,7 @@ describe Braintree::Transaction do
1179
1264
  :number => Braintree::Test::CreditCardNumbers::Visa,
1180
1265
  :expiration_date => "12/12",
1181
1266
  },
1182
- :options => { :store_in_vault => true }
1267
+ :options => {:store_in_vault => true},
1183
1268
  )
1184
1269
  result.success?.should == true
1185
1270
  result.transaction.credit_card_details.masked_number.should == "401288******1881"
@@ -1193,7 +1278,7 @@ describe Braintree::Transaction do
1193
1278
  :credit_card => {
1194
1279
  :number => Braintree::Test::CreditCardNumbers::Visa,
1195
1280
  :expiration_date => "05/2010"
1196
- }
1281
+ },
1197
1282
  )
1198
1283
 
1199
1284
  result = Braintree::Subscription.create(
@@ -1224,7 +1309,7 @@ describe Braintree::Transaction do
1224
1309
  :never_expires => true
1225
1310
  }
1226
1311
  ]
1227
- }
1312
+ },
1228
1313
  )
1229
1314
 
1230
1315
  result.success?.should be(true)
@@ -1265,15 +1350,15 @@ describe Braintree::Transaction do
1265
1350
  :expiration_date => "05/2009"
1266
1351
  },
1267
1352
  :descriptor => {
1268
- :name => '123*123456789012345678',
1269
- :phone => '3334445555',
1353
+ :name => "123*123456789012345678",
1354
+ :phone => "3334445555",
1270
1355
  :url => "ebay.com"
1271
- }
1356
+ },
1272
1357
  )
1273
1358
  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'
1359
+ result.transaction.descriptor.name.should == "123*123456789012345678"
1360
+ result.transaction.descriptor.phone.should == "3334445555"
1361
+ result.transaction.descriptor.url.should == "ebay.com"
1277
1362
  end
1278
1363
 
1279
1364
  it "has validation errors if format is invalid" do
@@ -1284,10 +1369,10 @@ describe Braintree::Transaction do
1284
1369
  :expiration_date => "05/2009"
1285
1370
  },
1286
1371
  :descriptor => {
1287
- :name => 'badcompanyname12*badproduct12',
1288
- :phone => '%bad4445555',
1289
- :url => '12345678901234'
1290
- }
1372
+ :name => "badcompanyname12*badproduct12",
1373
+ :phone => "%bad4445555",
1374
+ :url => "12345678901234"
1375
+ },
1291
1376
  )
1292
1377
  result.success?.should == false
1293
1378
  result.errors.for(:transaction).for(:descriptor).on(:name)[0].code.should == Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid
@@ -1304,14 +1389,14 @@ describe Braintree::Transaction do
1304
1389
  :number => Braintree::Test::CreditCardNumbers::Visa,
1305
1390
  :expiration_date => "05/2009"
1306
1391
  },
1307
- :tax_amount => '0.05',
1392
+ :tax_amount => "0.05",
1308
1393
  :tax_exempt => false,
1309
- :purchase_order_number => '12345678901234567'
1394
+ :purchase_order_number => "12345678901234567",
1310
1395
  )
1311
1396
  result.success?.should == true
1312
1397
  result.transaction.tax_amount.should == BigDecimal("0.05")
1313
1398
  result.transaction.tax_exempt.should == false
1314
- result.transaction.purchase_order_number.should == '12345678901234567'
1399
+ result.transaction.purchase_order_number.should == "12345678901234567"
1315
1400
  end
1316
1401
 
1317
1402
  it "accepts tax_amount as a BigDecimal" do
@@ -1321,8 +1406,8 @@ describe Braintree::Transaction do
1321
1406
  :number => Braintree::Test::CreditCardNumbers::Visa,
1322
1407
  :expiration_date => "05/2009"
1323
1408
  },
1324
- :tax_amount => BigDecimal('1.99'),
1325
- :tax_exempt => true
1409
+ :tax_amount => BigDecimal("1.99"),
1410
+ :tax_exempt => true,
1326
1411
  )
1327
1412
  result.success?.should == true
1328
1413
  result.transaction.tax_amount.should == BigDecimal("1.99")
@@ -1338,7 +1423,7 @@ describe Braintree::Transaction do
1338
1423
  :number => Braintree::Test::CreditCardNumbers::Visa,
1339
1424
  :expiration_date => "05/2009"
1340
1425
  },
1341
- :tax_amount => 'abcd'
1426
+ :tax_amount => "abcd",
1342
1427
  )
1343
1428
  result.success?.should == false
1344
1429
  result.errors.for(:transaction).on(:tax_amount)[0].code.should == Braintree::ErrorCodes::Transaction::TaxAmountFormatIsInvalid
@@ -1351,7 +1436,7 @@ describe Braintree::Transaction do
1351
1436
  :number => Braintree::Test::CreditCardNumbers::Visa,
1352
1437
  :expiration_date => "05/2009"
1353
1438
  },
1354
- :purchase_order_number => 'a' * 18
1439
+ :purchase_order_number => "a" * 18,
1355
1440
  )
1356
1441
  result.success?.should == false
1357
1442
  result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsTooLong
@@ -1364,7 +1449,7 @@ describe Braintree::Transaction do
1364
1449
  :number => Braintree::Test::CreditCardNumbers::Visa,
1365
1450
  :expiration_date => "05/2009"
1366
1451
  },
1367
- :purchase_order_number => "\303\237\303\245\342\210\202"
1452
+ :purchase_order_number => "\303\237\303\245\342\210\202",
1368
1453
  )
1369
1454
  result.success?.should == false
1370
1455
  result.errors.for(:transaction).on(:purchase_order_number)[0].code.should == Braintree::ErrorCodes::Transaction::PurchaseOrderNumberIsInvalid
@@ -1372,22 +1457,6 @@ describe Braintree::Transaction do
1372
1457
  end
1373
1458
  end
1374
1459
 
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
1460
  context "transaction_source" do
1392
1461
  it "marks a transactions as recurring_first" do
1393
1462
  result = Braintree::Transaction.create(
@@ -1397,7 +1466,7 @@ describe Braintree::Transaction do
1397
1466
  :number => Braintree::Test::CreditCardNumbers::Visa,
1398
1467
  :expiration_date => "12/12",
1399
1468
  },
1400
- :transaction_source => "recurring_first"
1469
+ :transaction_source => "recurring_first",
1401
1470
  )
1402
1471
  result.success?.should == true
1403
1472
  result.transaction.recurring.should == true
@@ -1411,7 +1480,7 @@ describe Braintree::Transaction do
1411
1480
  :number => Braintree::Test::CreditCardNumbers::Visa,
1412
1481
  :expiration_date => "12/12",
1413
1482
  },
1414
- :transaction_source => "recurring"
1483
+ :transaction_source => "recurring",
1415
1484
  )
1416
1485
  result.success?.should == true
1417
1486
  result.transaction.recurring.should == true
@@ -1425,7 +1494,7 @@ describe Braintree::Transaction do
1425
1494
  :number => Braintree::Test::CreditCardNumbers::Visa,
1426
1495
  :expiration_date => "12/12",
1427
1496
  },
1428
- :transaction_source => "merchant"
1497
+ :transaction_source => "merchant",
1429
1498
  )
1430
1499
  result.success?.should == true
1431
1500
  result.transaction.recurring.should == false
@@ -1439,7 +1508,7 @@ describe Braintree::Transaction do
1439
1508
  :number => Braintree::Test::CreditCardNumbers::Visa,
1440
1509
  :expiration_date => "12/12",
1441
1510
  },
1442
- :transaction_source => "moto"
1511
+ :transaction_source => "moto",
1443
1512
  )
1444
1513
  result.success?.should == true
1445
1514
  result.transaction.recurring.should == false
@@ -1453,7 +1522,7 @@ describe Braintree::Transaction do
1453
1522
  :number => Braintree::Test::CreditCardNumbers::Visa,
1454
1523
  :expiration_date => "12/12",
1455
1524
  },
1456
- :transaction_source => "invalid_value"
1525
+ :transaction_source => "invalid_value",
1457
1526
  )
1458
1527
  result.success?.should == false
1459
1528
  result.errors.for(:transaction).on(:transaction_source)[0].code.should == Braintree::ErrorCodes::Transaction::TransactionSourceIsInvalid
@@ -1473,7 +1542,7 @@ describe Braintree::Transaction do
1473
1542
  :number => Braintree::Test::CreditCardNumbers::Visa,
1474
1543
  :expiration_date => "12/12",
1475
1544
  },
1476
- :options => { :store_in_vault_on_success => true }
1545
+ :options => {:store_in_vault_on_success => true},
1477
1546
  )
1478
1547
  result.success?.should == true
1479
1548
  result.transaction.vault_customer.last_name.should == "Doe"
@@ -1492,7 +1561,7 @@ describe Braintree::Transaction do
1492
1561
  :number => Braintree::Test::CreditCardNumbers::Visa,
1493
1562
  :expiration_date => "12/12",
1494
1563
  },
1495
- :options => { :store_in_vault_on_success => true }
1564
+ :options => {:store_in_vault_on_success => true},
1496
1565
  )
1497
1566
  result.success?.should == false
1498
1567
  result.transaction.vault_customer.should be_nil
@@ -1512,7 +1581,7 @@ describe Braintree::Transaction do
1512
1581
  :number => Braintree::Test::CreditCardNumbers::Visa,
1513
1582
  :expiration_date => "12/12",
1514
1583
  },
1515
- :options => { :store_in_vault_on_success => false }
1584
+ :options => {:store_in_vault_on_success => false},
1516
1585
  )
1517
1586
  result.success?.should == true
1518
1587
  result.transaction.vault_customer.should be_nil
@@ -1530,7 +1599,7 @@ describe Braintree::Transaction do
1530
1599
  :number => Braintree::Test::CreditCardNumbers::Visa,
1531
1600
  :expiration_date => "12/12",
1532
1601
  },
1533
- :options => { :store_in_vault_on_success => false }
1602
+ :options => {:store_in_vault_on_success => false},
1534
1603
  )
1535
1604
  result.success?.should == false
1536
1605
  result.transaction.vault_customer.should be_nil
@@ -1549,7 +1618,7 @@ describe Braintree::Transaction do
1549
1618
  :number => Braintree::Test::CreditCardNumbers::Visa,
1550
1619
  :expiration_date => "12/12",
1551
1620
  },
1552
- :service_fee_amount => "1.00"
1621
+ :service_fee_amount => "1.00",
1553
1622
  )
1554
1623
  result.success?.should == true
1555
1624
  result.transaction.service_fee_amount.should == BigDecimal("1.00")
@@ -1564,7 +1633,7 @@ describe Braintree::Transaction do
1564
1633
  :number => Braintree::Test::CreditCardNumbers::Visa,
1565
1634
  :expiration_date => "12/12",
1566
1635
  },
1567
- :service_fee_amount => "1.00"
1636
+ :service_fee_amount => "1.00",
1568
1637
  )
1569
1638
  result.success?.should == false
1570
1639
  expected_error_code = Braintree::ErrorCodes::Transaction::ServiceFeeAmountNotAllowedOnMasterMerchantAccount
@@ -1579,7 +1648,7 @@ describe Braintree::Transaction do
1579
1648
  :credit_card => {
1580
1649
  :number => Braintree::Test::CreditCardNumbers::Visa,
1581
1650
  :expiration_date => "12/12",
1582
- }
1651
+ },
1583
1652
  )
1584
1653
  result.success?.should == false
1585
1654
  expected_error_code = Braintree::ErrorCodes::Transaction::SubMerchantAccountRequiresServiceFeeAmount
@@ -1589,7 +1658,7 @@ describe Braintree::Transaction do
1589
1658
  it "raises an error if service fee amount is negative" do
1590
1659
  result = Braintree::Transaction.create(
1591
1660
  :merchant_account_id => SpecHelper::NonDefaultSubMerchantAccountId,
1592
- :service_fee_amount => "-1.00"
1661
+ :service_fee_amount => "-1.00",
1593
1662
  )
1594
1663
  result.success?.should == false
1595
1664
  result.errors.for(:transaction).on(:service_fee_amount)[0].code.should == Braintree::ErrorCodes::Transaction::ServiceFeeAmountCannotBeNegative
@@ -1598,7 +1667,7 @@ describe Braintree::Transaction do
1598
1667
  it "raises an error if service fee amount is invalid" do
1599
1668
  result = Braintree::Transaction.create(
1600
1669
  :merchant_account_id => SpecHelper::NonDefaultSubMerchantAccountId,
1601
- :service_fee_amount => "invalid amount"
1670
+ :service_fee_amount => "invalid amount",
1602
1671
  )
1603
1672
  result.success?.should == false
1604
1673
  result.errors.for(:transaction).on(:service_fee_amount)[0].code.should == Braintree::ErrorCodes::Transaction::ServiceFeeAmountFormatIsInvalid
@@ -1616,7 +1685,7 @@ describe Braintree::Transaction do
1616
1685
  :expiration_date => "12/12",
1617
1686
  },
1618
1687
  :service_fee_amount => "10.00",
1619
- :options => {:hold_in_escrow => true}
1688
+ :options => {:hold_in_escrow => true},
1620
1689
  )
1621
1690
 
1622
1691
  result.success?.should == true
@@ -1633,7 +1702,7 @@ describe Braintree::Transaction do
1633
1702
  :expiration_date => "12/12",
1634
1703
  },
1635
1704
  :service_fee_amount => "1.00",
1636
- :options => {:hold_in_escrow => true}
1705
+ :options => {:hold_in_escrow => true},
1637
1706
  )
1638
1707
  result.success?.should == false
1639
1708
  expected_error_code = Braintree::ErrorCodes::Transaction::CannotHoldInEscrow
@@ -1646,7 +1715,7 @@ describe Braintree::Transaction do
1646
1715
  result = Braintree::Transaction.create(
1647
1716
  :type => "sale",
1648
1717
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1649
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode
1718
+ :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::VisaPaymentMethodCode,
1650
1719
  )
1651
1720
  result.success?.should == true
1652
1721
  result.transaction.credit_card_details.bin.should == "400934"
@@ -1663,7 +1732,7 @@ describe Braintree::Transaction do
1663
1732
  },
1664
1733
  :options => {
1665
1734
  :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
1666
- }
1735
+ },
1667
1736
  )
1668
1737
  result.success?.should == true
1669
1738
  result.transaction.credit_card_details.venmo_sdk?.should == false
@@ -1678,14 +1747,14 @@ describe Braintree::Transaction do
1678
1747
  :expiration_month => "11",
1679
1748
  :expiration_year => "2099",
1680
1749
  },
1681
- :share => true
1750
+ :share => true,
1682
1751
  )
1683
1752
  nonce.should_not be_nil
1684
1753
 
1685
1754
  result = Braintree::Transaction.create(
1686
1755
  :type => "sale",
1687
1756
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1688
- :payment_method_nonce => nonce
1757
+ :payment_method_nonce => nonce,
1689
1758
  )
1690
1759
  result.success?.should == true
1691
1760
  end
@@ -1700,14 +1769,14 @@ describe Braintree::Transaction do
1700
1769
  },
1701
1770
  :client_token_options => {
1702
1771
  :customer_id => customer.id,
1703
- }
1772
+ },
1704
1773
  )
1705
1774
  nonce.should_not be_nil
1706
1775
 
1707
1776
  result = Braintree::Transaction.create(
1708
1777
  :type => "sale",
1709
1778
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1710
- :payment_method_nonce => nonce
1779
+ :payment_method_nonce => nonce,
1711
1780
  )
1712
1781
  result.success?.should == true
1713
1782
  end
@@ -1720,14 +1789,14 @@ describe Braintree::Transaction do
1720
1789
  },
1721
1790
  :client_token_options => {
1722
1791
  :customer_id => customer.id,
1723
- }
1792
+ },
1724
1793
  )
1725
1794
  nonce.should_not be_nil
1726
1795
 
1727
1796
  result = Braintree::Transaction.create(
1728
1797
  :type => "sale",
1729
1798
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1730
- :payment_method_nonce => nonce
1799
+ :payment_method_nonce => nonce,
1731
1800
  )
1732
1801
  result.success?.should == true
1733
1802
  result.transaction.paypal_details.should_not be_nil
@@ -1739,14 +1808,14 @@ describe Braintree::Transaction do
1739
1808
  nonce = nonce_for_new_payment_method(
1740
1809
  :paypal_account => {
1741
1810
  :consent_code => "PAYPAL_CONSENT_CODE",
1742
- }
1811
+ },
1743
1812
  )
1744
1813
  nonce.should_not be_nil
1745
1814
 
1746
1815
  result = Braintree::Transaction.create(
1747
1816
  :type => "sale",
1748
1817
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1749
- :payment_method_nonce => nonce
1818
+ :payment_method_nonce => nonce,
1750
1819
  )
1751
1820
  result.success?.should == true
1752
1821
  result.transaction.paypal_details.should_not be_nil
@@ -1758,7 +1827,7 @@ describe Braintree::Transaction do
1758
1827
  result = Braintree::Transaction.create(
1759
1828
  :type => "sale",
1760
1829
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1761
- :payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa
1830
+ :payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa,
1762
1831
  )
1763
1832
  result.success?.should == true
1764
1833
  result.transaction.should_not be_nil
@@ -1788,7 +1857,7 @@ describe Braintree::Transaction do
1788
1857
  :type => "sale",
1789
1858
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1790
1859
  :payment_method_nonce => Braintree::Test::Nonce::ApplePayVisa,
1791
- :options => { :store_in_vault_on_success => true }
1860
+ :options => {:store_in_vault_on_success => true},
1792
1861
  )
1793
1862
  result.success?.should == true
1794
1863
  result.transaction.should_not be_nil
@@ -1804,106 +1873,83 @@ describe Braintree::Transaction do
1804
1873
  apple_pay_details.token.should_not be_nil
1805
1874
  end
1806
1875
 
1807
- it "can create a transaction with a fake android pay proxy card nonce" do
1876
+ it "can create a transaction with a fake google pay proxy card nonce" do
1808
1877
  customer = Braintree::Customer.create!
1809
1878
  result = Braintree::Transaction.create(
1810
1879
  :type => "sale",
1811
1880
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1812
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover
1881
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1813
1882
  )
1814
1883
  result.success?.should == true
1815
1884
  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
1885
+ google_pay_details = result.transaction.google_pay_details
1886
+ google_pay_details.should_not be_nil
1887
+ google_pay_details.bin.should_not be_nil
1888
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1889
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1890
+ google_pay_details.last_4.should == "1117"
1891
+ google_pay_details.virtual_card_last_4.should == "1117"
1892
+ google_pay_details.source_description.should == "Discover 1111"
1893
+ google_pay_details.expiration_month.to_i.should > 0
1894
+ google_pay_details.expiration_year.to_i.should > 0
1895
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1896
+ google_pay_details.image_url.should_not be_nil
1897
+ google_pay_details.is_network_tokenized?.should == false
1898
+ google_pay_details.token.should be_nil
1899
+ google_pay_details.prepaid.should_not be_nil
1900
+ google_pay_details.healthcare.should_not be_nil
1901
+ google_pay_details.debit.should_not be_nil
1902
+ google_pay_details.durbin_regulated.should_not be_nil
1903
+ google_pay_details.commercial.should_not be_nil
1904
+ google_pay_details.payroll.should_not be_nil
1905
+ google_pay_details.product_id.should_not be_nil
1906
+ end
1907
+
1908
+ it "can create a vaulted transaction with a fake google pay proxy card nonce" do
1840
1909
  customer = Braintree::Customer.create!
1841
1910
  result = Braintree::Transaction.create(
1842
1911
  :type => "sale",
1843
1912
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1844
- :payment_method_nonce => Braintree::Test::Nonce::AndroidPayDiscover,
1845
- :options => { :store_in_vault_on_success => true }
1913
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayDiscover,
1914
+ :options => {:store_in_vault_on_success => true},
1846
1915
  )
1847
1916
  result.success?.should == true
1848
1917
  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
1918
+ google_pay_details = result.transaction.google_pay_details
1919
+ google_pay_details.should_not be_nil
1920
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::Discover
1921
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::Discover
1922
+ google_pay_details.last_4.should == "1117"
1923
+ google_pay_details.virtual_card_last_4.should == "1117"
1924
+ google_pay_details.source_description.should == "Discover 1111"
1925
+ google_pay_details.expiration_month.to_i.should > 0
1926
+ google_pay_details.expiration_year.to_i.should > 0
1927
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1928
+ google_pay_details.image_url.should_not be_nil
1929
+ google_pay_details.is_network_tokenized?.should == false
1930
+ google_pay_details.token.should_not be_nil
1931
+ end
1932
+
1933
+ it "can create a transaction with a fake google pay network token nonce" do
1865
1934
  customer = Braintree::Customer.create!
1866
1935
  result = Braintree::Transaction.create(
1867
1936
  :type => "sale",
1868
1937
  :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}
1938
+ :payment_method_nonce => Braintree::Test::Nonce::GooglePayMasterCard,
1893
1939
  )
1894
1940
  result.success?.should == true
1895
1941
  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/
1942
+ google_pay_details = result.transaction.google_pay_details
1943
+ google_pay_details.should_not be_nil
1944
+ google_pay_details.card_type.should == Braintree::CreditCard::CardType::MasterCard
1945
+ google_pay_details.virtual_card_type.should == Braintree::CreditCard::CardType::MasterCard
1946
+ google_pay_details.last_4.should == "4444"
1947
+ google_pay_details.virtual_card_last_4.should == "4444"
1948
+ google_pay_details.source_description.should == "MasterCard 4444"
1949
+ google_pay_details.expiration_month.to_i.should > 0
1950
+ google_pay_details.expiration_year.to_i.should > 0
1951
+ google_pay_details.google_transaction_id.should == "google_transaction_id"
1952
+ google_pay_details.is_network_tokenized?.should == true
1907
1953
  end
1908
1954
 
1909
1955
  it "can create a transaction with a fake venmo account nonce" do
@@ -1912,7 +1958,7 @@ describe Braintree::Transaction do
1912
1958
  :merchant_account_id => SpecHelper::FakeVenmoAccountMerchantAccountId,
1913
1959
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1914
1960
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
1915
- :options => {:store_in_vault => true}
1961
+ :options => {:store_in_vault => true},
1916
1962
  )
1917
1963
  result.should be_success
1918
1964
 
@@ -1921,7 +1967,7 @@ describe Braintree::Transaction do
1921
1967
  venmo_account_details.should be_a(Braintree::Transaction::VenmoAccountDetails)
1922
1968
  venmo_account_details.token.should respond_to(:to_str)
1923
1969
  venmo_account_details.username.should == "venmojoe"
1924
- venmo_account_details.venmo_user_id.should == "Venmo-Joe-1"
1970
+ venmo_account_details.venmo_user_id.should == "1234567891234567891"
1925
1971
  venmo_account_details.image_url.should include(".png")
1926
1972
  venmo_account_details.source_description.should == "Venmo Account: venmojoe"
1927
1973
  end
@@ -1932,7 +1978,7 @@ describe Braintree::Transaction do
1932
1978
  :merchant_account_id => SpecHelper::FakeVenmoAccountMerchantAccountId,
1933
1979
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1934
1980
  :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
1935
- :options => {:store_in_vault => true, :venmo => {:profile_id => "integration_venmo_merchant_public_id" }}
1981
+ :options => {:store_in_vault => true, :venmo => {:profile_id => "integration_venmo_merchant_public_id"}},
1936
1982
  )
1937
1983
  result.should be_success
1938
1984
  end
@@ -1942,7 +1988,7 @@ describe Braintree::Transaction do
1942
1988
  result = Braintree::Transaction.create(
1943
1989
  :type => "sale",
1944
1990
  :amount => Braintree::Test::TransactionAmounts::Authorize,
1945
- :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable
1991
+ :payment_method_nonce => Braintree::Test::Nonce::AbstractTransactable,
1946
1992
  )
1947
1993
  result.success?.should == true
1948
1994
  result.transaction.should_not be_nil
@@ -1957,7 +2003,7 @@ describe Braintree::Transaction do
1957
2003
  :paypal_account => {
1958
2004
  :payer_id => "PAYER-1234",
1959
2005
  :payment_id => "PAY-5678",
1960
- }
2006
+ },
1961
2007
  )
1962
2008
 
1963
2009
  result.success?.should == true
@@ -1971,7 +2017,7 @@ describe Braintree::Transaction do
1971
2017
  nonce = nonce_for_new_payment_method(
1972
2018
  :paypal_account => {
1973
2019
  :consent_code => "PAYPAL_CONSENT_CODE",
1974
- }
2020
+ },
1975
2021
  )
1976
2022
  nonce.should_not be_nil
1977
2023
 
@@ -1981,7 +2027,7 @@ describe Braintree::Transaction do
1981
2027
  :payment_method_nonce => nonce,
1982
2028
  :paypal_account => {
1983
2029
  :payee_id => "fake-payee-id"
1984
- }
2030
+ },
1985
2031
  )
1986
2032
 
1987
2033
  result.success?.should == true
@@ -1995,7 +2041,7 @@ describe Braintree::Transaction do
1995
2041
  nonce = nonce_for_new_payment_method(
1996
2042
  :paypal_account => {
1997
2043
  :consent_code => "PAYPAL_CONSENT_CODE",
1998
- }
2044
+ },
1999
2045
  )
2000
2046
  nonce.should_not be_nil
2001
2047
 
@@ -2006,7 +2052,7 @@ describe Braintree::Transaction do
2006
2052
  :paypal_account => {},
2007
2053
  :options => {
2008
2054
  :payee_id => "fake-payee-id"
2009
- }
2055
+ },
2010
2056
  )
2011
2057
 
2012
2058
  result.success?.should == true
@@ -2020,7 +2066,7 @@ describe Braintree::Transaction do
2020
2066
  nonce = nonce_for_new_payment_method(
2021
2067
  :paypal_account => {
2022
2068
  :consent_code => "PAYPAL_CONSENT_CODE",
2023
- }
2069
+ },
2024
2070
  )
2025
2071
  nonce.should_not be_nil
2026
2072
 
@@ -2032,7 +2078,7 @@ describe Braintree::Transaction do
2032
2078
  :paypal => {
2033
2079
  :payee_id => "fake-payee-id"
2034
2080
  }
2035
- }
2081
+ },
2036
2082
  )
2037
2083
 
2038
2084
  result.success?.should == true
@@ -2046,7 +2092,7 @@ describe Braintree::Transaction do
2046
2092
  nonce = nonce_for_new_payment_method(
2047
2093
  :paypal_account => {
2048
2094
  :consent_code => "PAYPAL_CONSENT_CODE",
2049
- }
2095
+ },
2050
2096
  )
2051
2097
  nonce.should_not be_nil
2052
2098
 
@@ -2056,7 +2102,7 @@ describe Braintree::Transaction do
2056
2102
  :payment_method_nonce => nonce,
2057
2103
  :paypal_account => {
2058
2104
  :payee_email => "bt_seller_us@paypal.com"
2059
- }
2105
+ },
2060
2106
  )
2061
2107
 
2062
2108
  result.success?.should == true
@@ -2070,7 +2116,7 @@ describe Braintree::Transaction do
2070
2116
  nonce = nonce_for_new_payment_method(
2071
2117
  :paypal_account => {
2072
2118
  :consent_code => "PAYPAL_CONSENT_CODE",
2073
- }
2119
+ },
2074
2120
  )
2075
2121
  nonce.should_not be_nil
2076
2122
 
@@ -2081,7 +2127,7 @@ describe Braintree::Transaction do
2081
2127
  :paypal_account => {},
2082
2128
  :options => {
2083
2129
  :payee_email => "bt_seller_us@paypal.com"
2084
- }
2130
+ },
2085
2131
  )
2086
2132
 
2087
2133
  result.success?.should == true
@@ -2095,7 +2141,7 @@ describe Braintree::Transaction do
2095
2141
  nonce = nonce_for_new_payment_method(
2096
2142
  :paypal_account => {
2097
2143
  :consent_code => "PAYPAL_CONSENT_CODE",
2098
- }
2144
+ },
2099
2145
  )
2100
2146
  nonce.should_not be_nil
2101
2147
 
@@ -2107,7 +2153,7 @@ describe Braintree::Transaction do
2107
2153
  :paypal => {
2108
2154
  :payee_email => "bt_seller_us@paypal.com"
2109
2155
  }
2110
- }
2156
+ },
2111
2157
  )
2112
2158
 
2113
2159
  result.success?.should == true
@@ -2121,7 +2167,7 @@ describe Braintree::Transaction do
2121
2167
  nonce = nonce_for_new_payment_method(
2122
2168
  :paypal_account => {
2123
2169
  :consent_code => "PAYPAL_CONSENT_CODE",
2124
- }
2170
+ },
2125
2171
  )
2126
2172
  nonce.should_not be_nil
2127
2173
 
@@ -2133,7 +2179,7 @@ describe Braintree::Transaction do
2133
2179
  :paypal => {
2134
2180
  :custom_field => "Additional info"
2135
2181
  }
2136
- }
2182
+ },
2137
2183
  )
2138
2184
 
2139
2185
  result.success?.should == true
@@ -2147,7 +2193,7 @@ describe Braintree::Transaction do
2147
2193
  nonce = nonce_for_new_payment_method(
2148
2194
  :paypal_account => {
2149
2195
  :consent_code => "PAYPAL_CONSENT_CODE",
2150
- }
2196
+ },
2151
2197
  )
2152
2198
  nonce.should_not be_nil
2153
2199
 
@@ -2159,7 +2205,7 @@ describe Braintree::Transaction do
2159
2205
  :paypal => {
2160
2206
  :description => "A great product"
2161
2207
  }
2162
- }
2208
+ },
2163
2209
  )
2164
2210
 
2165
2211
  result.success?.should == true
@@ -2173,7 +2219,7 @@ describe Braintree::Transaction do
2173
2219
  nonce = nonce_for_new_payment_method(
2174
2220
  :paypal_account => {
2175
2221
  :consent_code => "PAYPAL_CONSENT_CODE",
2176
- }
2222
+ },
2177
2223
  )
2178
2224
  nonce.should_not be_nil
2179
2225
 
@@ -2188,7 +2234,7 @@ describe Braintree::Transaction do
2188
2234
  :key2 => "value2",
2189
2235
  }
2190
2236
  }
2191
- }
2237
+ },
2192
2238
  )
2193
2239
 
2194
2240
  # note - supplementary data is not returned in response
@@ -2202,7 +2248,7 @@ describe Braintree::Transaction do
2202
2248
  SpecHelper::ThreeDSecureMerchantAccountId,
2203
2249
  :number => Braintree::Test::CreditCardNumbers::Visa,
2204
2250
  :expiration_month => "12",
2205
- :expiration_year => "2012"
2251
+ :expiration_year => "2012",
2206
2252
  )
2207
2253
 
2208
2254
  result = Braintree::Transaction.create(
@@ -2213,7 +2259,7 @@ describe Braintree::Transaction do
2213
2259
  :number => Braintree::Test::CreditCardNumbers::Visa,
2214
2260
  :expiration_date => "12/12",
2215
2261
  },
2216
- :three_d_secure_token => three_d_secure_token
2262
+ :three_d_secure_token => three_d_secure_token,
2217
2263
  )
2218
2264
 
2219
2265
  result.success?.should == true
@@ -2225,7 +2271,7 @@ describe Braintree::Transaction do
2225
2271
  :number => "4111111111111111",
2226
2272
  :expiration_month => "11",
2227
2273
  :expiration_year => "2099",
2228
- }
2274
+ },
2229
2275
  )
2230
2276
  nonce.should_not be_nil
2231
2277
  result = Braintree::Transaction.create(
@@ -2237,7 +2283,7 @@ describe Braintree::Transaction do
2237
2283
  :three_d_secure => {
2238
2284
  :required => true,
2239
2285
  }
2240
- }
2286
+ },
2241
2287
  )
2242
2288
 
2243
2289
  result.success?.should == false
@@ -2253,7 +2299,7 @@ describe Braintree::Transaction do
2253
2299
  :credit_card => {
2254
2300
  :number => Braintree::Test::CreditCardNumbers::Visa,
2255
2301
  :expiration_date => "12/12",
2256
- }
2302
+ },
2257
2303
  )
2258
2304
  result.success?.should == true
2259
2305
  end
@@ -2264,7 +2310,7 @@ describe Braintree::Transaction do
2264
2310
  SpecHelper::ThreeDSecureMerchantAccountId,
2265
2311
  :number => Braintree::Test::CreditCardNumbers::Visa,
2266
2312
  :expiration_month => "12",
2267
- :expiration_year => "2022"
2313
+ :expiration_year => "2022",
2268
2314
  )
2269
2315
 
2270
2316
  result = Braintree::Transaction.create(
@@ -2275,7 +2321,7 @@ describe Braintree::Transaction do
2275
2321
  :number => Braintree::Test::CreditCardNumbers::Visa,
2276
2322
  :expiration_date => "12/22",
2277
2323
  },
2278
- :three_d_secure_authentication_id => three_d_secure_authentication_id
2324
+ :three_d_secure_authentication_id => three_d_secure_authentication_id,
2279
2325
  )
2280
2326
 
2281
2327
  result.success?.should == true
@@ -2289,7 +2335,7 @@ describe Braintree::Transaction do
2289
2335
  :number => Braintree::Test::CreditCardNumbers::Visa,
2290
2336
  :expiration_date => "12/12",
2291
2337
  },
2292
- :three_d_secure_authentication_id => nil
2338
+ :three_d_secure_authentication_id => nil,
2293
2339
  )
2294
2340
  result.success?.should == false
2295
2341
  result.errors.for(:transaction).on(:three_d_secure_authentication_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureAuthenticationIdIsInvalid
@@ -2299,7 +2345,7 @@ describe Braintree::Transaction do
2299
2345
  SpecHelper::ThreeDSecureMerchantAccountId,
2300
2346
  :number => Braintree::Test::CreditCardNumbers::Visa,
2301
2347
  :expiration_month => "12",
2302
- :expiration_year => "2012"
2348
+ :expiration_year => "2012",
2303
2349
  )
2304
2350
 
2305
2351
  result = Braintree::Transaction.create(
@@ -2309,7 +2355,7 @@ describe Braintree::Transaction do
2309
2355
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
2310
2356
  :expiration_date => "12/12",
2311
2357
  },
2312
- :three_d_secure_authentication_id => three_d_secure_authentication_id
2358
+ :three_d_secure_authentication_id => three_d_secure_authentication_id,
2313
2359
  )
2314
2360
  result.success?.should == false
2315
2361
  result.errors.for(:transaction).on(:three_d_secure_authentication_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureTransactionPaymentMethodDoesntMatchThreeDSecureAuthenticationPaymentMethod
@@ -2319,7 +2365,7 @@ describe Braintree::Transaction do
2319
2365
  SpecHelper::ThreeDSecureMerchantAccountId,
2320
2366
  :number => Braintree::Test::CreditCardNumbers::Visa,
2321
2367
  :expiration_month => "12",
2322
- :expiration_year => "2012"
2368
+ :expiration_year => "2012",
2323
2369
  )
2324
2370
 
2325
2371
  result = Braintree::Transaction.create(
@@ -2330,7 +2376,7 @@ describe Braintree::Transaction do
2330
2376
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
2331
2377
  :expiration_date => "12/12",
2332
2378
  },
2333
- :three_d_secure_authentication_id => three_d_secure_authentication_id
2379
+ :three_d_secure_authentication_id => three_d_secure_authentication_id,
2334
2380
  )
2335
2381
  result.success?.should == false
2336
2382
  result.errors.for(:transaction).on(:three_d_secure_authentication_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureTransactionPaymentMethodDoesntMatchThreeDSecureAuthenticationPaymentMethod
@@ -2340,7 +2386,7 @@ describe Braintree::Transaction do
2340
2386
  SpecHelper::ThreeDSecureMerchantAccountId,
2341
2387
  :number => Braintree::Test::CreditCardNumbers::Visa,
2342
2388
  :expiration_month => "12",
2343
- :expiration_year => "2012"
2389
+ :expiration_year => "2012",
2344
2390
  )
2345
2391
  result = Braintree::Transaction.create(
2346
2392
  :merchant_account_id => SpecHelper::ThreeDSecureMerchantAccountId,
@@ -2360,7 +2406,7 @@ describe Braintree::Transaction do
2360
2406
  :directory_response => "Y",
2361
2407
  :cavv_algorithm => "2",
2362
2408
  :ds_transaction_id => "some_ds_id",
2363
- }
2409
+ },
2364
2410
  )
2365
2411
  result.success?.should == false
2366
2412
  result.errors.for(:transaction).on(:three_d_secure_authentication_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureAuthenticationIdWithThreeDSecurePassThruIsInvalid
@@ -2373,7 +2419,7 @@ describe Braintree::Transaction do
2373
2419
  SpecHelper::ThreeDSecureMerchantAccountId,
2374
2420
  :number => Braintree::Test::CreditCardNumbers::Visa,
2375
2421
  :expiration_month => "12",
2376
- :expiration_year => "2012"
2422
+ :expiration_year => "2012",
2377
2423
  )
2378
2424
 
2379
2425
  result = Braintree::Transaction.create(
@@ -2384,7 +2430,7 @@ describe Braintree::Transaction do
2384
2430
  :number => Braintree::Test::CreditCardNumbers::Visa,
2385
2431
  :expiration_date => "12/12",
2386
2432
  },
2387
- :three_d_secure_token => three_d_secure_token
2433
+ :three_d_secure_token => three_d_secure_token,
2388
2434
  )
2389
2435
 
2390
2436
  result.success?.should == true
@@ -2399,7 +2445,7 @@ describe Braintree::Transaction do
2399
2445
  :number => Braintree::Test::CreditCardNumbers::Visa,
2400
2446
  :expiration_date => "12/12",
2401
2447
  },
2402
- :three_d_secure_token => nil
2448
+ :three_d_secure_token => nil,
2403
2449
  )
2404
2450
  result.success?.should == false
2405
2451
  result.errors.for(:transaction).on(:three_d_secure_token)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureTokenIsInvalid
@@ -2410,7 +2456,7 @@ describe Braintree::Transaction do
2410
2456
  SpecHelper::ThreeDSecureMerchantAccountId,
2411
2457
  :number => Braintree::Test::CreditCardNumbers::Visa,
2412
2458
  :expiration_month => "12",
2413
- :expiration_year => "2012"
2459
+ :expiration_year => "2012",
2414
2460
  )
2415
2461
 
2416
2462
  result = Braintree::Transaction.create(
@@ -2421,7 +2467,7 @@ describe Braintree::Transaction do
2421
2467
  :number => Braintree::Test::CreditCardNumbers::MasterCard,
2422
2468
  :expiration_date => "12/12",
2423
2469
  },
2424
- :three_d_secure_token => three_d_secure_token
2470
+ :three_d_secure_token => three_d_secure_token,
2425
2471
  )
2426
2472
  result.success?.should == false
2427
2473
  result.errors.for(:transaction).on(:three_d_secure_token)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureTransactionDataDoesntMatchVerify
@@ -2445,7 +2491,7 @@ describe Braintree::Transaction do
2445
2491
  :directory_response => "Y",
2446
2492
  :cavv_algorithm => "2",
2447
2493
  :ds_transaction_id => "some_ds_id",
2448
- }
2494
+ },
2449
2495
  )
2450
2496
 
2451
2497
  result.success?.should == true
@@ -2470,7 +2516,7 @@ describe Braintree::Transaction do
2470
2516
  :directory_response => "Y",
2471
2517
  :cavv_algorithm => "2",
2472
2518
  :ds_transaction_id => "some_ds_id",
2473
- }
2519
+ },
2474
2520
  )
2475
2521
  result.success?.should == false
2476
2522
  result.errors.for(:transaction).on(:merchant_account_id)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureMerchantAccountDoesNotSupportCardType
@@ -2488,7 +2534,7 @@ describe Braintree::Transaction do
2488
2534
  :eci_flag => "",
2489
2535
  :cavv => "some_cavv",
2490
2536
  :xid => "some_xid",
2491
- }
2537
+ },
2492
2538
  )
2493
2539
  result.success?.should == false
2494
2540
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:eci_flag)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureEciFlagIsRequired
@@ -2511,7 +2557,7 @@ describe Braintree::Transaction do
2511
2557
  :directory_response => "Y",
2512
2558
  :cavv_algorithm => "2",
2513
2559
  :ds_transaction_id => "some_ds_id",
2514
- }
2560
+ },
2515
2561
  )
2516
2562
  result.success?.should == false
2517
2563
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:cavv)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureCavvIsRequired
@@ -2534,7 +2580,7 @@ describe Braintree::Transaction do
2534
2580
  :directory_response => "Y",
2535
2581
  :cavv_algorithm => "2",
2536
2582
  :ds_transaction_id => "some_ds_id",
2537
- }
2583
+ },
2538
2584
  )
2539
2585
  result.success?.should == false
2540
2586
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:eci_flag)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureEciFlagIsInvalid
@@ -2557,7 +2603,7 @@ describe Braintree::Transaction do
2557
2603
  :directory_response => "Y",
2558
2604
  :cavv_algorithm => "2",
2559
2605
  :ds_transaction_id => "some_ds_id",
2560
- }
2606
+ },
2561
2607
  )
2562
2608
  result.success?.should == false
2563
2609
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:three_d_secure_version)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureThreeDSecureVersionIsInvalid
@@ -2581,7 +2627,7 @@ describe Braintree::Transaction do
2581
2627
  :directory_response => "Y",
2582
2628
  :cavv_algorithm => "2",
2583
2629
  :ds_transaction_id => "some_ds_id",
2584
- }
2630
+ },
2585
2631
  )
2586
2632
  result.success?.should == false
2587
2633
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:authentication_response)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureAuthenticationResponseIsInvalid
@@ -2605,7 +2651,7 @@ describe Braintree::Transaction do
2605
2651
  :directory_response => "abc",
2606
2652
  :cavv_algorithm => "2",
2607
2653
  :ds_transaction_id => "some_ds_id",
2608
- }
2654
+ },
2609
2655
  )
2610
2656
  result.success?.should == false
2611
2657
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:directory_response)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureDirectoryResponseIsInvalid
@@ -2629,7 +2675,7 @@ describe Braintree::Transaction do
2629
2675
  :directory_response => "Y",
2630
2676
  :cavv_algorithm => "bad_alg",
2631
2677
  :ds_transaction_id => "some_ds_id",
2632
- }
2678
+ },
2633
2679
  )
2634
2680
  result.success?.should == false
2635
2681
  result.errors.for(:transaction).for(:three_d_secure_pass_thru).on(:cavv_algorithm)[0].code.should == Braintree::ErrorCodes::Transaction::ThreeDSecureCavvAlgorithmIsInvalid
@@ -2641,12 +2687,12 @@ describe Braintree::Transaction do
2641
2687
  it "can create a transaction" do
2642
2688
  payment_method_result = Braintree::PaymentMethod.create(
2643
2689
  :customer_id => Braintree::Customer.create.customer.id,
2644
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
2690
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
2645
2691
  )
2646
2692
  result = Braintree::Transaction.create(
2647
2693
  :type => "sale",
2648
2694
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2649
- :payment_method_token => payment_method_result.payment_method.token
2695
+ :payment_method_token => payment_method_result.payment_method.token,
2650
2696
  )
2651
2697
 
2652
2698
  result.should be_success
@@ -2661,13 +2707,13 @@ describe Braintree::Transaction do
2661
2707
  payment_method_token = rand(36**3).to_s(36)
2662
2708
  nonce = nonce_for_paypal_account(
2663
2709
  :consent_code => "PAYPAL_CONSENT_CODE",
2664
- :token => payment_method_token
2710
+ :token => payment_method_token,
2665
2711
  )
2666
2712
 
2667
2713
  result = Braintree::Transaction.create(
2668
2714
  :type => "sale",
2669
2715
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2670
- :payment_method_nonce => nonce
2716
+ :payment_method_nonce => nonce,
2671
2717
  )
2672
2718
 
2673
2719
  result.should be_success
@@ -2683,14 +2729,14 @@ describe Braintree::Transaction do
2683
2729
  payment_method_token = rand(36**3).to_s(36)
2684
2730
  nonce = nonce_for_paypal_account(
2685
2731
  :consent_code => "PAYPAL_CONSENT_CODE",
2686
- :token => payment_method_token
2732
+ :token => payment_method_token,
2687
2733
  )
2688
2734
 
2689
2735
  result = Braintree::Transaction.create(
2690
2736
  :type => "sale",
2691
2737
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2692
2738
  :payment_method_nonce => nonce,
2693
- :options => {:store_in_vault => true}
2739
+ :options => {:store_in_vault => true},
2694
2740
  )
2695
2741
 
2696
2742
  result.success?.should == true
@@ -2703,12 +2749,28 @@ describe Braintree::Transaction do
2703
2749
  end
2704
2750
  end
2705
2751
 
2752
+ context "billing agreement" do
2753
+ it "can create a paypal billing agreement" do
2754
+ result = Braintree::Transaction.create(
2755
+ :type => "sale",
2756
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
2757
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalBillingAgreement,
2758
+ :options => {:store_in_vault => true},
2759
+ )
2760
+
2761
+ result.should be_success
2762
+ result.transaction.paypal_details.should_not be_nil
2763
+ result.transaction.paypal_details.debug_id.should_not be_nil
2764
+ result.transaction.paypal_details.billing_agreement_id.should_not be_nil
2765
+ end
2766
+ end
2767
+
2706
2768
  context "local payments" do
2707
2769
  it "can create a local payment transaction with a nonce" do
2708
2770
  result = Braintree::Transaction.create(
2709
2771
  :type => "sale",
2710
2772
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2711
- :payment_method_nonce => Braintree::Test::Nonce::LocalPayment
2773
+ :payment_method_nonce => Braintree::Test::Nonce::LocalPayment,
2712
2774
  )
2713
2775
 
2714
2776
  result.should be_success
@@ -2726,7 +2788,7 @@ describe Braintree::Transaction do
2726
2788
  result = Braintree::Transaction.create(
2727
2789
  :type => "sale",
2728
2790
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2729
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
2791
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2730
2792
  )
2731
2793
 
2732
2794
  result.should be_success
@@ -2738,14 +2800,14 @@ describe Braintree::Transaction do
2738
2800
  payment_method_token = rand(36**3).to_s(36)
2739
2801
  nonce = nonce_for_paypal_account(
2740
2802
  :access_token => "PAYPAL_ACCESS_TOKEN",
2741
- :token => payment_method_token
2803
+ :token => payment_method_token,
2742
2804
  )
2743
2805
 
2744
2806
  result = Braintree::Transaction.create(
2745
2807
  :type => "sale",
2746
2808
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2747
2809
  :payment_method_nonce => nonce,
2748
- :options => {:store_in_vault => true}
2810
+ :options => {:store_in_vault => true},
2749
2811
  )
2750
2812
 
2751
2813
  result.success?.should == true
@@ -2765,7 +2827,7 @@ describe Braintree::Transaction do
2765
2827
  :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2766
2828
  :options => {
2767
2829
  :submit_for_settlement => true
2768
- }
2830
+ },
2769
2831
  )
2770
2832
  result.success?.should == true
2771
2833
  result.transaction.status.should == Braintree::Transaction::Status::Settling
@@ -2776,7 +2838,7 @@ describe Braintree::Transaction do
2776
2838
  it "successfully voids a paypal transaction that's been authorized" do
2777
2839
  sale_transaction = Braintree::Transaction.sale!(
2778
2840
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2779
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
2841
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2780
2842
  )
2781
2843
 
2782
2844
  void_transaction = Braintree::Transaction.void!(sale_transaction.id)
@@ -2787,7 +2849,7 @@ describe Braintree::Transaction do
2787
2849
  it "fails to void a paypal transaction that's been declined" do
2788
2850
  sale_transaction = Braintree::Transaction.sale(
2789
2851
  :amount => Braintree::Test::TransactionAmounts::Decline,
2790
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
2852
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2791
2853
  ).transaction
2792
2854
 
2793
2855
  expect do
@@ -2857,6 +2919,19 @@ describe Braintree::Transaction do
2857
2919
  result.transaction.amount.should == transaction.amount/2
2858
2920
  end
2859
2921
 
2922
+ it "allows merchant_account_id to be passed for the refund" do
2923
+ transaction = create_transaction_to_refund
2924
+
2925
+ result = Braintree::Transaction.refund(
2926
+ transaction.id,
2927
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
2928
+ )
2929
+
2930
+ result.success?.should == true
2931
+ result.transaction.type.should == "credit"
2932
+ result.transaction.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
2933
+ end
2934
+
2860
2935
  it "does not allow arbitrary options to be passed" do
2861
2936
  transaction = create_paypal_transaction_for_refund
2862
2937
 
@@ -2865,14 +2940,6 @@ describe Braintree::Transaction do
2865
2940
  }.to raise_error(ArgumentError)
2866
2941
  end
2867
2942
 
2868
- it "assigns the refund_id on the original transaction" do
2869
- transaction = create_paypal_transaction_for_refund
2870
- refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
2871
- transaction = Braintree::Transaction.find(transaction.id)
2872
-
2873
- transaction.refund_id.should == refund_transaction.id
2874
- end
2875
-
2876
2943
  it "assigns the refunded_transaction_id to the original transaction" do
2877
2944
  transaction = create_paypal_transaction_for_refund
2878
2945
  refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
@@ -2883,7 +2950,7 @@ describe Braintree::Transaction do
2883
2950
  it "returns an error result if unsettled" do
2884
2951
  transaction = Braintree::Transaction.sale!(
2885
2952
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2886
- :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment
2953
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
2887
2954
  )
2888
2955
  result = Braintree::Transaction.refund(transaction.id)
2889
2956
  result.success?.should == false
@@ -2896,13 +2963,19 @@ describe Braintree::Transaction do
2896
2963
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
2897
2964
  :options => {
2898
2965
  :submit_for_settlement => true
2899
- }
2966
+ },
2900
2967
  )
2901
2968
  config = Braintree::Configuration.instantiate
2902
2969
  response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
2903
2970
  result = Braintree::Transaction.refund(transaction.id, :amount => "2046.00")
2904
2971
  result.success?.should == false
2905
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::RefundAuthSoftDeclined
2972
+ result.transaction.id.should =~ /^\w{6,}$/
2973
+ result.transaction.type.should == "credit"
2974
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
2975
+ result.transaction.processor_response_code.should == "2046"
2976
+ result.transaction.processor_response_text.should == "Declined"
2977
+ result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::SoftDeclined
2978
+ result.transaction.additional_processor_response.should == "2046 : Declined"
2906
2979
  end
2907
2980
 
2908
2981
  it "handles hard declined refund authorizations" do
@@ -2911,13 +2984,19 @@ describe Braintree::Transaction do
2911
2984
  :payment_method_nonce => Braintree::Test::Nonce::Transactable,
2912
2985
  :options => {
2913
2986
  :submit_for_settlement => true
2914
- }
2987
+ },
2915
2988
  )
2916
2989
  config = Braintree::Configuration.instantiate
2917
2990
  response = config.http.put("#{config.base_merchant_path}/transactions/#{transaction.id}/settle")
2918
2991
  result = Braintree::Transaction.refund(transaction.id, :amount => "2009.00")
2919
2992
  result.success?.should == false
2920
- result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::RefundAuthHardDeclined
2993
+ result.transaction.id.should =~ /^\w{6,}$/
2994
+ result.transaction.type.should == "credit"
2995
+ result.transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
2996
+ result.transaction.processor_response_code.should == "2009"
2997
+ result.transaction.processor_response_text.should == "No Such Issuer"
2998
+ result.transaction.processor_response_type.should == Braintree::ProcessorResponseTypes::HardDeclined
2999
+ result.transaction.additional_processor_response.should == "2009 : No Such Issuer"
2921
3000
  end
2922
3001
  end
2923
3002
 
@@ -2925,13 +3004,13 @@ describe Braintree::Transaction do
2925
3004
  it "handles bad unvalidated nonces" do
2926
3005
  nonce = nonce_for_paypal_account(
2927
3006
  :access_token => "PAYPAL_ACCESS_TOKEN",
2928
- :consent_code => "PAYPAL_CONSENT_CODE"
3007
+ :consent_code => "PAYPAL_CONSENT_CODE",
2929
3008
  )
2930
3009
 
2931
3010
  result = Braintree::Transaction.create(
2932
3011
  :type => "sale",
2933
3012
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2934
- :payment_method_nonce => nonce
3013
+ :payment_method_nonce => nonce,
2935
3014
  )
2936
3015
 
2937
3016
  result.should_not be_success
@@ -2942,7 +3021,7 @@ describe Braintree::Transaction do
2942
3021
  result = Braintree::Transaction.create(
2943
3022
  :type => "sale",
2944
3023
  :amount => Braintree::Test::TransactionAmounts::Authorize,
2945
- :payment_method_nonce => "NON_EXISTENT_NONCE"
3024
+ :payment_method_nonce => "NON_EXISTENT_NONCE",
2946
3025
  )
2947
3026
 
2948
3027
  result.should_not be_success
@@ -4070,7 +4149,7 @@ describe Braintree::Transaction do
4070
4149
  :unit_of_measure => "gallon",
4071
4150
  :total_amount => "10.1",
4072
4151
  },
4073
- ['Name #2'],
4152
+ ["Name #2"],
4074
4153
  {
4075
4154
  :quantity => "2.02",
4076
4155
  :name => "Name #3",
@@ -4256,7 +4335,7 @@ describe Braintree::Transaction do
4256
4335
  customer = Braintree::Customer.create!
4257
4336
  result = Braintree::PaymentMethod.create(
4258
4337
  :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
4259
- :customer_id => customer.id
4338
+ :customer_id => customer.id,
4260
4339
  )
4261
4340
  payment_method_token = result.payment_method.token
4262
4341
 
@@ -4289,7 +4368,7 @@ describe Braintree::Transaction do
4289
4368
  result.errors.for(:transaction).for(:external_vault).on(:status)[0].code.should == Braintree::ErrorCodes::Transaction::ExternalVault::StatusIsInvalid
4290
4369
  end
4291
4370
 
4292
- context "Visa/Mastercard/Discover" do
4371
+ context "Visa/Mastercard/Discover/AmEx" do
4293
4372
  it "accepts status" do
4294
4373
  result = Braintree::Transaction.create(
4295
4374
  :type => "sale",
@@ -4341,12 +4420,12 @@ describe Braintree::Transaction do
4341
4420
  end
4342
4421
  end
4343
4422
 
4344
- context "Non-(Visa/Mastercard/Discover) card types" do
4423
+ context "Non-(Visa/Mastercard/Discover/AmEx) card types" do
4345
4424
  it "accepts status" do
4346
4425
  result = Braintree::Transaction.create(
4347
4426
  :type => "sale",
4348
4427
  :credit_card => {
4349
- :number => Braintree::Test::CreditCardNumbers::AmExes[0],
4428
+ :number => Braintree::Test::CreditCardNumbers::JCBs[0],
4350
4429
  :expiration_date => "05/2009"
4351
4430
  },
4352
4431
  :external_vault => {
@@ -4355,14 +4434,14 @@ describe Braintree::Transaction do
4355
4434
  :amount => "10.00",
4356
4435
  )
4357
4436
  result.success?.should == true
4358
- result.transaction.network_transaction_id.should be_nil
4437
+ result.transaction.network_transaction_id.should_not be_nil
4359
4438
  end
4360
4439
 
4361
4440
  it "accepts blank previous_network_transaction_id" do
4362
4441
  result = Braintree::Transaction.create(
4363
4442
  :type => "sale",
4364
4443
  :credit_card => {
4365
- :number => Braintree::Test::CreditCardNumbers::AmExes[0],
4444
+ :number => Braintree::Test::CreditCardNumbers::JCBs[0],
4366
4445
  :expiration_date => "05/2009"
4367
4446
  },
4368
4447
  :external_vault => {
@@ -4372,27 +4451,9 @@ describe Braintree::Transaction do
4372
4451
  :amount => "10.00",
4373
4452
  )
4374
4453
  result.success?.should == true
4375
- result.transaction.network_transaction_id.should be_nil
4376
- 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
4454
+ result.transaction.network_transaction_id.should_not be_nil
4393
4455
  end
4394
4456
  end
4395
-
4396
4457
  end
4397
4458
 
4398
4459
  context "account_type" do
@@ -4409,7 +4470,7 @@ describe Braintree::Transaction do
4409
4470
  :credit_card => {
4410
4471
  :account_type => "credit",
4411
4472
  }
4412
- }
4473
+ },
4413
4474
  )
4414
4475
  result.success?.should == true
4415
4476
  result.transaction.credit_card_details.account_type.should == "credit"
@@ -4428,7 +4489,7 @@ describe Braintree::Transaction do
4428
4489
  :credit_card => {
4429
4490
  :account_type => "credit",
4430
4491
  }
4431
- }
4492
+ },
4432
4493
  )
4433
4494
  result.success?.should == true
4434
4495
  result.transaction.credit_card_details.account_type.should == "credit"
@@ -4448,7 +4509,7 @@ describe Braintree::Transaction do
4448
4509
  :account_type => "debit",
4449
4510
  },
4450
4511
  :submit_for_settlement => true,
4451
- }
4512
+ },
4452
4513
  )
4453
4514
  result.success?.should == true
4454
4515
  result.transaction.credit_card_details.account_type.should == "debit"
@@ -4467,7 +4528,7 @@ describe Braintree::Transaction do
4467
4528
  :credit_card => {
4468
4529
  :account_type => "debit",
4469
4530
  },
4470
- }
4531
+ },
4471
4532
  )
4472
4533
  result.success?.should == false
4473
4534
  result.errors.for(:transaction).for(:options).for(:credit_card).on(:account_type)[0].code.should == Braintree::ErrorCodes::Transaction::Options::CreditCard::AccountTypeDebitDoesNotSupportAuths
@@ -4486,7 +4547,7 @@ describe Braintree::Transaction do
4486
4547
  :credit_card => {
4487
4548
  :account_type => "ach",
4488
4549
  },
4489
- }
4550
+ },
4490
4551
  )
4491
4552
  result.success?.should == false
4492
4553
  result.errors.for(:transaction).for(:options).for(:credit_card).on(:account_type)[0].code.should == Braintree::ErrorCodes::Transaction::Options::CreditCard::AccountTypeIsInvalid
@@ -4504,7 +4565,7 @@ describe Braintree::Transaction do
4504
4565
  :credit_card => {
4505
4566
  :account_type => "credit",
4506
4567
  },
4507
- }
4568
+ },
4508
4569
  )
4509
4570
  result.success?.should == false
4510
4571
  result.errors.for(:transaction).for(:options).for(:credit_card).on(:account_type)[0].code.should == Braintree::ErrorCodes::Transaction::Options::CreditCard::AccountTypeNotSupported
@@ -4520,7 +4581,7 @@ describe Braintree::Transaction do
4520
4581
  :credit_card => {
4521
4582
  :number => Braintree::Test::CreditCardNumbers::Visa,
4522
4583
  :expiration_date => "05/2009"
4523
- }
4584
+ },
4524
4585
  )
4525
4586
  transaction.id.should =~ /^\w{6,}$/
4526
4587
  transaction.type.should == "sale"
@@ -4538,7 +4599,7 @@ describe Braintree::Transaction do
4538
4599
  :credit_card => {
4539
4600
  :number => Braintree::Test::CreditCardNumbers::Visa,
4540
4601
  :expiration_date => "05/2009"
4541
- }
4602
+ },
4542
4603
  )
4543
4604
  end.to raise_error(Braintree::ValidationsFailed)
4544
4605
  end
@@ -4571,14 +4632,6 @@ describe Braintree::Transaction do
4571
4632
  result.transaction.type.should == "credit"
4572
4633
  end
4573
4634
 
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
4635
  it "assigns the refunded_transaction_id to the original transaction" do
4583
4636
  transaction = create_transaction_to_refund
4584
4637
  refund_transaction = Braintree::Transaction.refund(transaction.id).transaction
@@ -4602,7 +4655,7 @@ describe Braintree::Transaction do
4602
4655
  :credit_card => {
4603
4656
  :number => Braintree::Test::CreditCardNumbers::Visa,
4604
4657
  :expiration_date => "05/2009"
4605
- }
4658
+ },
4606
4659
  )
4607
4660
  result = Braintree::Transaction.refund(transaction.id)
4608
4661
  result.success?.should == false
@@ -4639,7 +4692,7 @@ describe Braintree::Transaction do
4639
4692
  :credit_card => {
4640
4693
  :number => Braintree::Test::CreditCardNumbers::Visa,
4641
4694
  :expiration_date => "05/2009"
4642
- }
4695
+ },
4643
4696
  )
4644
4697
  result.success?.should == true
4645
4698
  result.transaction.id.should =~ /^\w{6,}$/
@@ -4695,7 +4748,7 @@ describe Braintree::Transaction do
4695
4748
  :postal_code => "60103",
4696
4749
  :country_name => "United States of America",
4697
4750
  :shipping_method => Braintree::Transaction::AddressDetails::ShippingMethod::Electronic
4698
- }
4751
+ },
4699
4752
  )
4700
4753
  result.success?.should == true
4701
4754
  transaction = result.transaction
@@ -4759,7 +4812,7 @@ describe Braintree::Transaction do
4759
4812
  :credit_card => {
4760
4813
  :number => Braintree::Test::CreditCardNumbers::Visa,
4761
4814
  :expiration_date => "05/2009"
4762
- }
4815
+ },
4763
4816
  )
4764
4817
  result.success?.should == true
4765
4818
  result.transaction.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
@@ -4771,7 +4824,7 @@ describe Braintree::Transaction do
4771
4824
  :credit_card => {
4772
4825
  :number => Braintree::Test::CreditCardNumbers::Visa,
4773
4826
  :expiration_date => "05/2009"
4774
- }
4827
+ },
4775
4828
  )
4776
4829
  result.success?.should == true
4777
4830
  result.transaction.merchant_account_id.should == SpecHelper::DefaultMerchantAccountId
@@ -4790,7 +4843,7 @@ describe Braintree::Transaction do
4790
4843
  },
4791
4844
  :options => {
4792
4845
  :store_in_vault => true
4793
- }
4846
+ },
4794
4847
  )
4795
4848
  result.success?.should == true
4796
4849
  transaction = result.transaction
@@ -4825,7 +4878,7 @@ describe Braintree::Transaction do
4825
4878
  :options => {
4826
4879
  :store_in_vault => true,
4827
4880
  :add_billing_address_to_payment_method => true,
4828
- }
4881
+ },
4829
4882
  )
4830
4883
  result.success?.should == true
4831
4884
  transaction = result.transaction
@@ -4870,7 +4923,7 @@ describe Braintree::Transaction do
4870
4923
  :options => {
4871
4924
  :store_in_vault => true,
4872
4925
  :store_shipping_address_in_vault => true,
4873
- }
4926
+ },
4874
4927
  )
4875
4928
  result.success?.should == true
4876
4929
  transaction = result.transaction
@@ -4896,7 +4949,7 @@ describe Braintree::Transaction do
4896
4949
  :number => "5105105105105100",
4897
4950
  :expiration_date => "05/2012"
4898
4951
  },
4899
- :options => { :store_in_vault => true }
4952
+ :options => {:store_in_vault => true},
4900
4953
  )
4901
4954
 
4902
4955
  result.success?.should == true
@@ -4914,7 +4967,7 @@ describe Braintree::Transaction do
4914
4967
  },
4915
4968
  :options => {
4916
4969
  :submit_for_settlement => true
4917
- }
4970
+ },
4918
4971
  )
4919
4972
  result.success?.should == true
4920
4973
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -4937,7 +4990,7 @@ describe Braintree::Transaction do
4937
4990
  },
4938
4991
  :options => {
4939
4992
  :store_in_vault => true
4940
- }
4993
+ },
4941
4994
  )
4942
4995
  result.success?.should == true
4943
4996
  transaction = result.transaction
@@ -4952,20 +5005,20 @@ describe Braintree::Transaction do
4952
5005
  :credit_card => {
4953
5006
  :number => Braintree::Test::CreditCardNumbers::Visa,
4954
5007
  :expiration_date => "05/2010"
4955
- }
5008
+ },
4956
5009
  )
4957
5010
  address = Braintree::Address.create!(
4958
5011
  :customer_id => customer.id,
4959
- :street_address => '123 Fake St.'
5012
+ :street_address => "123 Fake St.",
4960
5013
  )
4961
5014
  result = Braintree::Transaction.sale(
4962
5015
  :amount => "100",
4963
5016
  :customer_id => customer.id,
4964
- :shipping_address_id => address.id
5017
+ :shipping_address_id => address.id,
4965
5018
  )
4966
5019
  result.success?.should == true
4967
5020
  transaction = result.transaction
4968
- transaction.shipping_details.street_address.should == '123 Fake St.'
5021
+ transaction.shipping_details.street_address.should == "123 Fake St."
4969
5022
  transaction.customer_details.id.should == customer.id
4970
5023
  transaction.shipping_details.id.should == address.id
4971
5024
  end
@@ -4982,12 +5035,95 @@ describe Braintree::Transaction do
4982
5035
  }
4983
5036
  result = Braintree::Transaction.sale(params[:transaction])
4984
5037
  result.success?.should == false
4985
- result.params.should == {:transaction => {:type => 'sale', :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
5038
+ result.params.should == {:transaction => {:type => "sale", :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
4986
5039
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
4987
5040
  end
4988
5041
 
5042
+ it "validates currency_iso_code and creates transaction" do
5043
+ params = {
5044
+ :transaction => {
5045
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5046
+ :currency_iso_code => "USD",
5047
+ :credit_card => {
5048
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5049
+ :expiration_date => "05/2009"
5050
+ }
5051
+ }
5052
+ }
5053
+ result = Braintree::Transaction.sale(params[:transaction])
5054
+ result.success?.should == true
5055
+ result.transaction.currency_iso_code == "USD"
5056
+ end
5057
+
5058
+ it "validates currency_iso_code and returns error" do
5059
+ params = {
5060
+ :transaction => {
5061
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5062
+ :currency_iso_code => "CAD",
5063
+ :credit_card => {
5064
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5065
+ :expiration_date => "05/2009"
5066
+ }
5067
+ }
5068
+ }
5069
+ result = Braintree::Transaction.sale(params[:transaction])
5070
+ result.success?.should == false
5071
+ result.errors.for(:transaction).on(:currency_iso_code)[0].code.should == Braintree::ErrorCodes::Transaction::CurrencyCodeNotSupportedByMerchantAccount
5072
+ end
5073
+
5074
+ it "validates currency_iso_code and creates transaction with specified merchant account" do
5075
+ params = {
5076
+ :transaction => {
5077
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5078
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
5079
+ :currency_iso_code => "USD",
5080
+ :credit_card => {
5081
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5082
+ :expiration_date => "05/2009"
5083
+ }
5084
+ }
5085
+ }
5086
+ result = Braintree::Transaction.sale(params[:transaction])
5087
+ result.success?.should == true
5088
+ result.transaction.currency_iso_code == "USD"
5089
+ result.transaction.merchant_account_id == SpecHelper::NonDefaultMerchantAccountId
5090
+ end
5091
+
5092
+ it "validates currency_iso_code and returns error with specified merchant account" do
5093
+ params = {
5094
+ :transaction => {
5095
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5096
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
5097
+ :currency_iso_code => "CAD",
5098
+ :credit_card => {
5099
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5100
+ :expiration_date => "05/2009"
5101
+ }
5102
+ }
5103
+ }
5104
+ result = Braintree::Transaction.sale(params[:transaction])
5105
+ result.success?.should == false
5106
+ result.errors.for(:transaction).on(:currency_iso_code)[0].code.should == Braintree::ErrorCodes::Transaction::CurrencyCodeNotSupportedByMerchantAccount
5107
+ end
5108
+
5109
+ it "validates tax_amount for Aib domestic sweden transaction and returns error" do
5110
+ params = {
5111
+ :transaction => {
5112
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
5113
+ :merchant_account_id => SpecHelper::AibSwedenMaMerchantAccountId,
5114
+ :credit_card => {
5115
+ :number => Braintree::Test::CreditCardNumbers::Visa,
5116
+ :expiration_date => "05/2030"
5117
+ }
5118
+ }
5119
+ }
5120
+ result = Braintree::Transaction.sale(params[:transaction])
5121
+ result.success?.should == false
5122
+ result.errors.for(:transaction).on(:tax_amount)[0].code.should == Braintree::ErrorCodes::Transaction::TaxAmountIsRequiredForAibSwedish
5123
+ end
5124
+
4989
5125
  it "skips advanced fraud checking if transaction[options][skip_advanced_fraud_checking] is set to true" do
4990
- with_advanced_fraud_integration_merchant do
5126
+ with_advanced_fraud_kount_integration_merchant do
4991
5127
  result = Braintree::Transaction.sale(
4992
5128
  :amount => Braintree::Test::TransactionAmounts::Authorize,
4993
5129
  :credit_card => {
@@ -4996,7 +5132,7 @@ describe Braintree::Transaction do
4996
5132
  },
4997
5133
  :options => {
4998
5134
  :skip_advanced_fraud_checking => true
4999
- }
5135
+ },
5000
5136
  )
5001
5137
  result.success?.should == true
5002
5138
  result.transaction.risk_data.should be_nil
@@ -5020,11 +5156,11 @@ describe Braintree::Transaction do
5020
5156
  result.transaction.status.should == Braintree::Transaction::Status::Authorized
5021
5157
  end
5022
5158
 
5023
- context "Android Pay params" do
5159
+ context "Google Pay params" do
5024
5160
  it "works with full params" do
5025
5161
  params = {
5026
5162
  :amount => "3.12",
5027
- :android_pay_card => {
5163
+ :google_pay_card => {
5028
5164
  :number => "4012888888881881",
5029
5165
  :cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
5030
5166
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
@@ -5043,7 +5179,7 @@ describe Braintree::Transaction do
5043
5179
  it "works with only number, cryptogram, expiration and transaction ID (network tokenized card)" do
5044
5180
  params = {
5045
5181
  :amount => "3.12",
5046
- :android_pay_card => {
5182
+ :google_pay_card => {
5047
5183
  :number => "4012888888881881",
5048
5184
  :cryptogram => "AAAAAAAA/COBt84dnIEcwAA3gAAGhgEDoLABAAhAgAABAAAALnNCLw==",
5049
5185
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
@@ -5059,7 +5195,7 @@ describe Braintree::Transaction do
5059
5195
  it "works with only number, expiration and transaction ID (non-tokenized card)" do
5060
5196
  params = {
5061
5197
  :amount => "3.12",
5062
- :android_pay_card => {
5198
+ :google_pay_card => {
5063
5199
  :number => "4012888888881881",
5064
5200
  :google_transaction_id => "25469d622c1dd37cb1a403c6d438e850",
5065
5201
  :expiration_month => "10",
@@ -5090,7 +5226,7 @@ describe Braintree::Transaction do
5090
5226
  :currency_amount => "10.00",
5091
5227
  :currency_iso_code => "USD"
5092
5228
  }
5093
- }
5229
+ },
5094
5230
  )
5095
5231
  result.success?.should == true
5096
5232
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -5112,7 +5248,7 @@ describe Braintree::Transaction do
5112
5248
  :currency_amount => "10.00",
5113
5249
  :currency_iso_code => "USD"
5114
5250
  }
5115
- }
5251
+ },
5116
5252
  )
5117
5253
  result.success?.should == true
5118
5254
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -5134,7 +5270,7 @@ describe Braintree::Transaction do
5134
5270
  :currency_amount => "10.00",
5135
5271
  :currency_iso_code => "USD"
5136
5272
  }
5137
- }
5273
+ },
5138
5274
  )
5139
5275
  result.success?.should == true
5140
5276
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -5157,7 +5293,7 @@ describe Braintree::Transaction do
5157
5293
  :currency_amount => "10.00",
5158
5294
  :currency_iso_code => "USD"
5159
5295
  }
5160
- }
5296
+ },
5161
5297
  )
5162
5298
  result.success?.should == true
5163
5299
 
@@ -5181,7 +5317,7 @@ describe Braintree::Transaction do
5181
5317
  :currency_amount => "10.00",
5182
5318
  :currency_iso_code => "USD"
5183
5319
  }
5184
- }
5320
+ },
5185
5321
  )
5186
5322
  result.success?.should == true
5187
5323
  result.transaction.status.should == Braintree::Transaction::Status::Authorized
@@ -5206,7 +5342,7 @@ describe Braintree::Transaction do
5206
5342
  :currency_amount => "10.00",
5207
5343
  :currency_iso_code => "USD"
5208
5344
  }
5209
- }
5345
+ },
5210
5346
  )
5211
5347
  result.success?.should == true
5212
5348
  result.transaction.status.should == Braintree::Transaction::Status::Authorized
@@ -5226,7 +5362,7 @@ describe Braintree::Transaction do
5226
5362
  :credit_card => {
5227
5363
  :number => Braintree::Test::CreditCardNumbers::Visa,
5228
5364
  :expiration_date => "05/2009"
5229
- }
5365
+ },
5230
5366
  )
5231
5367
  transaction.id.should =~ /^\w{6,}$/
5232
5368
  transaction.type.should == "sale"
@@ -5243,7 +5379,7 @@ describe Braintree::Transaction do
5243
5379
  :credit_card => {
5244
5380
  :number => Braintree::Test::CreditCardNumbers::Visa,
5245
5381
  :expiration_date => "05/2009"
5246
- }
5382
+ },
5247
5383
  )
5248
5384
  end.to raise_error(Braintree::ValidationsFailed)
5249
5385
  end
@@ -5256,7 +5392,7 @@ describe Braintree::Transaction do
5256
5392
  :credit_card => {
5257
5393
  :number => Braintree::Test::CreditCardNumbers::Visa,
5258
5394
  :expiration_date => "06/2009"
5259
- }
5395
+ },
5260
5396
  )
5261
5397
  result = Braintree::Transaction.submit_for_settlement(transaction.id)
5262
5398
  result.success?.should == true
@@ -5268,7 +5404,7 @@ describe Braintree::Transaction do
5268
5404
  :credit_card => {
5269
5405
  :number => Braintree::Test::CreditCardNumbers::Visa,
5270
5406
  :expiration_date => "06/2009"
5271
- }
5407
+ },
5272
5408
  )
5273
5409
  transaction.amount.should == BigDecimal("1000.00")
5274
5410
  result = Braintree::Transaction.submit_for_settlement(transaction.id, "999.99")
@@ -5284,9 +5420,9 @@ describe Braintree::Transaction do
5284
5420
  :credit_card => {
5285
5421
  :number => Braintree::Test::CreditCardNumbers::Visa,
5286
5422
  :expiration_date => "06/2009"
5287
- }
5423
+ },
5288
5424
  )
5289
- options = { :order_id => "ABC123" }
5425
+ options = {:order_id => "ABC123"}
5290
5426
  result = Braintree::Transaction.submit_for_settlement(transaction.id, nil, options)
5291
5427
  result.success?.should == true
5292
5428
  result.transaction.order_id.should == "ABC123"
@@ -5299,13 +5435,13 @@ describe Braintree::Transaction do
5299
5435
  :credit_card => {
5300
5436
  :number => Braintree::Test::CreditCardNumbers::Visa,
5301
5437
  :expiration_date => "06/2009"
5302
- }
5438
+ },
5303
5439
  )
5304
5440
 
5305
5441
  options = {
5306
5442
  :descriptor => {
5307
- :name => '123*123456789012345678',
5308
- :phone => '3334445555',
5443
+ :name => "123*123456789012345678",
5444
+ :phone => "3334445555",
5309
5445
  :url => "ebay.com"
5310
5446
  }
5311
5447
  }
@@ -5313,9 +5449,9 @@ describe Braintree::Transaction do
5313
5449
  result = Braintree::Transaction.submit_for_settlement(transaction.id, nil, options)
5314
5450
  result.success?.should == true
5315
5451
  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'
5452
+ result.transaction.descriptor.name.should == "123*123456789012345678"
5453
+ result.transaction.descriptor.phone.should == "3334445555"
5454
+ result.transaction.descriptor.url.should == "ebay.com"
5319
5455
  end
5320
5456
 
5321
5457
  it "raises an error if an invalid option is passed in" do
@@ -5324,10 +5460,10 @@ describe Braintree::Transaction do
5324
5460
  :credit_card => {
5325
5461
  :number => Braintree::Test::CreditCardNumbers::Visa,
5326
5462
  :expiration_date => "06/2009"
5327
- }
5463
+ },
5328
5464
  )
5329
5465
 
5330
- options = { :order_id => "ABC123", :invalid_option => "i'm invalid" }
5466
+ options = {:order_id => "ABC123", :invalid_option => "i'm invalid"}
5331
5467
 
5332
5468
  expect do
5333
5469
  Braintree::Transaction.submit_for_settlement(transaction.id, nil, options)
@@ -5337,10 +5473,11 @@ describe Braintree::Transaction do
5337
5473
  it "returns an error result if settlement is too large" do
5338
5474
  transaction = Braintree::Transaction.sale!(
5339
5475
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5476
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
5340
5477
  :credit_card => {
5341
5478
  :number => Braintree::Test::CreditCardNumbers::Visa,
5342
5479
  :expiration_date => "06/2009"
5343
- }
5480
+ },
5344
5481
  )
5345
5482
  transaction.amount.should == BigDecimal("1000.00")
5346
5483
  result = Braintree::Transaction.submit_for_settlement(transaction.id, "1000.01")
@@ -5355,7 +5492,7 @@ describe Braintree::Transaction do
5355
5492
  :credit_card => {
5356
5493
  :number => Braintree::Test::CreditCardNumbers::Visa,
5357
5494
  :expiration_date => "06/2009"
5358
- }
5495
+ },
5359
5496
  ).transaction
5360
5497
  result = Braintree::Transaction.submit_for_settlement(transaction.id)
5361
5498
  result.success?.should == false
@@ -5372,7 +5509,7 @@ describe Braintree::Transaction do
5372
5509
  :number => Braintree::Test::CreditCardNumbers::Visa,
5373
5510
  :expiration_date => "06/2009"
5374
5511
  },
5375
- :service_fee_amount => "1.00"
5512
+ :service_fee_amount => "1.00",
5376
5513
  ).transaction
5377
5514
  result = Braintree::Transaction.submit_for_settlement(transaction.id, "0.01")
5378
5515
  result.success?.should == false
@@ -5395,7 +5532,7 @@ describe Braintree::Transaction do
5395
5532
  :currency_amount => "10.00",
5396
5533
  :currency_iso_code => "USD"
5397
5534
  }
5398
- }
5535
+ },
5399
5536
  )
5400
5537
  result.success?.should == true
5401
5538
 
@@ -5419,7 +5556,7 @@ describe Braintree::Transaction do
5419
5556
  :currency_amount => "10.00",
5420
5557
  :currency_iso_code => "USD"
5421
5558
  }
5422
- }
5559
+ },
5423
5560
  )
5424
5561
  result.success?.should == true
5425
5562
 
@@ -5439,7 +5576,7 @@ describe Braintree::Transaction do
5439
5576
  :discount_amount => "12.00",
5440
5577
  :tax_amount => "0",
5441
5578
  },
5442
- ]
5579
+ ],
5443
5580
  )
5444
5581
  result.success?.should == true
5445
5582
  result.transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
@@ -5453,9 +5590,9 @@ describe Braintree::Transaction do
5453
5590
  :credit_card => {
5454
5591
  :number => Braintree::Test::CreditCardNumbers::Visa,
5455
5592
  :expiration_date => "06/2009"
5456
- }
5593
+ },
5457
5594
  )
5458
- options = { :order_id => "ABC123" }
5595
+ options = {:order_id => "ABC123"}
5459
5596
  transaction = Braintree::Transaction.submit_for_settlement!(original_transaction.id, "0.01", options)
5460
5597
  transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
5461
5598
  transaction.id.should == original_transaction.id
@@ -5465,10 +5602,11 @@ describe Braintree::Transaction do
5465
5602
  it "raises a ValidationsFailed if unsuccessful" do
5466
5603
  transaction = Braintree::Transaction.sale!(
5467
5604
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5605
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
5468
5606
  :credit_card => {
5469
5607
  :number => Braintree::Test::CreditCardNumbers::Visa,
5470
5608
  :expiration_date => "06/2009"
5471
- }
5609
+ },
5472
5610
  )
5473
5611
  transaction.amount.should == BigDecimal("1000.00")
5474
5612
  expect do
@@ -5484,18 +5622,18 @@ describe Braintree::Transaction do
5484
5622
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5485
5623
  :merchant_account_id => SpecHelper::DefaultMerchantAccountId,
5486
5624
  :descriptor => {
5487
- :name => '123*123456789012345678',
5488
- :phone => '3334445555',
5625
+ :name => "123*123456789012345678",
5626
+ :phone => "3334445555",
5489
5627
  :url => "ebay.com"
5490
5628
  },
5491
- :order_id => '123',
5629
+ :order_id => "123",
5492
5630
  :credit_card => {
5493
5631
  :number => Braintree::Test::CreditCardNumbers::Visa,
5494
5632
  :expiration_date => "06/2009"
5495
5633
  },
5496
5634
  :options => {
5497
5635
  :submit_for_settlement => true
5498
- }
5636
+ },
5499
5637
  )
5500
5638
  end
5501
5639
 
@@ -5503,16 +5641,16 @@ describe Braintree::Transaction do
5503
5641
  result = Braintree::Transaction.update_details(transaction.id, {
5504
5642
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5505
5643
  :descriptor => {
5506
- :name => '456*123456789012345678',
5507
- :phone => '3334445555',
5644
+ :name => "456*123456789012345678",
5645
+ :phone => "3334445555",
5508
5646
  :url => "ebay.com",
5509
5647
  },
5510
- :order_id => '456'
5648
+ :order_id => "456"
5511
5649
  })
5512
5650
  result.success?.should == true
5513
5651
  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'
5652
+ result.transaction.order_id.should == "456"
5653
+ result.transaction.descriptor.name.should == "456*123456789012345678"
5516
5654
  end
5517
5655
 
5518
5656
  it "raises an error when a key is invalid" do
@@ -5520,11 +5658,11 @@ describe Braintree::Transaction do
5520
5658
  Braintree::Transaction.update_details(transaction.id, {
5521
5659
  :invalid_key => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5522
5660
  :descriptor => {
5523
- :name => '456*123456789012345678',
5524
- :phone => '3334445555',
5661
+ :name => "456*123456789012345678",
5662
+ :phone => "3334445555",
5525
5663
  :url => "ebay.com",
5526
5664
  },
5527
- :order_id => '456'
5665
+ :order_id => "456"
5528
5666
  })
5529
5667
  end.to raise_error(ArgumentError)
5530
5668
  end
@@ -5534,11 +5672,11 @@ describe Braintree::Transaction do
5534
5672
  result = Braintree::Transaction.update_details(transaction.id, {
5535
5673
  :amount => "10000",
5536
5674
  :descriptor => {
5537
- :name => '456*123456789012345678',
5538
- :phone => '3334445555',
5675
+ :name => "456*123456789012345678",
5676
+ :phone => "3334445555",
5539
5677
  :url => "ebay.com",
5540
5678
  },
5541
- :order_id => '456'
5679
+ :order_id => "456"
5542
5680
  })
5543
5681
  result.success?.should == false
5544
5682
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::SettlementAmountIsTooLarge
@@ -5548,11 +5686,11 @@ describe Braintree::Transaction do
5548
5686
  result = Braintree::Transaction.update_details(transaction.id, {
5549
5687
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5550
5688
  :descriptor => {
5551
- :name => 'invalid descriptor name',
5552
- :phone => 'invalid phone',
5553
- :url => '12345678901234'
5689
+ :name => "invalid descriptor name",
5690
+ :phone => "invalid phone",
5691
+ :url => "12345678901234"
5554
5692
  },
5555
- :order_id => '456'
5693
+ :order_id => "456"
5556
5694
  })
5557
5695
  result.success?.should == false
5558
5696
  result.errors.for(:transaction).for(:descriptor).on(:name)[0].code.should == Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid
@@ -5564,11 +5702,11 @@ describe Braintree::Transaction do
5564
5702
  result = Braintree::Transaction.update_details(transaction.id, {
5565
5703
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5566
5704
  :descriptor => {
5567
- :name => '456*123456789012345678',
5568
- :phone => '3334445555',
5705
+ :name => "456*123456789012345678",
5706
+ :phone => "3334445555",
5569
5707
  :url => "ebay.com",
5570
5708
  },
5571
- :order_id => 'x' * 256
5709
+ :order_id => "x" * 256
5572
5710
  })
5573
5711
  result.success?.should == false
5574
5712
  result.errors.for(:transaction).on(:order_id)[0].code.should == Braintree::ErrorCodes::Transaction::OrderIdIsTooLong
@@ -5579,27 +5717,27 @@ describe Braintree::Transaction do
5579
5717
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5580
5718
  :merchant_account_id => SpecHelper::FakeAmexDirectMerchantAccountId,
5581
5719
  :descriptor => {
5582
- :name => '123*123456789012345678',
5583
- :phone => '3334445555',
5720
+ :name => "123*123456789012345678",
5721
+ :phone => "3334445555",
5584
5722
  :url => "ebay.com"
5585
5723
  },
5586
- :order_id => '123',
5724
+ :order_id => "123",
5587
5725
  :credit_card => {
5588
5726
  :number => Braintree::Test::CreditCardNumbers::AmexPayWithPoints::Success,
5589
5727
  :expiration_date => "05/2009"
5590
5728
  },
5591
5729
  :options => {
5592
5730
  :submit_for_settlement => true
5593
- }
5731
+ },
5594
5732
  )
5595
5733
  result = Braintree::Transaction.update_details(transaction.id, {
5596
5734
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5597
5735
  :descriptor => {
5598
- :name => '456*123456789012345678',
5599
- :phone => '3334445555',
5736
+ :name => "456*123456789012345678",
5737
+ :phone => "3334445555",
5600
5738
  :url => "ebay.com",
5601
5739
  },
5602
- :order_id => '456'
5740
+ :order_id => "456"
5603
5741
  })
5604
5742
  result.success?.should == false
5605
5743
  result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::ProcessorDoesNotSupportUpdatingTransactionDetails
@@ -5613,24 +5751,24 @@ describe Braintree::Transaction do
5613
5751
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5614
5752
  :merchant_account_id => SpecHelper::DefaultMerchantAccountId,
5615
5753
  :descriptor => {
5616
- :name => '123*123456789012345678',
5617
- :phone => '3334445555',
5754
+ :name => "123*123456789012345678",
5755
+ :phone => "3334445555",
5618
5756
  :url => "ebay.com"
5619
5757
  },
5620
- :order_id => '123',
5758
+ :order_id => "123",
5621
5759
  :credit_card => {
5622
5760
  :number => Braintree::Test::CreditCardNumbers::Visa,
5623
5761
  :expiration_date => "06/2009"
5624
- }
5762
+ },
5625
5763
  )
5626
5764
  result = Braintree::Transaction.update_details(transaction.id, {
5627
5765
  :amount => Braintree::Test::TransactionAmounts::Authorize.to_f - 1,
5628
5766
  :descriptor => {
5629
- :name => '456*123456789012345678',
5630
- :phone => '3334445555',
5767
+ :name => "456*123456789012345678",
5768
+ :phone => "3334445555",
5631
5769
  :url => "ebay.com",
5632
5770
  },
5633
- :order_id => '456'
5771
+ :order_id => "456"
5634
5772
  })
5635
5773
  result.success?.should == false
5636
5774
  result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::CannotUpdateTransactionDetailsNotSubmittedForSettlement
@@ -5647,7 +5785,7 @@ describe Braintree::Transaction do
5647
5785
  :credit_card => {
5648
5786
  :number => Braintree::Test::CreditCardNumbers::Visa,
5649
5787
  :expiration_date => "06/2009"
5650
- }
5788
+ },
5651
5789
  )
5652
5790
 
5653
5791
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100)
@@ -5682,7 +5820,7 @@ describe Braintree::Transaction do
5682
5820
  :credit_card => {
5683
5821
  :number => Braintree::Test::CreditCardNumbers::Visa,
5684
5822
  :expiration_date => "05/2009"
5685
- }
5823
+ },
5686
5824
  )
5687
5825
 
5688
5826
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100, :order_id => 1234)
@@ -5698,7 +5836,7 @@ describe Braintree::Transaction do
5698
5836
  :credit_card => {
5699
5837
  :number => Braintree::Test::CreditCardNumbers::Visa,
5700
5838
  :expiration_date => "05/2009"
5701
- }
5839
+ },
5702
5840
  )
5703
5841
 
5704
5842
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100, :order_id => "1"*256)
@@ -5713,13 +5851,13 @@ describe Braintree::Transaction do
5713
5851
  :credit_card => {
5714
5852
  :number => Braintree::Test::CreditCardNumbers::Visa,
5715
5853
  :expiration_date => "05/2009"
5716
- }
5854
+ },
5717
5855
  )
5718
5856
 
5719
5857
  result = Braintree::Transaction.submit_for_partial_settlement(
5720
5858
  authorized_transaction.id,
5721
5859
  100,
5722
- :descriptor => { :name => "123*123456789012345678", :phone => "5555551234", :url => "url.com" }
5860
+ :descriptor => {:name => "123*123456789012345678", :phone => "5555551234", :url => "url.com"},
5723
5861
  )
5724
5862
  result.success?.should == true
5725
5863
  partial_settlement_transaction = result.transaction
@@ -5735,7 +5873,7 @@ describe Braintree::Transaction do
5735
5873
  :credit_card => {
5736
5874
  :number => Braintree::Test::CreditCardNumbers::Visa,
5737
5875
  :expiration_date => "05/2009"
5738
- }
5876
+ },
5739
5877
  )
5740
5878
 
5741
5879
  result = Braintree::Transaction.submit_for_partial_settlement(
@@ -5743,9 +5881,9 @@ describe Braintree::Transaction do
5743
5881
  100,
5744
5882
  :descriptor => {
5745
5883
  :name => "invalid_format",
5746
- :phone => '%bad4445555',
5747
- :url => '12345678901234'
5748
- }
5884
+ :phone => "%bad4445555",
5885
+ :url => "12345678901234"
5886
+ },
5749
5887
  )
5750
5888
  result.success?.should == false
5751
5889
  result.errors.for(:transaction).for(:descriptor).on(:name)[0].code.should == Braintree::ErrorCodes::Descriptor::NameFormatIsInvalid
@@ -5760,7 +5898,7 @@ describe Braintree::Transaction do
5760
5898
  :credit_card => {
5761
5899
  :number => Braintree::Test::CreditCardNumbers::AmexPayWithPoints::Success,
5762
5900
  :expiration_date => "05/2009"
5763
- }
5901
+ },
5764
5902
  )
5765
5903
 
5766
5904
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100)
@@ -5772,7 +5910,7 @@ describe Braintree::Transaction do
5772
5910
  authorized_transaction = Braintree::Transaction.sale!(
5773
5911
  :amount => Braintree::Test::TransactionAmounts::Authorize,
5774
5912
  :merchant_account_id => SpecHelper::FakeVenmoAccountMerchantAccountId,
5775
- :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount
5913
+ :payment_method_nonce => Braintree::Test::Nonce::VenmoAccount,
5776
5914
  )
5777
5915
 
5778
5916
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100)
@@ -5787,7 +5925,7 @@ describe Braintree::Transaction do
5787
5925
  :credit_card => {
5788
5926
  :number => Braintree::Test::CreditCardNumbers::Visa,
5789
5927
  :expiration_date => "06/2009"
5790
- }
5928
+ },
5791
5929
  )
5792
5930
 
5793
5931
  result = Braintree::Transaction.submit_for_partial_settlement(authorized_transaction.id, 100)
@@ -5805,7 +5943,7 @@ describe Braintree::Transaction do
5805
5943
  :credit_card => {
5806
5944
  :number => Braintree::Test::CreditCardNumbers::Visa,
5807
5945
  :expiration_date => "06/2009"
5808
- }
5946
+ },
5809
5947
  )
5810
5948
 
5811
5949
  result = Braintree::Transaction.void(authorized_transaction.id)
@@ -5824,9 +5962,9 @@ describe Braintree::Transaction do
5824
5962
  :credit_card => {
5825
5963
  :number => Braintree::Test::CreditCardNumbers::Visa,
5826
5964
  :expiration_date => "06/2009"
5827
- }
5965
+ },
5828
5966
  )
5829
- options = { :order_id => "ABC123" }
5967
+ options = {:order_id => "ABC123"}
5830
5968
  transaction = Braintree::Transaction.submit_for_partial_settlement!(original_transaction.id, "0.01", options)
5831
5969
  transaction.status.should == Braintree::Transaction::Status::SubmittedForSettlement
5832
5970
  transaction.order_id.should == options[:order_id]
@@ -5838,7 +5976,7 @@ describe Braintree::Transaction do
5838
5976
  :credit_card => {
5839
5977
  :number => Braintree::Test::CreditCardNumbers::Visa,
5840
5978
  :expiration_date => "06/2009"
5841
- }
5979
+ },
5842
5980
  )
5843
5981
  transaction.amount.should == BigDecimal("1000.00")
5844
5982
  expect do
@@ -5863,7 +6001,7 @@ describe Braintree::Transaction do
5863
6001
  :number => Braintree::Test::CreditCardNumbers::Visa,
5864
6002
  :expiration_date => "05/2009"
5865
6003
  },
5866
- :service_fee_amount => '1.00'
6004
+ :service_fee_amount => "1.00",
5867
6005
  )
5868
6006
 
5869
6007
  transaction.escrow_status.should be_nil
@@ -5889,7 +6027,7 @@ describe Braintree::Transaction do
5889
6027
  :number => Braintree::Test::CreditCardNumbers::Visa,
5890
6028
  :expiration_date => "05/2009"
5891
6029
  },
5892
- :service_fee_amount => '1.00'
6030
+ :service_fee_amount => "1.00",
5893
6031
  )
5894
6032
 
5895
6033
  transaction.escrow_status.should be_nil
@@ -5949,7 +6087,7 @@ describe Braintree::Transaction do
5949
6087
  :credit_card => {
5950
6088
  :number => Braintree::Test::CreditCardNumbers::Visa,
5951
6089
  :expiration_date => "05/2009"
5952
- }
6090
+ },
5953
6091
  )
5954
6092
  result.success?.should == true
5955
6093
  result.transaction.id.should =~ /^\w{6,}$/
@@ -5972,7 +6110,7 @@ describe Braintree::Transaction do
5972
6110
  }
5973
6111
  result = Braintree::Transaction.credit(params[:transaction])
5974
6112
  result.success?.should == false
5975
- result.params.should == {:transaction => {:type => 'credit', :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
6113
+ result.params.should == {:transaction => {:type => "credit", :amount => nil, :credit_card => {:expiration_date => "05/2009"}}}
5976
6114
  result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
5977
6115
  end
5978
6116
 
@@ -5983,7 +6121,7 @@ describe Braintree::Transaction do
5983
6121
  :credit_card => {
5984
6122
  :number => Braintree::Test::CreditCardNumbers::Visa,
5985
6123
  :expiration_date => "05/2009"
5986
- }
6124
+ },
5987
6125
  )
5988
6126
  result.success?.should == true
5989
6127
  result.transaction.merchant_account_id.should == SpecHelper::NonDefaultMerchantAccountId
@@ -5995,7 +6133,7 @@ describe Braintree::Transaction do
5995
6133
  :credit_card => {
5996
6134
  :number => Braintree::Test::CreditCardNumbers::Visa,
5997
6135
  :expiration_date => "05/2009"
5998
- }
6136
+ },
5999
6137
  )
6000
6138
  result.success?.should == true
6001
6139
  result.transaction.merchant_account_id.should == SpecHelper::DefaultMerchantAccountId
@@ -6025,7 +6163,7 @@ describe Braintree::Transaction do
6025
6163
  :credit_card => {
6026
6164
  :number => Braintree::Test::CreditCardNumbers::Visa,
6027
6165
  :expiration_date => "05/2009"
6028
- }
6166
+ },
6029
6167
  )
6030
6168
  transaction.id.should =~ /^\w{6,}$/
6031
6169
  transaction.type.should == "credit"
@@ -6042,190 +6180,12 @@ describe Braintree::Transaction do
6042
6180
  :credit_card => {
6043
6181
  :number => Braintree::Test::CreditCardNumbers::Visa,
6044
6182
  :expiration_date => "05/2009"
6045
- }
6183
+ },
6046
6184
  )
6047
6185
  end.to raise_error(Braintree::ValidationsFailed)
6048
6186
  end
6049
6187
  end
6050
6188
 
6051
- describe "self.create_from_transparent_redirect" do
6052
- it "returns a successful result if successful" do
6053
- params = {
6054
- :transaction => {
6055
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6056
- :credit_card => {
6057
- :number => Braintree::Test::CreditCardNumbers::Visa,
6058
- :expiration_date => "05/2009"
6059
- }
6060
- }
6061
- }
6062
- tr_data_params = {
6063
- :transaction => {
6064
- :type => "sale"
6065
- }
6066
- }
6067
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6068
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6069
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6070
-
6071
- result.success?.should == true
6072
- transaction = result.transaction
6073
- transaction.type.should == "sale"
6074
- transaction.amount.should == BigDecimal("1000.00")
6075
- transaction.credit_card_details.bin.should == Braintree::Test::CreditCardNumbers::Visa[0, 6]
6076
- transaction.credit_card_details.last_4.should == Braintree::Test::CreditCardNumbers::Visa[-4..-1]
6077
- transaction.credit_card_details.expiration_date.should == "05/2009"
6078
- end
6079
-
6080
- it "raises an error with a message if given invalid params" do
6081
- params = {
6082
- :transaction => {
6083
- :bad => "value",
6084
- :amount => Braintree::Test::TransactionAmounts::Authorize,
6085
- :credit_card => {
6086
- :number => Braintree::Test::CreditCardNumbers::Visa,
6087
- :expiration_date => "05/2009"
6088
- }
6089
- }
6090
- }
6091
- tr_data_params = {
6092
- :transaction => {
6093
- :type => "sale"
6094
- }
6095
- }
6096
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6097
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6098
-
6099
- expect do
6100
- Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6101
- end.to raise_error(Braintree::AuthorizationError, "Invalid params: transaction[bad]")
6102
- end
6103
-
6104
- it "can put any param in tr_data" do
6105
- params = {
6106
-
6107
- }
6108
- tr_data_params = {
6109
- :transaction => {
6110
- :amount => "100.00",
6111
- :order_id => "123",
6112
- :channel => "MyShoppingCartProvider",
6113
- :type => "sale",
6114
- :credit_card => {
6115
- :cardholder_name => "The Cardholder",
6116
- :number => "5105105105105100",
6117
- :expiration_date => "05/2011",
6118
- :cvv => "123"
6119
- },
6120
- :customer => {
6121
- :first_name => "Dan",
6122
- :last_name => "Smith",
6123
- :company => "Braintree",
6124
- :email => "dan@example.com",
6125
- :phone => "419-555-1234",
6126
- :fax => "419-555-1235",
6127
- :website => "http://braintreepayments.com"
6128
- },
6129
- :billing => {
6130
- :first_name => "Carl",
6131
- :last_name => "Jones",
6132
- :company => "Braintree",
6133
- :street_address => "123 E Main St",
6134
- :extended_address => "Suite 403",
6135
- :locality => "Chicago",
6136
- :region => "IL",
6137
- :postal_code => "60622",
6138
- :country_name => "United States of America"
6139
- },
6140
- :shipping => {
6141
- :first_name => "Andrew",
6142
- :last_name => "Mason",
6143
- :company => "Braintree",
6144
- :street_address => "456 W Main St",
6145
- :extended_address => "Apt 2F",
6146
- :locality => "Bartlett",
6147
- :region => "IL",
6148
- :postal_code => "60103",
6149
- :country_name => "United States of America"
6150
- }
6151
- }
6152
- }
6153
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6154
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6155
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6156
-
6157
- transaction = result.transaction
6158
- transaction.id.should =~ /\A\w{6,}\z/
6159
- transaction.type.should == "sale"
6160
- transaction.status.should == Braintree::Transaction::Status::Authorized
6161
- transaction.amount.should == BigDecimal("100.00")
6162
- transaction.order_id.should == "123"
6163
- transaction.channel.should == "MyShoppingCartProvider"
6164
- transaction.processor_response_code.should == "1000"
6165
- transaction.authorization_expires_at.between?(Time.now, Time.now + (60 * 60 * 24 * 60)).should == true
6166
- transaction.created_at.between?(Time.now - 60, Time.now).should == true
6167
- transaction.updated_at.between?(Time.now - 60, Time.now).should == true
6168
- transaction.credit_card_details.bin.should == "510510"
6169
- transaction.credit_card_details.last_4.should == "5100"
6170
- transaction.credit_card_details.cardholder_name.should == "The Cardholder"
6171
- transaction.credit_card_details.masked_number.should == "510510******5100"
6172
- transaction.credit_card_details.card_type.should == "MasterCard"
6173
- transaction.avs_error_response_code.should == nil
6174
- transaction.avs_postal_code_response_code.should == "M"
6175
- transaction.avs_street_address_response_code.should == "M"
6176
- transaction.cvv_response_code.should == "M"
6177
- transaction.customer_details.first_name.should == "Dan"
6178
- transaction.customer_details.last_name.should == "Smith"
6179
- transaction.customer_details.company.should == "Braintree"
6180
- transaction.customer_details.email.should == "dan@example.com"
6181
- transaction.customer_details.phone.should == "419-555-1234"
6182
- transaction.customer_details.fax.should == "419-555-1235"
6183
- transaction.customer_details.website.should == "http://braintreepayments.com"
6184
- transaction.billing_details.first_name.should == "Carl"
6185
- transaction.billing_details.last_name.should == "Jones"
6186
- transaction.billing_details.company.should == "Braintree"
6187
- transaction.billing_details.street_address.should == "123 E Main St"
6188
- transaction.billing_details.extended_address.should == "Suite 403"
6189
- transaction.billing_details.locality.should == "Chicago"
6190
- transaction.billing_details.region.should == "IL"
6191
- transaction.billing_details.postal_code.should == "60622"
6192
- transaction.billing_details.country_name.should == "United States of America"
6193
- transaction.shipping_details.first_name.should == "Andrew"
6194
- transaction.shipping_details.last_name.should == "Mason"
6195
- transaction.shipping_details.company.should == "Braintree"
6196
- transaction.shipping_details.street_address.should == "456 W Main St"
6197
- transaction.shipping_details.extended_address.should == "Apt 2F"
6198
- transaction.shipping_details.locality.should == "Bartlett"
6199
- transaction.shipping_details.region.should == "IL"
6200
- transaction.shipping_details.postal_code.should == "60103"
6201
- transaction.shipping_details.country_name.should == "United States of America"
6202
- end
6203
-
6204
- it "returns an error result if validations fail" do
6205
- params = {
6206
- :transaction => {
6207
- :amount => "",
6208
- :credit_card => {
6209
- :number => Braintree::Test::CreditCardNumbers::Visa,
6210
- :expiration_date => "05/2009"
6211
- }
6212
- }
6213
- }
6214
- tr_data_params = {
6215
- :transaction => {
6216
- :type => "sale"
6217
- }
6218
- }
6219
- tr_data = Braintree::TransparentRedirect.transaction_data({:redirect_url => "http://example.com"}.merge(tr_data_params))
6220
- query_string_response = SpecHelper.simulate_form_post_for_tr(tr_data, params, Braintree::Transaction.create_transaction_url)
6221
- result = Braintree::Transaction.create_from_transparent_redirect(query_string_response)
6222
-
6223
- result.success?.should == false
6224
- result.params[:transaction].should == {:amount => "", :type => "sale", :credit_card => {:expiration_date => "05/2009"}}
6225
- result.errors.for(:transaction).on(:amount)[0].code.should == Braintree::ErrorCodes::Transaction::AmountIsRequired
6226
- end
6227
- end
6228
-
6229
6189
  describe "self.find" do
6230
6190
  it "finds the transaction with the given id" do
6231
6191
  result = Braintree::Transaction.create(
@@ -6234,7 +6194,7 @@ describe Braintree::Transaction do
6234
6194
  :credit_card => {
6235
6195
  :number => Braintree::Test::CreditCardNumbers::Visa,
6236
6196
  :expiration_date => "05/2009"
6237
- }
6197
+ },
6238
6198
  )
6239
6199
  result.success?.should == true
6240
6200
  created_transaction = result.transaction
@@ -6251,7 +6211,7 @@ describe Braintree::Transaction do
6251
6211
  :number => Braintree::Test::CreditCardNumbers::Visa,
6252
6212
  :expiration_date => "05/2009"
6253
6213
  },
6254
- :options => { :store_in_vault => true }
6214
+ :options => {:store_in_vault => true},
6255
6215
  )
6256
6216
  result.success?.should == true
6257
6217
  created_transaction = result.transaction
@@ -6267,6 +6227,12 @@ describe Braintree::Transaction do
6267
6227
  end.to raise_error(Braintree::NotFoundError, 'transaction with id "invalid-id" not found')
6268
6228
  end
6269
6229
 
6230
+ it "finds a transaction and returns an acquirer_reference_number if the transaction has one" do
6231
+ transaction = Braintree::Transaction.find("transactionwithacquirerreferencenumber")
6232
+
6233
+ transaction.acquirer_reference_number.should == "123456789 091019"
6234
+ end
6235
+
6270
6236
  context "disbursement_details" do
6271
6237
  it "includes disbursement_details on found transactions" do
6272
6238
  found_transaction = Braintree::Transaction.find("deposittransaction")
@@ -6274,7 +6240,8 @@ describe Braintree::Transaction do
6274
6240
  found_transaction.disbursed?.should == true
6275
6241
  disbursement = found_transaction.disbursement_details
6276
6242
 
6277
- disbursement.disbursement_date.should == "2013-04-10"
6243
+ expect(disbursement.disbursement_date).to be_a Date
6244
+ expect(disbursement.disbursement_date).to eq Date.parse("2013-04-10")
6278
6245
  disbursement.settlement_amount.should == "100.00"
6279
6246
  disbursement.settlement_currency_iso_code.should == "USD"
6280
6247
  disbursement.settlement_currency_exchange_rate.should == "1"
@@ -6289,7 +6256,7 @@ describe Braintree::Transaction do
6289
6256
  :credit_card => {
6290
6257
  :number => Braintree::Test::CreditCardNumbers::Visa,
6291
6258
  :expiration_date => "05/2009"
6292
- }
6259
+ },
6293
6260
  )
6294
6261
  result.success?.should == true
6295
6262
  created_transaction = result.transaction
@@ -6339,7 +6306,7 @@ describe Braintree::Transaction do
6339
6306
  :credit_card => {
6340
6307
  :number => Braintree::Test::CreditCardNumbers::Visa,
6341
6308
  :expiration_date => "05/2009"
6342
- }
6309
+ },
6343
6310
  )
6344
6311
  result.success?.should == true
6345
6312
  created_transaction = result.transaction
@@ -6352,15 +6319,21 @@ describe Braintree::Transaction do
6352
6319
  it "returns all the three_d_secure_info" do
6353
6320
  transaction = Braintree::Transaction.find("threedsecuredtransaction")
6354
6321
 
6322
+ expect(transaction.three_d_secure_info.authentication).to have_key(:trans_status)
6323
+ expect(transaction.three_d_secure_info.authentication).to have_key(:trans_status_reason)
6324
+ expect(transaction.three_d_secure_info.lookup).to have_key(:trans_status)
6325
+ expect(transaction.three_d_secure_info.lookup).to have_key(:trans_status_reason)
6326
+ transaction.three_d_secure_info.cavv.should == "somebase64value"
6327
+ transaction.three_d_secure_info.ds_transaction_id.should == "dstxnid"
6328
+ transaction.three_d_secure_info.eci_flag.should == "07"
6355
6329
  transaction.three_d_secure_info.enrolled.should == "Y"
6356
- transaction.three_d_secure_info.should be_liability_shifted
6330
+ transaction.three_d_secure_info.pares_status.should == "Y"
6357
6331
  transaction.three_d_secure_info.should be_liability_shift_possible
6332
+ transaction.three_d_secure_info.should be_liability_shifted
6358
6333
  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"
6334
+ expect(transaction.three_d_secure_info.three_d_secure_authentication_id).to be
6362
6335
  transaction.three_d_secure_info.three_d_secure_version.should == "1.0.2"
6363
- transaction.three_d_secure_info.ds_transaction_id.should == "dstxnid"
6336
+ transaction.three_d_secure_info.xid.should == "xidvalue"
6364
6337
  end
6365
6338
 
6366
6339
  it "is nil if the transaction wasn't 3d secured" do
@@ -6402,7 +6375,7 @@ describe Braintree::Transaction do
6402
6375
  :number => Braintree::Test::CreditCardNumbers::Visa,
6403
6376
  :expiration_date => "12/12",
6404
6377
  },
6405
- :service_fee_amount => "10.00"
6378
+ :service_fee_amount => "10.00",
6406
6379
  )
6407
6380
 
6408
6381
  result.transaction.escrow_status.should be_nil
@@ -6419,7 +6392,7 @@ describe Braintree::Transaction do
6419
6392
  :credit_card => {
6420
6393
  :number => Braintree::Test::CreditCardNumbers::Visa,
6421
6394
  :expiration_date => "05/2009"
6422
- }
6395
+ },
6423
6396
  )
6424
6397
 
6425
6398
  result = Braintree::Transaction.hold_in_escrow(transaction.id)
@@ -6437,7 +6410,7 @@ describe Braintree::Transaction do
6437
6410
  :number => Braintree::Test::CreditCardNumbers::Visa,
6438
6411
  :expiration_date => "12/12",
6439
6412
  },
6440
- :service_fee_amount => "10.00"
6413
+ :service_fee_amount => "10.00",
6441
6414
  )
6442
6415
 
6443
6416
  result.transaction.escrow_status.should be_nil
@@ -6453,7 +6426,7 @@ describe Braintree::Transaction do
6453
6426
  :credit_card => {
6454
6427
  :number => Braintree::Test::CreditCardNumbers::Visa,
6455
6428
  :expiration_date => "05/2009"
6456
- }
6429
+ },
6457
6430
  )
6458
6431
 
6459
6432
  expect do
@@ -6469,7 +6442,7 @@ describe Braintree::Transaction do
6469
6442
  :credit_card => {
6470
6443
  :number => Braintree::Test::CreditCardNumbers::Visa,
6471
6444
  :expiration_date => "05/2009"
6472
- }
6445
+ },
6473
6446
  )
6474
6447
  result = Braintree::Transaction.void(transaction.id)
6475
6448
  result.success?.should == true
@@ -6483,7 +6456,7 @@ describe Braintree::Transaction do
6483
6456
  :credit_card => {
6484
6457
  :number => Braintree::Test::CreditCardNumbers::Visa,
6485
6458
  :expiration_date => "05/2009"
6486
- }
6459
+ },
6487
6460
  ).transaction
6488
6461
  result = Braintree::Transaction.void(transaction.id)
6489
6462
  result.success?.should == false
@@ -6498,7 +6471,7 @@ describe Braintree::Transaction do
6498
6471
  :credit_card => {
6499
6472
  :number => Braintree::Test::CreditCardNumbers::Visa,
6500
6473
  :expiration_date => "05/2009"
6501
- }
6474
+ },
6502
6475
  )
6503
6476
  returned_transaction = Braintree::Transaction.void!(transaction.id)
6504
6477
  returned_transaction.should == transaction
@@ -6511,7 +6484,7 @@ describe Braintree::Transaction do
6511
6484
  :credit_card => {
6512
6485
  :number => Braintree::Test::CreditCardNumbers::Visa,
6513
6486
  :expiration_date => "05/2009"
6514
- }
6487
+ },
6515
6488
  ).transaction
6516
6489
  expect do
6517
6490
  Braintree::Transaction.void!(transaction.id)
@@ -6519,151 +6492,6 @@ describe Braintree::Transaction do
6519
6492
  end
6520
6493
  end
6521
6494
 
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
6495
  describe "status_history" do
6668
6496
  it "returns an array of StatusDetail" do
6669
6497
  transaction = Braintree::Transaction.sale!(
@@ -6671,12 +6499,12 @@ describe Braintree::Transaction do
6671
6499
  :credit_card => {
6672
6500
  :number => Braintree::Test::CreditCardNumbers::Visa,
6673
6501
  :expiration_date => "05/2009"
6674
- }
6502
+ },
6675
6503
  )
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
6504
+ result = Braintree::Transaction.submit_for_settlement!(transaction.id)
6505
+ result.status_history.size.should == 2
6506
+ result.status_history[0].status.should == Braintree::Transaction::Status::Authorized
6507
+ result.status_history[1].status.should == Braintree::Transaction::Status::SubmittedForSettlement
6680
6508
  end
6681
6509
  end
6682
6510
 
@@ -6729,9 +6557,9 @@ describe Braintree::Transaction do
6729
6557
  :credit_card => {
6730
6558
  :number => Braintree::Test::CreditCardNumbers::Visa,
6731
6559
  :expiration_date => "05/2010"
6732
- }
6560
+ },
6733
6561
  )
6734
- transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
6562
+ transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, {:amount => "100.00"}).transaction
6735
6563
  transaction.vault_credit_card.should == customer.credit_cards[0]
6736
6564
  end
6737
6565
 
@@ -6742,7 +6570,7 @@ describe Braintree::Transaction do
6742
6570
  :credit_card => {
6743
6571
  :number => Braintree::Test::CreditCardNumbers::Visa,
6744
6572
  :expiration_date => "05/2010"
6745
- }
6573
+ },
6746
6574
  )
6747
6575
  transaction.vault_credit_card.should == nil
6748
6576
  end
@@ -6754,9 +6582,9 @@ describe Braintree::Transaction do
6754
6582
  :credit_card => {
6755
6583
  :number => Braintree::Test::CreditCardNumbers::Visa,
6756
6584
  :expiration_date => "05/2010"
6757
- }
6585
+ },
6758
6586
  )
6759
- transaction = customer.credit_cards[0].sale(:amount => "100.00").transaction
6587
+ transaction = Braintree::CreditCard.sale(customer.credit_cards[0].token, :amount => "100.00").transaction
6760
6588
  transaction.vault_customer.should == customer
6761
6589
  end
6762
6590
 
@@ -6767,74 +6595,12 @@ describe Braintree::Transaction do
6767
6595
  :credit_card => {
6768
6596
  :number => Braintree::Test::CreditCardNumbers::Visa,
6769
6597
  :expiration_date => "05/2010"
6770
- }
6598
+ },
6771
6599
  )
6772
6600
  transaction.vault_customer.should == nil
6773
6601
  end
6774
6602
  end
6775
6603
 
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
6604
  def create_transaction_to_refund
6839
6605
  transaction = Braintree::Transaction.sale!(
6840
6606
  :amount => Braintree::Test::TransactionAmounts::Authorize,
@@ -6844,7 +6610,7 @@ describe Braintree::Transaction do
6844
6610
  },
6845
6611
  :options => {
6846
6612
  :submit_for_settlement => true
6847
- }
6613
+ },
6848
6614
  )
6849
6615
 
6850
6616
  config = Braintree::Configuration.instantiate
@@ -6858,7 +6624,7 @@ describe Braintree::Transaction do
6858
6624
  :payment_method_nonce => Braintree::Test::Nonce::PayPalOneTimePayment,
6859
6625
  :options => {
6860
6626
  :submit_for_settlement => true
6861
- }
6627
+ },
6862
6628
  )
6863
6629
 
6864
6630
  config = Braintree::Configuration.instantiate
@@ -6874,8 +6640,8 @@ describe Braintree::Transaction do
6874
6640
  :number => Braintree::Test::CreditCardNumbers::Visa,
6875
6641
  :expiration_date => "05/2009"
6876
6642
  },
6877
- :service_fee_amount => '1.00',
6878
- :options => { :hold_in_escrow => true }
6643
+ :service_fee_amount => "1.00",
6644
+ :options => {:hold_in_escrow => true},
6879
6645
  )
6880
6646
 
6881
6647
  config = Braintree::Configuration.instantiate
@@ -6889,7 +6655,7 @@ describe Braintree::Transaction do
6889
6655
  it "can create a transaction with venmo_sdk_payment_method_code" do
6890
6656
  result = Braintree::Transaction.sale(
6891
6657
  :amount => "10.00",
6892
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK.generate_test_payment_method_code(Braintree::Test::CreditCardNumbers::Visa)
6658
+ :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK.generate_test_payment_method_code(Braintree::Test::CreditCardNumbers::Visa),
6893
6659
  )
6894
6660
  result.success?.should == true
6895
6661
  result.transaction.credit_card_details.venmo_sdk?.should == false
@@ -6898,7 +6664,7 @@ describe Braintree::Transaction do
6898
6664
  it "errors when an invalid payment method code is passed" do
6899
6665
  result = Braintree::Transaction.sale(
6900
6666
  :amount => "10.00",
6901
- :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::InvalidPaymentMethodCode
6667
+ :venmo_sdk_payment_method_code => Braintree::Test::VenmoSDK::InvalidPaymentMethodCode,
6902
6668
  )
6903
6669
  result.success?.should == false
6904
6670
  result.message.should include("Invalid VenmoSDK payment method code")
@@ -6916,7 +6682,7 @@ describe Braintree::Transaction do
6916
6682
  },
6917
6683
  :options => {
6918
6684
  :venmo_sdk_session => Braintree::Test::VenmoSDK::Session
6919
- }
6685
+ },
6920
6686
  )
6921
6687
  result.success?.should == true
6922
6688
  result.transaction.credit_card_details.venmo_sdk?.should == false
@@ -6931,7 +6697,7 @@ describe Braintree::Transaction do
6931
6697
  },
6932
6698
  :options => {
6933
6699
  :venmo_sdk_session => Braintree::Test::VenmoSDK::InvalidSession
6934
- }
6700
+ },
6935
6701
  )
6936
6702
  result.success?.should == true
6937
6703
  result.transaction.credit_card_details.venmo_sdk?.should == false
@@ -6943,7 +6709,7 @@ describe Braintree::Transaction do
6943
6709
  it "can create a transaction for a paypal account" do
6944
6710
  result = Braintree::Transaction.sale(
6945
6711
  :amount => "10.00",
6946
- :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment
6712
+ :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
6947
6713
  )
6948
6714
  result.success?.should == true
6949
6715
  result.transaction.paypal_details.payer_email.should == "payer@example.com"
@@ -6958,7 +6724,7 @@ describe Braintree::Transaction do
6958
6724
  :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
6959
6725
  :options => {
6960
6726
  :store_in_vault => true
6961
- }
6727
+ },
6962
6728
  )
6963
6729
  result.success?.should == true
6964
6730
  result.transaction.paypal_details.token.should_not be_nil
@@ -6971,7 +6737,7 @@ describe Braintree::Transaction do
6971
6737
  customer = Braintree::Customer.create!
6972
6738
  result = Braintree::PaymentMethod.create(
6973
6739
  :payment_method_nonce => Braintree::Test::Nonce::PayPalFuturePayment,
6974
- :customer_id => customer.id
6740
+ :customer_id => customer.id,
6975
6741
  )
6976
6742
 
6977
6743
  result.should be_success
@@ -6981,7 +6747,7 @@ describe Braintree::Transaction do
6981
6747
  result = Braintree::Transaction.sale(
6982
6748
  :amount => "100",
6983
6749
  :customer_id => customer.id,
6984
- :payment_method_token => payment_method_token
6750
+ :payment_method_token => payment_method_token,
6985
6751
  )
6986
6752
 
6987
6753
  result.should be_success
@@ -6996,7 +6762,7 @@ describe Braintree::Transaction do
6996
6762
  nonce = nonce_for_paypal_account(:token => "TOKEN")
6997
6763
  result = Braintree::Transaction.sale(
6998
6764
  :amount => "10.00",
6999
- :payment_method_nonce => nonce
6765
+ :payment_method_nonce => nonce,
7000
6766
  )
7001
6767
  result.should_not be_success
7002
6768
  result.errors.for(:transaction).for(:paypal_account).first.code.should == Braintree::ErrorCodes::PayPalAccount::IncompletePayPalAccount
@@ -7011,7 +6777,7 @@ describe Braintree::Transaction do
7011
6777
  :public_key => "oauth_app_partner_user_public_key",
7012
6778
  :private_key => "oauth_app_partner_user_private_key",
7013
6779
  :environment => Braintree::Configuration.environment,
7014
- :logger => Logger.new("/dev/null")
6780
+ :logger => Logger.new("/dev/null"),
7015
6781
  )
7016
6782
  @customer = @partner_merchant_gateway.customer.create(
7017
6783
  :first_name => "Joe",
@@ -7020,12 +6786,12 @@ describe Braintree::Transaction do
7020
6786
  :email => "joe@example.com",
7021
6787
  :phone => "312.555.1234",
7022
6788
  :fax => "614.555.5678",
7023
- :website => "www.example.com"
6789
+ :website => "www.example.com",
7024
6790
  ).customer
7025
6791
  @address = @partner_merchant_gateway.address.create(
7026
6792
  :customer_id => @customer.id,
7027
6793
  :first_name => "Testy",
7028
- :last_name => "McTesterson"
6794
+ :last_name => "McTesterson",
7029
6795
  ).address
7030
6796
  @credit_card = @partner_merchant_gateway.credit_card.create(
7031
6797
  :customer_id => @customer.id,
@@ -7036,13 +6802,13 @@ describe Braintree::Transaction do
7036
6802
  :first_name => "Adam",
7037
6803
  :last_name => "Davis",
7038
6804
  :postal_code => "95131"
7039
- }
6805
+ },
7040
6806
  ).credit_card
7041
6807
 
7042
6808
  oauth_gateway = Braintree::Gateway.new(
7043
6809
  :client_id => "client_id$#{Braintree::Configuration.environment}$integration_client_id",
7044
6810
  :client_secret => "client_secret$#{Braintree::Configuration.environment}$integration_client_secret",
7045
- :logger => Logger.new("/dev/null")
6811
+ :logger => Logger.new("/dev/null"),
7046
6812
  )
7047
6813
  access_token = Braintree::OAuthTestHelper.create_token(oauth_gateway, {
7048
6814
  :merchant_public_id => "integration_merchant_id",
@@ -7051,7 +6817,7 @@ describe Braintree::Transaction do
7051
6817
 
7052
6818
  @granting_gateway = Braintree::Gateway.new(
7053
6819
  :access_token => access_token,
7054
- :logger => Logger.new("/dev/null")
6820
+ :logger => Logger.new("/dev/null"),
7055
6821
  )
7056
6822
 
7057
6823
  end
@@ -7061,7 +6827,7 @@ describe Braintree::Transaction do
7061
6827
 
7062
6828
  result = Braintree::Transaction.sale(
7063
6829
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
7064
- :amount => Braintree::Test::TransactionAmounts::Authorize
6830
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7065
6831
  )
7066
6832
  result.transaction.facilitated_details.merchant_id.should == "integration_merchant_id"
7067
6833
  result.transaction.facilitated_details.merchant_name.should == "14ladders"
@@ -7077,7 +6843,7 @@ describe Braintree::Transaction do
7077
6843
 
7078
6844
  result = Braintree::Transaction.sale(
7079
6845
  :payment_method_nonce => grant_result.payment_method_nonce.nonce,
7080
- :amount => Braintree::Test::TransactionAmounts::Authorize
6846
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7081
6847
  )
7082
6848
 
7083
6849
  result.transaction.billing_details.postal_code == "95131"
@@ -7089,7 +6855,7 @@ describe Braintree::Transaction do
7089
6855
  :shared_customer_id => @customer.id,
7090
6856
  :shared_shipping_address_id => @address.id,
7091
6857
  :shared_billing_address_id => @address.id,
7092
- :amount => Braintree::Test::TransactionAmounts::Authorize
6858
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7093
6859
  )
7094
6860
  result.success?.should == true
7095
6861
  result.transaction.shipping_details.first_name.should == @address.first_name
@@ -7099,7 +6865,7 @@ describe Braintree::Transaction do
7099
6865
  it "facilitated details are returned on transaction created via a shared_payment_method_token" do
7100
6866
  result = @granting_gateway.transaction.sale(
7101
6867
  :shared_payment_method_token => @credit_card.token,
7102
- :amount => Braintree::Test::TransactionAmounts::Authorize
6868
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7103
6869
  )
7104
6870
  result.transaction.facilitated_details.merchant_id.should == "integration_merchant_id"
7105
6871
  result.transaction.facilitated_details.merchant_name.should == "14ladders"
@@ -7111,12 +6877,12 @@ describe Braintree::Transaction do
7111
6877
 
7112
6878
  it "facilitated details are returned on transaction created via a shared_payment_method_nonce" do
7113
6879
  shared_nonce = @partner_merchant_gateway.payment_method_nonce.create(
7114
- @credit_card.token
6880
+ @credit_card.token,
7115
6881
  ).payment_method_nonce.nonce
7116
6882
 
7117
6883
  result = @granting_gateway.transaction.sale(
7118
6884
  :shared_payment_method_nonce => shared_nonce,
7119
- :amount => Braintree::Test::TransactionAmounts::Authorize
6885
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
7120
6886
  )
7121
6887
  result.transaction.facilitated_details.merchant_id.should == "integration_merchant_id"
7122
6888
  result.transaction.facilitated_details.merchant_name.should == "14ladders"
@@ -7129,7 +6895,7 @@ describe Braintree::Transaction do
7129
6895
 
7130
6896
  context "paypal here" do
7131
6897
  it "gets the details of an auth/capture transaction" do
7132
- result = Braintree::Transaction.find('paypal_here_auth_capture_id')
6898
+ result = Braintree::Transaction.find("paypal_here_auth_capture_id")
7133
6899
  result.payment_instrument_type.should eq(Braintree::PaymentInstrumentType::PayPalHere)
7134
6900
  result.paypal_here_details.should_not be_nil
7135
6901
 
@@ -7146,7 +6912,7 @@ describe Braintree::Transaction do
7146
6912
  end
7147
6913
 
7148
6914
  it "gets the details of a sale transaction" do
7149
- result = Braintree::Transaction.find('paypal_here_sale_id')
6915
+ result = Braintree::Transaction.find("paypal_here_sale_id")
7150
6916
  result.paypal_here_details.should_not be_nil
7151
6917
 
7152
6918
  details = result.paypal_here_details
@@ -7154,7 +6920,7 @@ describe Braintree::Transaction do
7154
6920
  end
7155
6921
 
7156
6922
  it "gets the details of a refunded sale transaction" do
7157
- result = Braintree::Transaction.find('paypal_here_refund_id')
6923
+ result = Braintree::Transaction.find("paypal_here_refund_id")
7158
6924
  result.paypal_here_details.should_not be_nil
7159
6925
 
7160
6926
  details = result.paypal_here_details
@@ -7179,7 +6945,7 @@ describe Braintree::Transaction do
7179
6945
  customer = Braintree::Customer.create!
7180
6946
  result = Braintree::PaymentMethod.create(
7181
6947
  :payment_method_nonce => Braintree::Test::Nonce::TransactableVisa,
7182
- :customer_id => customer.id
6948
+ :customer_id => customer.id,
7183
6949
  )
7184
6950
  payment_method_token = result.payment_method.token
7185
6951
 
@@ -7194,4 +6960,299 @@ describe Braintree::Transaction do
7194
6960
  transaction.processed_with_network_token?.should == false
7195
6961
  end
7196
6962
  end
6963
+
6964
+ describe "retried flag presence in response" do
6965
+ it "creates a retried transaction" do
6966
+ result = Braintree::Transaction.sale(
6967
+ :amount => Braintree::Test::TransactionAmounts::Decline,
6968
+ :payment_method_token => "network_tokenized_credit_card",
6969
+ )
6970
+ transaction = result.transaction
6971
+ transaction.retried.should == true
6972
+ end
6973
+
6974
+ it "creates a non-retried transaction" do
6975
+ result = Braintree::Transaction.sale(
6976
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
6977
+ :payment_method_token => "network_tokenized_credit_card",
6978
+ )
6979
+ transaction = result.transaction
6980
+ transaction.retried.should == nil
6981
+ end
6982
+
6983
+ it "creates a transaction that is ineligible for retries" do
6984
+ result = Braintree::Transaction.sale(
6985
+ :merchant_account_id => SpecHelper::NonDefaultMerchantAccountId,
6986
+ :credit_card => {
6987
+ :number => Braintree::Test::CreditCardNumbers::Visa,
6988
+ :expiration_date => "05/2009"
6989
+ },
6990
+ :amount => Braintree::Test::TransactionAmounts::Authorize,
6991
+ )
6992
+ transaction = result.transaction
6993
+ transaction.retried.should == nil
6994
+ end
6995
+ end
6996
+
6997
+ describe "installments" do
6998
+ it "creates a transaction with an installment count" do
6999
+ result = Braintree::Transaction.create(
7000
+ :type => "sale",
7001
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
7002
+ :credit_card => {
7003
+ :number => Braintree::Test::CreditCardNumbers::Visa,
7004
+ :expiration_date => "05/2009"
7005
+ },
7006
+ :amount => "100.01",
7007
+ :installments => {
7008
+ :count => 12,
7009
+ },
7010
+ )
7011
+
7012
+ expect(result.success?).to eq(true)
7013
+ expect(result.transaction.installment_count).to eq(12)
7014
+ end
7015
+
7016
+ it "creates a transaction with a installments during capture" do
7017
+ result = Braintree::Transaction.create(
7018
+ :type => "sale",
7019
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
7020
+ :credit_card => {
7021
+ :number => Braintree::Test::CreditCardNumbers::Visa,
7022
+ :expiration_date => "05/2009"
7023
+ },
7024
+ :amount => "100.01",
7025
+ :installments => {
7026
+ :count => 12,
7027
+ },
7028
+ :options => {
7029
+ :submit_for_settlement => true,
7030
+ },
7031
+ )
7032
+
7033
+ expect(result.success?).to eq(true)
7034
+ transaction = result.transaction
7035
+ expect(transaction.installment_count).to eq(12)
7036
+
7037
+ installments = transaction.installments
7038
+ expect(installments.map(&:id)).to match_array((1..12).map { |i| "#{transaction.id}_INST_#{i}" })
7039
+ expect(installments.map(&:amount)).to match_array([BigDecimal("8.33")] * 11 + [BigDecimal("8.38")])
7040
+ end
7041
+
7042
+ it "can refund a transaction with installments" do
7043
+ sale_result = Braintree::Transaction.create(
7044
+ :type => "sale",
7045
+ :merchant_account_id => SpecHelper::CardProcessorBRLMerchantAccountId,
7046
+ :credit_card => {
7047
+ :number => Braintree::Test::CreditCardNumbers::Visa,
7048
+ :expiration_date => "05/2009"
7049
+ },
7050
+ :amount => "100.01",
7051
+ :installments => {
7052
+ :count => 12,
7053
+ },
7054
+ :options => {
7055
+ :submit_for_settlement => true,
7056
+ },
7057
+ )
7058
+
7059
+ expect(sale_result.success?).to eq(true)
7060
+ sale_transaction = sale_result.transaction
7061
+
7062
+ refund_result = Braintree::Transaction.refund(sale_transaction.id, "49.99")
7063
+
7064
+ expect(refund_result.success?).to eq(true)
7065
+ refund_transaction = refund_result.transaction
7066
+ installments = refund_transaction.refunded_installments
7067
+
7068
+ (1..11).each do |i|
7069
+ installment = installments.find { |installment| installment.id == "#{sale_transaction.id}_INST_#{i}" }
7070
+
7071
+ expect(installment.amount).to eq(BigDecimal("8.33"))
7072
+ expect(installment.adjustments.map(&:amount)).to match_array([BigDecimal("-4.16")])
7073
+ expect(installment.adjustments.map(&:kind)).to match_array([Braintree::Transaction::Installment::Adjustment::Kind::Refund])
7074
+ end
7075
+
7076
+ installment = installments.find { |installment| installment.id == "#{sale_transaction.id}_INST_12" }
7077
+
7078
+ expect(installment.amount).to eq(BigDecimal("8.38"))
7079
+ expect(installment.adjustments.map(&:amount)).to match_array([BigDecimal("-4.23")])
7080
+ expect(installment.adjustments.map(&:kind)).to match_array([Braintree::Transaction::Installment::Adjustment::Kind::Refund])
7081
+ end
7082
+ end
7083
+
7084
+ describe "Manual Key Entry" do
7085
+ context "with correct encrypted payment reader card details" do
7086
+ it "returns a success response" do
7087
+ result = Braintree::Transaction.sale(
7088
+ :amount => "10.00",
7089
+ :credit_card => {
7090
+ :payment_reader_card_details => {
7091
+ :encrypted_card_data => "8F34DFB312DC79C24FD5320622F3E11682D79E6B0C0FD881",
7092
+ :key_serial_number => "FFFFFF02000572A00005",
7093
+ },
7094
+ },
7095
+ )
7096
+
7097
+ expect(result).to be_success
7098
+ end
7099
+ end
7100
+
7101
+ context "with invalid encrypted payment reader card details" do
7102
+ it "returns a failure response" do
7103
+ result = Braintree::Transaction.sale(
7104
+ :amount => "10.00",
7105
+ :credit_card => {
7106
+ :payment_reader_card_details => {
7107
+ :encrypted_card_data => "invalid",
7108
+ :key_serial_number => "invalid",
7109
+ },
7110
+ },
7111
+ )
7112
+
7113
+ expect(result).not_to be_success
7114
+ expect(result.errors.for(:transaction).first.code)
7115
+ .to eq(Braintree::ErrorCodes::Transaction::PaymentInstrumentNotSupportedByMerchantAccount)
7116
+ end
7117
+ end
7118
+ end
7119
+
7120
+ describe "Adjust Authorization" do
7121
+ let(:first_data_master_transaction_params) do
7122
+ {
7123
+ :merchant_account_id => SpecHelper::FakeFirstDataMerchantAccountId,
7124
+ :amount => "75.50",
7125
+ :credit_card => {
7126
+ :number => "5105105105105100",
7127
+ :expiration_date => "05/2012"
7128
+ }
7129
+ }
7130
+ end
7131
+ let(:first_data_visa_transaction_params) do
7132
+ {
7133
+ :merchant_account_id => SpecHelper::FakeFirstDataMerchantAccountId,
7134
+ :amount => "75.50",
7135
+ :credit_card => {
7136
+ :number => Braintree::Test::CreditCardNumbers::Visa,
7137
+ :expiration_date => "06/2009"
7138
+ }
7139
+ }
7140
+ end
7141
+ context "successful authorization" do
7142
+ it "returns success response" do
7143
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params)
7144
+ expect(initial_transaction.success?).to eq(true)
7145
+
7146
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7147
+ initial_transaction.transaction.id, "85.50"
7148
+ )
7149
+
7150
+ expect(adjustment_transaction.success?).to eq(true)
7151
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("85.50"))
7152
+ end
7153
+ end
7154
+
7155
+ context "unsuccessful authorization" do
7156
+ it "returns failure, when processor does not support multi auth adjustment" do
7157
+ initial_transaction = Braintree::Transaction.sale(
7158
+ :merchant_account_id => SpecHelper::DefaultMerchantAccountId,
7159
+ :amount => "75.50",
7160
+ :credit_card => {
7161
+ :number => Braintree::Test::CreditCardNumbers::Visa,
7162
+ :expiration_date => "06/2009"
7163
+ },
7164
+ )
7165
+ expect(initial_transaction.success?).to eq(true)
7166
+
7167
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7168
+ initial_transaction.transaction.id, "85.50"
7169
+ )
7170
+
7171
+
7172
+ expect(adjustment_transaction.success?).to eq(false)
7173
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7174
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::ProcessorDoesNotSupportAuthAdjustment)
7175
+ end
7176
+
7177
+ it "returns failure response, when adjusted amount submitted is zero" do
7178
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params)
7179
+ expect(initial_transaction.success?).to eq(true)
7180
+
7181
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7182
+ initial_transaction.transaction.id, "0.0"
7183
+ )
7184
+
7185
+ expect(adjustment_transaction.success?).to eq(false)
7186
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7187
+ expect(adjustment_transaction.errors.for(:authorization_adjustment).on(:amount).first.code).to eq(Braintree::ErrorCodes::Transaction::AdjustmentAmountMustBeGreaterThanZero)
7188
+ end
7189
+
7190
+ it "returns failure response, when adjusted amount submitted same as authorized amount" do
7191
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params)
7192
+ expect(initial_transaction.success?).to eq(true)
7193
+
7194
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7195
+ initial_transaction.transaction.id, "75.50"
7196
+ )
7197
+
7198
+ expect(adjustment_transaction.success?).to eq(false)
7199
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7200
+ expect(adjustment_transaction.errors.for(:authorization_adjustment).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::NoNetAmountToPerformAuthAdjustment)
7201
+ end
7202
+
7203
+ it "returns failure, when transaction status is not authorized" do
7204
+ additional_params = {:options => {:submit_for_settlement => true}}
7205
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params.merge(additional_params))
7206
+ expect(initial_transaction.success?).to eq(true)
7207
+
7208
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7209
+ initial_transaction.transaction.id, "85.50"
7210
+ )
7211
+
7212
+ expect(adjustment_transaction.success?).to eq(false)
7213
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7214
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::TransactionMustBeInStateAuthorized)
7215
+ end
7216
+
7217
+ it "returns failure, when transaction authorization type final or undefined" do
7218
+ additional_params = {:transaction_source => "recurring_first"}
7219
+ initial_transaction = Braintree::Transaction.sale(first_data_master_transaction_params.merge(additional_params))
7220
+ expect(initial_transaction.success?).to eq(true)
7221
+
7222
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7223
+ initial_transaction.transaction.id, "85.50"
7224
+ )
7225
+
7226
+ expect(adjustment_transaction.success?).to eq(false)
7227
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7228
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::TransactionIsNotEligibleForAdjustment)
7229
+ end
7230
+
7231
+ it "returns failure, when processor does not support incremental auth" do
7232
+ initial_transaction = Braintree::Transaction.sale(first_data_visa_transaction_params)
7233
+ expect(initial_transaction.success?).to eq(true)
7234
+
7235
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7236
+ initial_transaction.transaction.id, "85.50"
7237
+ )
7238
+
7239
+ expect(adjustment_transaction.success?).to eq(false)
7240
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7241
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::ProcessorDoesNotSupportIncrementalAuth)
7242
+ end
7243
+
7244
+ it "returns failure, when processor does not support auth reversal" do
7245
+ initial_transaction = Braintree::Transaction.sale(first_data_visa_transaction_params)
7246
+ expect(initial_transaction.success?).to eq(true)
7247
+
7248
+ adjustment_transaction = Braintree::Transaction.adjust_authorization(
7249
+ initial_transaction.transaction.id, "65.50"
7250
+ )
7251
+
7252
+ expect(adjustment_transaction.success?).to eq(false)
7253
+ expect(adjustment_transaction.transaction.amount.should).to eq(BigDecimal("75.50"))
7254
+ expect(adjustment_transaction.errors.for(:transaction).on(:base).first.code).to eq(Braintree::ErrorCodes::Transaction::ProcessorDoesNotSupportPartialAuthReversal)
7255
+ end
7256
+ end
7257
+ end
7197
7258
  end