braintree 2.104.1 → 3.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/braintree.gemspec +7 -4
  4. data/lib/braintree.rb +7 -18
  5. data/lib/braintree/account_updater_daily_report.rb +1 -1
  6. data/lib/braintree/address.rb +1 -23
  7. data/lib/braintree/apple_pay.rb +1 -1
  8. data/lib/braintree/apple_pay_card.rb +1 -1
  9. data/lib/braintree/apple_pay_options.rb +1 -1
  10. data/lib/braintree/authorization_adjustment.rb +1 -1
  11. data/lib/braintree/base_module.rb +6 -0
  12. data/lib/braintree/bin_data.rb +9 -2
  13. data/lib/braintree/client_token.rb +1 -1
  14. data/lib/braintree/configuration.rb +12 -12
  15. data/lib/braintree/connected_merchant_paypal_status_changed.rb +1 -1
  16. data/lib/braintree/connected_merchant_status_transitioned.rb +1 -1
  17. data/lib/braintree/credit_card.rb +2 -77
  18. data/lib/braintree/credit_card_gateway.rb +7 -36
  19. data/lib/braintree/credit_card_verification.rb +18 -5
  20. data/lib/braintree/credit_card_verification_search.rb +1 -1
  21. data/lib/braintree/customer.rb +5 -76
  22. data/lib/braintree/customer_gateway.rb +0 -23
  23. data/lib/braintree/customer_search.rb +1 -1
  24. data/lib/braintree/disbursement.rb +1 -1
  25. data/lib/braintree/dispute.rb +2 -8
  26. data/lib/braintree/dispute/{history_event.rb → status_history.rb} +3 -1
  27. data/lib/braintree/dispute_gateway.rb +4 -9
  28. data/lib/braintree/dispute_search.rb +2 -2
  29. data/lib/braintree/document_upload.rb +1 -1
  30. data/lib/braintree/error_codes.rb +151 -170
  31. data/lib/braintree/exceptions.rb +5 -3
  32. data/lib/braintree/gateway.rb +0 -14
  33. data/lib/braintree/{android_pay_card.rb → google_pay_card.rb} +2 -3
  34. data/lib/braintree/granted_payment_instrument_update.rb +1 -1
  35. data/lib/braintree/graphql_client.rb +7 -7
  36. data/lib/braintree/http.rb +3 -3
  37. data/lib/braintree/local_payment_completed.rb +1 -1
  38. data/lib/braintree/local_payment_reversed.rb +19 -0
  39. data/lib/braintree/merchant.rb +1 -1
  40. data/lib/braintree/merchant_account.rb +1 -1
  41. data/lib/braintree/merchant_account_gateway.rb +3 -1
  42. data/lib/braintree/merchant_gateway.rb +1 -1
  43. data/lib/braintree/modification.rb +1 -1
  44. data/lib/braintree/oauth_credentials.rb +1 -1
  45. data/lib/braintree/oauth_gateway.rb +5 -5
  46. data/lib/braintree/payment_instrument_type.rb +10 -14
  47. data/lib/braintree/payment_method_gateway.rb +8 -13
  48. data/lib/braintree/payment_method_nonce_gateway.rb +1 -1
  49. data/lib/braintree/payment_method_parser.rb +1 -8
  50. data/lib/braintree/plan.rb +1 -1
  51. data/lib/braintree/processor_response_types.rb +3 -3
  52. data/lib/braintree/resource_collection.rb +8 -3
  53. data/lib/braintree/revoked_payment_method_metadata.rb +1 -1
  54. data/lib/braintree/risk_data.rb +3 -1
  55. data/lib/braintree/samsung_pay_card.rb +1 -1
  56. data/lib/braintree/settlement_batch_summary.rb +2 -2
  57. data/lib/braintree/subscription.rb +11 -11
  58. data/lib/braintree/successful_result.rb +0 -1
  59. data/lib/braintree/test/credit_card.rb +1 -0
  60. data/lib/braintree/test/nonce.rb +4 -23
  61. data/lib/braintree/three_d_secure_info.rb +22 -12
  62. data/lib/braintree/transaction.rb +44 -104
  63. data/lib/braintree/transaction/disbursement_details.rb +1 -0
  64. data/lib/braintree/transaction/{android_pay_details.rb → google_pay_details.rb} +1 -1
  65. data/lib/braintree/transaction/installment.rb +28 -0
  66. data/lib/braintree/transaction/installment/adjustment.rb +33 -0
  67. data/lib/braintree/transaction/paypal_details.rb +1 -0
  68. data/lib/braintree/transaction/subscription_details.rb +2 -0
  69. data/lib/braintree/transaction_gateway.rb +37 -25
  70. data/lib/braintree/transaction_line_item.rb +1 -1
  71. data/lib/braintree/transaction_search.rb +3 -2
  72. data/lib/braintree/unknown_payment_method.rb +1 -1
  73. data/lib/braintree/us_bank_account.rb +3 -3
  74. data/lib/braintree/us_bank_account_verification.rb +1 -1
  75. data/lib/braintree/us_bank_account_verification_gateway.rb +1 -1
  76. data/lib/braintree/util.rb +21 -6
  77. data/lib/braintree/venmo_account.rb +1 -1
  78. data/lib/braintree/version.rb +3 -3
  79. data/lib/braintree/visa_checkout_card.rb +2 -2
  80. data/lib/braintree/webhook_notification.rb +28 -29
  81. data/lib/braintree/webhook_notification_gateway.rb +5 -5
  82. data/lib/braintree/webhook_testing_gateway.rb +10 -43
  83. data/lib/braintree/xml/generator.rb +5 -4
  84. data/lib/braintree/xml/libxml.rb +1 -0
  85. data/lib/braintree/xml/parser.rb +21 -44
  86. data/spec/integration/braintree/add_on_spec.rb +1 -1
  87. data/spec/integration/braintree/address_spec.rb +26 -113
  88. data/spec/integration/braintree/advanced_search_spec.rb +45 -45
  89. data/spec/integration/braintree/apple_pay_spec.rb +3 -3
  90. data/spec/integration/braintree/braintree_gateway_spec.rb +2 -1
  91. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -14
  92. data/spec/integration/braintree/client_api/spec_helper.rb +5 -31
  93. data/spec/integration/braintree/credit_card_spec.rb +130 -593
  94. data/spec/integration/braintree/credit_card_verification_search_spec.rb +2 -2
  95. data/spec/integration/braintree/credit_card_verification_spec.rb +1 -1
  96. data/spec/integration/braintree/customer_search_spec.rb +8 -8
  97. data/spec/integration/braintree/customer_spec.rb +336 -509
  98. data/spec/integration/braintree/dispute_search_spec.rb +6 -6
  99. data/spec/integration/braintree/dispute_spec.rb +6 -7
  100. data/spec/integration/braintree/error_codes_spec.rb +1 -1
  101. data/spec/integration/braintree/http_spec.rb +2 -2
  102. data/spec/integration/braintree/merchant_account_spec.rb +25 -26
  103. data/spec/integration/braintree/merchant_spec.rb +14 -14
  104. data/spec/integration/braintree/oauth_spec.rb +11 -11
  105. data/spec/integration/braintree/payment_method_nonce_spec.rb +12 -12
  106. data/spec/integration/braintree/payment_method_spec.rb +403 -269
  107. data/spec/integration/braintree/payment_method_us_bank_account_spec.rb +17 -13
  108. data/spec/integration/braintree/paypal_account_spec.rb +28 -28
  109. data/spec/integration/braintree/samsung_pay_card_spec.rb +9 -9
  110. data/spec/integration/braintree/settlement_batch_summary_spec.rb +8 -8
  111. data/spec/integration/braintree/subscription_spec.rb +144 -149
  112. data/spec/integration/braintree/test/transaction_amounts_spec.rb +2 -2
  113. data/spec/integration/braintree/test_transaction_spec.rb +10 -10
  114. data/spec/integration/braintree/transaction_search_spec.rb +96 -70
  115. data/spec/integration/braintree/transaction_spec.rb +832 -904
  116. data/spec/integration/braintree/transaction_us_bank_account_spec.rb +32 -26
  117. data/spec/integration/braintree/us_bank_account_spec.rb +6 -6
  118. data/spec/integration/braintree/us_bank_account_verification_search_spec.rb +7 -7
  119. data/spec/integration/braintree/us_bank_account_verification_spec.rb +8 -8
  120. data/spec/integration/braintree/visa_checkout_card_spec.rb +5 -5
  121. data/spec/integration/spec_helper.rb +10 -7
  122. data/spec/oauth_test_helper.rb +1 -1
  123. data/spec/script/httpsd.rb +6 -6
  124. data/spec/spec_helper.rb +6 -14
  125. data/spec/unit/braintree/address_spec.rb +1 -9
  126. data/spec/unit/braintree/apple_pay_card_spec.rb +1 -1
  127. data/spec/unit/braintree/client_token_spec.rb +2 -2
  128. data/spec/unit/braintree/configuration_spec.rb +42 -42
  129. data/spec/unit/braintree/credit_card_spec.rb +9 -28
  130. data/spec/unit/braintree/credit_card_verification_search_spec.rb +1 -1
  131. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -4
  132. data/spec/unit/braintree/customer_spec.rb +5 -16
  133. data/spec/unit/braintree/disbursement_spec.rb +7 -7
  134. data/spec/unit/braintree/dispute_spec.rb +9 -20
  135. data/spec/unit/braintree/error_result_spec.rb +5 -5
  136. data/spec/unit/braintree/errors_spec.rb +8 -8
  137. data/spec/unit/braintree/http_spec.rb +8 -8
  138. data/spec/unit/braintree/merchant_account_spec.rb +1 -1
  139. data/spec/unit/braintree/payment_method_spec.rb +1 -1
  140. data/spec/unit/braintree/paypal_account_spec.rb +2 -2
  141. data/spec/unit/braintree/resource_collection_spec.rb +30 -1
  142. data/spec/unit/braintree/risk_data_spec.rb +9 -5
  143. data/spec/unit/braintree/subscription_search_spec.rb +1 -1
  144. data/spec/unit/braintree/successful_result_spec.rb +1 -1
  145. data/spec/unit/braintree/three_d_secure_info_spec.rb +32 -14
  146. data/spec/unit/braintree/transaction/credit_card_details_spec.rb +3 -3
  147. data/spec/unit/braintree/transaction/customer_details_spec.rb +1 -1
  148. data/spec/unit/braintree/transaction/deposit_details_spec.rb +2 -2
  149. data/spec/unit/braintree/transaction/installment_spec.rb +25 -0
  150. data/spec/unit/braintree/transaction/paypal_details_spec.rb +3 -1
  151. data/spec/unit/braintree/transaction_search_spec.rb +12 -12
  152. data/spec/unit/braintree/transaction_spec.rb +25 -51
  153. data/spec/unit/braintree/util_spec.rb +55 -21
  154. data/spec/unit/braintree/validation_error_collection_spec.rb +36 -36
  155. data/spec/unit/braintree/webhook_notification_spec.rb +73 -57
  156. data/spec/unit/braintree/xml/parser_spec.rb +21 -16
  157. data/spec/unit/braintree/xml_spec.rb +31 -31
  158. metadata +30 -31
  159. data/lib/braintree/amex_express_checkout_card.rb +0 -40
  160. data/lib/braintree/coinbase_account.rb +0 -34
  161. data/lib/braintree/europe_bank_account.rb +0 -36
  162. data/lib/braintree/europe_bank_account_gateway.rb +0 -17
  163. data/lib/braintree/ideal_payment.rb +0 -61
  164. data/lib/braintree/ideal_payment_gateway.rb +0 -19
  165. data/lib/braintree/masterpass_card.rb +0 -83
  166. data/lib/braintree/settlement_batch.rb +0 -0
  167. data/lib/braintree/transaction/amex_express_checkout_details.rb +0 -21
  168. data/lib/braintree/transaction/coinbase_details.rb +0 -16
  169. data/lib/braintree/transaction/ideal_payment_details.rb +0 -19
  170. data/lib/braintree/transaction/masterpass_card_details.rb +0 -49
  171. data/lib/braintree/transparent_redirect.rb +0 -40
  172. data/lib/braintree/transparent_redirect_gateway.rb +0 -105
  173. data/lib/braintree/xml/rexml.rb +0 -71
  174. data/spec/hacks/tcp_socket.rb +0 -18
  175. data/spec/integration/braintree/coinbase_spec.rb +0 -34
  176. data/spec/integration/braintree/masterpass_card_spec.rb +0 -97
  177. data/spec/integration/braintree/transparent_redirect_spec.rb +0 -268
  178. data/spec/unit/braintree/transparent_redirect_spec.rb +0 -223
  179. data/spec/unit/braintree/xml/rexml_spec.rb +0 -51
@@ -13,6 +13,7 @@ module Braintree
13
13
 
14
14
  def initialize(attributes)
15
15
  set_instance_variables_from_hash attributes unless attributes.nil?
16
+ @disbursement_date = Date.parse(disbursement_date) unless disbursement_date.nil?
16
17
  end
17
18
 
18
19
  def funds_held?
@@ -1,6 +1,6 @@
1
1
  module Braintree
2
2
  class Transaction
3
- class AndroidPayDetails
3
+ class GooglePayDetails
4
4
  include BaseModule
5
5
 
6
6
  attr_reader :bin
@@ -0,0 +1,28 @@
1
+ module Braintree
2
+ class Transaction
3
+ class Installment
4
+ include BaseModule
5
+
6
+ attr_reader :id
7
+ attr_reader :amount
8
+ attr_reader :projected_disbursement_date
9
+ attr_reader :actual_disbursement_date
10
+ attr_reader :adjustments
11
+
12
+ def initialize(attributes)
13
+ set_instance_variables_from_hash attributes unless attributes.nil?
14
+ @amount = Util.to_big_decimal(amount)
15
+ adjustments.map! { |attrs| Adjustment.new(attrs) } if adjustments
16
+ end
17
+
18
+ def inspect
19
+ attrs = [:id, :amount, :projected_disbursement_date, :actual_disbursement_date, :adjustments]
20
+ formatted_attrs = attrs.map do |attr|
21
+ "#{attr}: #{send(attr).inspect}"
22
+ end
23
+
24
+ "#<#{formatted_attrs.join(", ")}>"
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ module Braintree
2
+ class Transaction
3
+ class Installment
4
+ class Adjustment
5
+ include BaseModule
6
+
7
+ module Kind
8
+ Refund = "REFUND"
9
+ Dispute = "DISPUTE"
10
+ end
11
+
12
+ attr_reader :amount
13
+ attr_reader :kind
14
+ attr_reader :projected_disbursement_date
15
+ attr_reader :actual_disbursement_date
16
+
17
+ def initialize(attributes)
18
+ set_instance_variables_from_hash attributes unless attributes.nil?
19
+ @amount = Util.to_big_decimal(amount)
20
+ end
21
+
22
+ def inspect
23
+ attrs = [:amount, :kind, :projected_disbursement_date, :actual_disbursement_date]
24
+ formatted_attrs = attrs.map do |attr|
25
+ "#{attr}: #{send(attr).inspect}"
26
+ end
27
+
28
+ "#<#{formatted_attrs.join(", ")}>"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -4,6 +4,7 @@ module Braintree
4
4
  include BaseModule
5
5
 
6
6
  attr_reader :authorization_id
7
+ attr_reader :billing_agreement_id
7
8
  attr_reader :capture_id
8
9
  attr_reader :custom_field
9
10
  attr_reader :debug_id
@@ -8,6 +8,8 @@ module Braintree
8
8
 
9
9
  def initialize(attributes)
10
10
  set_instance_variables_from_hash attributes unless attributes.nil?
11
+ @billing_period_start_date = Date.parse(billing_period_start_date) unless billing_period_start_date.nil?
12
+ @billing_period_end_date = Date.parse(billing_period_end_date) unless billing_period_end_date.nil?
11
13
  end
12
14
  end
13
15
  end
@@ -52,19 +52,8 @@ module Braintree
52
52
  return_object_or_raise(:transaction) { clone_transaction(*args) }
53
53
  end
54
54
 
55
- # Deprecated
56
- def create_from_transparent_redirect(query_string)
57
- params = @gateway.transparent_redirect.parse_and_validate_query_string query_string
58
- _do_create("/transactions/all/confirm_transparent_redirect_request", :id => params[:id])
59
- end
60
-
61
- def create_transaction_url
62
- warn "[DEPRECATED] Transaction.create_transaction_url is deprecated. Please use TransparentRedirect.url"
63
- "#{@config.base_merchant_url}/transactions/all/create_via_transparent_redirect_request"
64
- end
65
-
66
55
  def credit(attributes)
67
- create(attributes.merge(:type => 'credit'))
56
+ create(attributes.merge(:type => "credit"))
68
57
  end
69
58
 
70
59
  def credit!(*args)
@@ -83,7 +72,7 @@ module Braintree
83
72
  options = if amount_or_options.is_a?(Hash)
84
73
  amount_or_options
85
74
  else
86
- { :amount => amount_or_options }
75
+ {:amount => amount_or_options}
87
76
  end
88
77
 
89
78
  Util.verify_keys(TransactionGateway._refund_signature, options)
@@ -108,7 +97,7 @@ module Braintree
108
97
  end
109
98
 
110
99
  def sale(attributes)
111
- create(attributes.merge(:type => 'sale'))
100
+ create(attributes.merge(:type => "sale"))
112
101
  end
113
102
 
114
103
  def sale!(*args)
@@ -124,7 +113,7 @@ module Braintree
124
113
  if response.has_key?(:search_results)
125
114
  ResourceCollection.new(response) { |ids| _fetch_transactions(search, ids) }
126
115
  else
127
- raise DownForMaintenanceError
116
+ raise UnexpectedError, "expected :search_results"
128
117
  end
129
118
  end
130
119
 
@@ -150,6 +139,18 @@ module Braintree
150
139
  return_object_or_raise(:transaction) { submit_for_settlement(*args) }
151
140
  end
152
141
 
142
+ def adjust_authorization(transaction_id, amount)
143
+ raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/
144
+ Util.verify_keys(TransactionGateway._adjust_authorization_signature, {})
145
+ transaction_params = {:amount => amount}
146
+ response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/adjust_authorization", :transaction => transaction_params)
147
+ _handle_transaction_response(response)
148
+ end
149
+
150
+ def adjust_authorization!(*args)
151
+ return_object_or_raise(:transaction) { adjust_authorization(*args) }
152
+ end
153
+
153
154
  def update_details(transaction_id, options = {})
154
155
  raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/
155
156
  Util.verify_keys(TransactionGateway._update_details_signature, options)
@@ -184,13 +185,14 @@ module Braintree
184
185
 
185
186
  def self._create_signature # :nodoc:
186
187
  [
187
- :amount, :customer_id, :merchant_account_id, :order_id, :channel, :payment_method_token,
188
- :purchase_order_number, :recurring, :transaction_source, :shipping_address_id, :type, :tax_amount, :tax_exempt,
189
- :venmo_sdk_payment_method_code, :device_session_id, :service_fee_amount, :device_data, :fraud_merchant_id,
190
- :shipping_amount, :discount_amount, :ships_from_postal_code,
191
- :billing_address_id, :payment_method_nonce, :three_d_secure_token, :three_d_secure_authentication_id,
192
- :shared_payment_method_token, :shared_billing_address_id, :shared_customer_id, :shared_shipping_address_id, :shared_payment_method_nonce,
193
- :product_sku,
188
+ :amount, :billing_address_id, :channel, :customer_id, :device_data, :discount_amount,
189
+ :merchant_account_id, :order_id, :payment_method_nonce, :payment_method_token,
190
+ :product_sku, :purchase_order_number, :service_fee_amount, :shared_billing_address_id,
191
+ :shared_customer_id, :shared_payment_method_nonce, :shared_payment_method_token,
192
+ :shared_shipping_address_id, :shipping_address_id, :shipping_amount,
193
+ :ships_from_postal_code, :tax_amount, :tax_exempt, :three_d_secure_authentication_id,
194
+ :three_d_secure_token, :transaction_source, :type, :venmo_sdk_payment_method_code,
195
+ :sca_exemption, :currency_iso_code,
194
196
  {:line_items => [:quantity, :name, :description, :kind, :unit_amount, :unit_tax_amount, :total_amount, :discount_amount, :tax_amount, :unit_of_measure, :product_code, :commodity_code, :url]},
195
197
  {:risk_data => [:customer_browser, :customer_device_id, :customer_ip, :customer_location_zip, :customer_tenure]},
196
198
  {:credit_card => [:token, :cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]},
@@ -256,8 +258,8 @@ module Braintree
256
258
  ]},
257
259
  ]},
258
260
  {:apple_pay_card => [:number, :cardholder_name, :cryptogram, :expiration_month, :expiration_year, :eci_indicator]},
259
- # NEXT_MAJOR_VERSION rename Android Pay to Google Pay
260
- {:android_pay_card => [:number, :cryptogram, :google_transaction_id, :expiration_month, :expiration_year, :source_card_type, :source_card_last_four, :eci_indicator]}
261
+ {:google_pay_card => [:number, :cryptogram, :google_transaction_id, :expiration_month, :expiration_year, :source_card_type, :source_card_last_four, :eci_indicator]},
262
+ {:installments => [:count]},
261
263
  ]
262
264
  end
263
265
 
@@ -275,6 +277,12 @@ module Braintree
275
277
  ]
276
278
  end
277
279
 
280
+ def self._adjust_authorization_signature
281
+ [
282
+ :amount
283
+ ]
284
+ end
285
+
278
286
  def self._update_details_signature # :nodoc:
279
287
  [
280
288
  :amount,
@@ -286,11 +294,15 @@ module Braintree
286
294
  def self._refund_signature
287
295
  [
288
296
  :amount,
289
- :order_id
297
+ :merchant_account_id,
298
+ :order_id,
290
299
  ]
291
300
  end
292
301
 
293
302
  def _do_create(path, params=nil) # :nodoc:
303
+ if !params.nil?
304
+ params = Util.replace_key(params, :google_pay_card, :android_pay_card)
305
+ end
294
306
  response = @config.http.post("#{@config.base_merchant_path}#{path}", params)
295
307
  _handle_transaction_response(response)
296
308
  end
@@ -29,7 +29,7 @@ module Braintree
29
29
  class << self
30
30
  protected :new
31
31
  def _new(*args) # :nodoc:
32
- self.new *args
32
+ self.new(*args)
33
33
  end
34
34
  end
35
35
 
@@ -28,7 +28,6 @@ module Braintree
28
28
  :paypal_authorization_id,
29
29
  :paypal_payer_email,
30
30
  :processor_authorization_code,
31
- :europe_bank_account_iban,
32
31
  :settlement_batch_id,
33
32
  :shipping_company,
34
33
  :shipping_country_name,
@@ -38,7 +37,8 @@ module Braintree
38
37
  :shipping_locality,
39
38
  :shipping_postal_code,
40
39
  :shipping_region,
41
- :shipping_street_address
40
+ :shipping_street_address,
41
+ :store_id,
42
42
  )
43
43
 
44
44
  equality_fields :credit_card_expiration_date
@@ -60,6 +60,7 @@ module Braintree
60
60
  multiple_value_field :status, :allows => Transaction::Status::All
61
61
  multiple_value_field :source
62
62
  multiple_value_field :type, :allows => Transaction::Type::All
63
+ multiple_value_field :store_ids
63
64
 
64
65
  key_value_fields :refund
65
66
 
@@ -20,7 +20,7 @@ module Braintree
20
20
  end
21
21
 
22
22
  def self._new(*args) # :nodoc:
23
- self.new *args
23
+ self.new(*args)
24
24
  end
25
25
  end
26
26
  end
@@ -35,7 +35,7 @@ module Braintree
35
35
  end
36
36
 
37
37
  def self._new(*args) # :nodoc:
38
- self.new *args
38
+ self.new(*args)
39
39
  end
40
40
 
41
41
  def self.find(*args)
@@ -45,8 +45,8 @@ module Braintree
45
45
  def self.sale(token, transaction_attributes)
46
46
  Configuration.gateway.transaction.sale(transaction_attributes.merge(
47
47
  :payment_method_token => token,
48
- :options => { :submit_for_settlement => true }
49
- )
48
+ :options => {:submit_for_settlement => true},
49
+ ),
50
50
  )
51
51
  end
52
52
 
@@ -63,7 +63,7 @@ module Braintree
63
63
  end
64
64
 
65
65
  def self._new(*args) # :nodoc:
66
- self.new *args
66
+ self.new(*args)
67
67
  end
68
68
 
69
69
  def self.confirm_micro_transfer_amounts(*args)
@@ -18,7 +18,7 @@ module Braintree
18
18
  ErrorResult.new(@gateway, response[:api_error_response])
19
19
  else
20
20
  SuccessfulResult.new(
21
- :us_bank_account_verification => UsBankAccountVerification._new(response[:us_bank_account_verification])
21
+ :us_bank_account_verification => UsBankAccountVerification._new(response[:us_bank_account_verification]),
22
22
  )
23
23
  end
24
24
  rescue NotFoundError
@@ -14,13 +14,13 @@ module Braintree
14
14
  else
15
15
  url_encode(full_key) + "=" + url_encode(value)
16
16
  end
17
- end.sort * '&'
17
+ end.sort * "&"
18
18
  end
19
19
 
20
20
  def self.parse_query_string(qs)
21
- qs.split('&').inject({}) do |result, couplet|
22
- pair = couplet.split('=')
23
- result[CGI.unescape(pair[0]).to_sym] = CGI.unescape(pair[1] || '')
21
+ qs.split("&").inject({}) do |result, couplet|
22
+ pair = couplet.split("=")
23
+ result[CGI.unescape(pair[0]).to_sym] = CGI.unescape(pair[1] || "")
24
24
  result
25
25
  end
26
26
  end
@@ -53,6 +53,8 @@ module Braintree
53
53
  raise AuthorizationError, message
54
54
  when 404
55
55
  raise NotFoundError
56
+ when 408
57
+ raise RequestTimeoutError
56
58
  when 426
57
59
  raise UpgradeRequiredError, "Please upgrade your client library."
58
60
  when 429
@@ -60,7 +62,9 @@ module Braintree
60
62
  when 500
61
63
  raise ServerError
62
64
  when 503
63
- raise DownForMaintenanceError
65
+ raise ServiceUnavailableError
66
+ when 504
67
+ raise GatewayTimeoutError
64
68
  else
65
69
  raise UnexpectedError, "Unexpected HTTP_RESPONSE #{status_code.to_i}"
66
70
  end
@@ -87,7 +91,7 @@ module Braintree
87
91
  when "INTERNAL"
88
92
  raise ServerError
89
93
  when "SERVICE_AVAILABILITY"
90
- raise DownForMaintenanceError
94
+ raise ServiceUnavailableError
91
95
  else
92
96
  raise UnexpectedError, "Unexpected Response: #{error[:message]}"
93
97
  end
@@ -126,6 +130,17 @@ module Braintree
126
130
  !invalid_keys.any?
127
131
  end
128
132
 
133
+ def self.replace_key(hash, target_key, replacement_key)
134
+ hash.inject({}) do |new_hash, (key, value)|
135
+ if value.is_a?(Hash)
136
+ value = replace_key(value, target_key, replacement_key)
137
+ end
138
+
139
+ key = replacement_key if key == target_key
140
+ new_hash.merge(key => value)
141
+ end
142
+ end
143
+
129
144
  def self._flatten_valid_keys(valid_keys, namespace = nil)
130
145
  valid_keys.inject([]) do |result, key|
131
146
  if key.is_a?(Hash)
@@ -28,7 +28,7 @@ module Braintree
28
28
  end
29
29
 
30
30
  def self._new(*args) # :nodoc:
31
- self.new *args
31
+ self.new(*args)
32
32
  end
33
33
  end
34
34
  end
@@ -1,8 +1,8 @@
1
1
  module Braintree
2
2
  module Version
3
- Major = 2
4
- Minor = 104
5
- Tiny = 1
3
+ Major = 3
4
+ Minor = 4
5
+ Tiny = 0
6
6
 
7
7
  String = "#{Major}.#{Minor}.#{Tiny}"
8
8
  end
@@ -39,7 +39,7 @@ module Braintree
39
39
  end
40
40
 
41
41
  def _most_recent_verification(attributes)
42
- verification = (attributes[:verifications] || []).sort_by{ |verification| verification[:created_at] }.reverse.first
42
+ verification = (attributes[:verifications] || []).sort_by { |verification| verification[:created_at] }.reverse.first
43
43
  CreditCardVerification._new(verification) if verification
44
44
  end
45
45
 
@@ -84,7 +84,7 @@ module Braintree
84
84
  end
85
85
 
86
86
  def self._new(*args) # :nodoc:
87
- self.new *args
87
+ self.new(*args)
88
88
  end
89
89
  end
90
90
  end
@@ -1,12 +1,17 @@
1
- require 'ostruct'
1
+ require "ostruct"
2
2
 
3
3
  module Braintree
4
4
  class WebhookNotification
5
5
  include BaseModule
6
6
 
7
7
  module Kind
8
+
9
+ AccountUpdaterDailyReport = "account_updater_daily_report"
10
+
8
11
  Check = "check"
9
12
 
13
+ ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
14
+ ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
10
15
  Disbursement = "disbursement"
11
16
  DisbursementException = "disbursement_exception"
12
17
 
@@ -17,6 +22,23 @@ module Braintree
17
22
  DisputeDisputed = "dispute_disputed"
18
23
  DisputeExpired = "dispute_expired"
19
24
 
25
+ GrantedPaymentInstrumentRevoked = "granted_payment_instrument_revoked"
26
+
27
+ GrantorUpdatedGrantedPaymentMethod = "grantor_updated_granted_payment_method"
28
+
29
+ LocalPaymentCompleted = "local_payment_completed"
30
+ LocalPaymentReversed = "local_payment_reversed"
31
+
32
+ OAuthAccessRevoked = "oauth_access_revoked"
33
+
34
+ PartnerMerchantConnected = "partner_merchant_connected"
35
+ PartnerMerchantDisconnected = "partner_merchant_disconnected"
36
+ PartnerMerchantDeclined = "partner_merchant_declined"
37
+
38
+ PaymentMethodRevokedByCustomer = "payment_method_revoked_by_customer"
39
+
40
+ RecipientUpdatedGrantedPaymentMethod = "recipient_updated_granted_payment_method"
41
+
20
42
  SubscriptionCanceled = "subscription_canceled"
21
43
  SubscriptionChargedSuccessfully = "subscription_charged_successfully"
22
44
  SubscriptionChargedUnsuccessfully = "subscription_charged_unsuccessfully"
@@ -27,33 +49,10 @@ module Braintree
27
49
 
28
50
  SubMerchantAccountApproved = "sub_merchant_account_approved"
29
51
  SubMerchantAccountDeclined = "sub_merchant_account_declined"
52
+
30
53
  TransactionDisbursed = "transaction_disbursed"
31
54
  TransactionSettlementDeclined = "transaction_settlement_declined"
32
55
  TransactionSettled = "transaction_settled"
33
- PartnerMerchantConnected = "partner_merchant_connected"
34
- PartnerMerchantDisconnected = "partner_merchant_disconnected"
35
- PartnerMerchantDeclined = "partner_merchant_declined"
36
-
37
- AccountUpdaterDailyReport = "account_updater_daily_report"
38
-
39
- # NEXT_MAJOR_VERSION Remove this class as legacy Ideal has been removed/disabled in the Braintree Gateway
40
- # DEPRECATED If you're looking to accept iDEAL as a payment method contact accounts@braintreepayments.com for a solution.
41
- IdealPaymentComplete = "ideal_payment_complete"
42
- IdealPaymentFailed = "ideal_payment_failed"
43
-
44
- OAuthAccessRevoked = "oauth_access_revoked"
45
- ConnectedMerchantStatusTransitioned = "connected_merchant_status_transitioned"
46
- ConnectedMerchantPayPalStatusChanged = "connected_merchant_paypal_status_changed"
47
-
48
- # NEXT_MAJOR_VERSION remove GrantedPaymentInstrumentUpdate. Kind is not sent by Braintree Gateway.
49
- # Kind will either be GrantorUpdatedGrantedPaymentMethod or RecipientUpdatedGrantedPaymentMethod.
50
- GrantedPaymentInstrumentUpdate = "granted_payment_instrument_update"
51
- GrantorUpdatedGrantedPaymentMethod = "grantor_updated_granted_payment_method"
52
- RecipientUpdatedGrantedPaymentMethod = "recipient_updated_granted_payment_method"
53
- GrantedPaymentInstrumentRevoked = "granted_payment_instrument_revoked"
54
- PaymentMethodRevokedByCustomer = "payment_method_revoked_by_customer"
55
-
56
- LocalPaymentCompleted = "local_payment_completed"
57
56
  end
58
57
 
59
58
  attr_reader :account_updater_daily_report
@@ -63,9 +62,9 @@ module Braintree
63
62
  attr_reader :dispute
64
63
  attr_reader :granted_payment_instrument_update
65
64
  attr_reader :revoked_payment_method_metadata
66
- attr_reader :ideal_payment
67
65
  attr_reader :kind
68
66
  attr_reader :local_payment_completed
67
+ attr_reader :local_payment_reversed
69
68
  attr_reader :oauth_access_revocation
70
69
  attr_reader :partner_merchant
71
70
  attr_reader :source_merchant_id
@@ -93,12 +92,12 @@ module Braintree
93
92
  @disbursement = Disbursement._new(gateway, @subject[:disbursement]) if @subject.has_key?(:disbursement)
94
93
  @dispute = Dispute._new(@subject[:dispute]) if @subject.has_key?(:dispute)
95
94
  @account_updater_daily_report = AccountUpdaterDailyReport._new(@subject[:account_updater_daily_report]) if @subject.has_key?(:account_updater_daily_report)
96
- @ideal_payment = Braintree::IdealPayment._new(gateway, @subject[:ideal_payment]) if @subject.has_key?(:ideal_payment)
97
95
  @connected_merchant_status_transitioned = ConnectedMerchantStatusTransitioned._new(@subject[:connected_merchant_status_transitioned]) if @subject.has_key?(:connected_merchant_status_transitioned)
98
96
  @connected_merchant_paypal_status_changed = ConnectedMerchantPayPalStatusChanged._new(@subject[:connected_merchant_paypal_status_changed]) if @subject.has_key?(:connected_merchant_paypal_status_changed)
99
97
  @granted_payment_instrument_update = GrantedPaymentInstrumentUpdate._new(@subject[:granted_payment_instrument_update]) if @subject.has_key?(:granted_payment_instrument_update)
100
98
  @revoked_payment_method_metadata = RevokedPaymentMethodMetadata._new(gateway, @subject) if [Kind::GrantedPaymentInstrumentRevoked, Kind::PaymentMethodRevokedByCustomer].include?(@kind)
101
- @local_payment_completed = LocalPaymentCompleted._new(@subject[:local_payment]) if @subject.has_key?(:local_payment)
99
+ @local_payment_completed = LocalPaymentCompleted._new(@subject[:local_payment]) if @subject.has_key?(:local_payment) && Kind::LocalPaymentCompleted == @kind
100
+ @local_payment_reversed = LocalPaymentReversed._new(@subject[:local_payment_reversed]) if @subject.has_key?(:local_payment_reversed) && Kind::LocalPaymentReversed == @kind
102
101
  end
103
102
 
104
103
  def merchant_account
@@ -120,7 +119,7 @@ module Braintree
120
119
  class << self
121
120
  protected :new
122
121
  def _new(*args) # :nodoc:
123
- self.new *args
122
+ self.new(*args)
124
123
  end
125
124
  end
126
125
  end