braintree 4.39.0 → 4.41.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/lib/braintree/address_gateway.rb +13 -3
  3. data/lib/braintree/client_token_gateway.rb +10 -1
  4. data/lib/braintree/credit_card_gateway.rb +9 -2
  5. data/lib/braintree/credit_card_verification_gateway.rb +3 -0
  6. data/lib/braintree/customer_gateway.rb +11 -3
  7. data/lib/braintree/dispute_gateway.rb +7 -7
  8. data/lib/braintree/error_codes.rb +11 -0
  9. data/lib/braintree/http.rb +4 -2
  10. data/lib/braintree/merchant_account_gateway.rb +2 -0
  11. data/lib/braintree/payment_method_gateway.rb +7 -1
  12. data/lib/braintree/payment_method_nonce_gateway.rb +4 -0
  13. data/lib/braintree/paypal_account_gateway.rb +6 -1
  14. data/lib/braintree/plan_gateway.rb +4 -0
  15. data/lib/braintree/sepa_direct_debit_account_gateway.rb +4 -0
  16. data/lib/braintree/subscription_gateway.rb +6 -0
  17. data/lib/braintree/testing_gateway.rb +4 -0
  18. data/lib/braintree/three_d_secure_pass_thru.rb +11 -0
  19. data/lib/braintree/transaction.rb +6 -0
  20. data/lib/braintree/transaction_gateway.rb +17 -7
  21. data/lib/braintree/transaction_line_item_gateway.rb +3 -1
  22. data/lib/braintree/transaction_search.rb +1 -0
  23. data/lib/braintree/us_bank_account_gateway.rb +2 -0
  24. data/lib/braintree/us_bank_account_verification_gateway.rb +4 -0
  25. data/lib/braintree/util.rb +5 -0
  26. data/lib/braintree/version.rb +1 -1
  27. data/lib/braintree.rb +1 -0
  28. data/spec/integration/braintree/advanced_search_spec.rb +4 -7
  29. data/spec/integration/braintree/braintree_gateway_spec.rb +1 -2
  30. data/spec/integration/braintree/client_api/client_token_spec.rb +14 -0
  31. data/spec/integration/braintree/credit_card_spec.rb +94 -2
  32. data/spec/integration/braintree/credit_card_verification_spec.rb +33 -0
  33. data/spec/integration/braintree/customer_spec.rb +196 -5
  34. data/spec/integration/braintree/http_spec.rb +1 -1
  35. data/spec/integration/braintree/payment_method_spec.rb +77 -7
  36. data/spec/integration/braintree/samsung_pay_card_spec.rb +1 -1
  37. data/spec/integration/braintree/transaction_search_spec.rb +113 -13
  38. data/spec/integration/braintree/transaction_spec.rb +197 -17
  39. data/spec/unit/braintree/address_spec.rb +32 -0
  40. data/spec/unit/braintree/client_token_spec.rb +72 -0
  41. data/spec/unit/braintree/credit_card_spec.rb +28 -0
  42. data/spec/unit/braintree/credit_card_verification_spec.rb +8 -0
  43. data/spec/unit/braintree/customer_spec.rb +28 -0
  44. data/spec/unit/braintree/dispute_spec.rb +38 -0
  45. data/spec/unit/braintree/http_spec.rb +44 -0
  46. data/spec/unit/braintree/merchant_account_spec.rb +11 -0
  47. data/spec/unit/braintree/package_tracking_spec.rb +2 -2
  48. data/spec/unit/braintree/payment_method_nonce_spec.rb +14 -0
  49. data/spec/unit/braintree/payment_method_spec.rb +20 -0
  50. data/spec/unit/braintree/paypal_account_spec.rb +20 -0
  51. data/spec/unit/braintree/plan_gateway_spec.rb +30 -0
  52. data/spec/unit/braintree/sepa_debit_account_spec.rb +14 -0
  53. data/spec/unit/braintree/subscription_spec.rb +20 -0
  54. data/spec/unit/braintree/test_transaction_spec.rb +18 -0
  55. data/spec/unit/braintree/transaction_gateway_spec.rb +11 -0
  56. data/spec/unit/braintree/transaction_line_item_spec.rb +11 -0
  57. data/spec/unit/braintree/transaction_search_spec.rb +25 -0
  58. data/spec/unit/braintree/transaction_spec.rb +68 -6
  59. data/spec/unit/braintree/us_bank_account_spec.rb +8 -0
  60. data/spec/unit/braintree/us_bank_account_verification_spec.rb +14 -0
  61. data/spec/unit/braintree/util_spec.rb +37 -0
  62. metadata +8 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a8a4986148f9b2ded5832261519f85d75e2932d7d7d15bc7d49207d2422431e
4
- data.tar.gz: 3431f5d87f5f15ffd7c2d29fe28674d7c49645f0447342360d0f41444def6c16
3
+ metadata.gz: 874cd322dda721874dc4418b2f6ca24116b9395f7affc02d43fe056f43424b3a
4
+ data.tar.gz: 8c73ed2ec27ecf6b916474bc12dc14bde985c48107a53bdcea17a65a216cc3d5
5
5
  SHA512:
6
- metadata.gz: d523c2199f88f2eea71960c92659b7e8aabb02aa78c35ab51f0b513b575d408b6df9b881c5d895ed8a30b300c3ab4c43fa48ce3d88a331dcd9c96c9c6aac8ca8
7
- data.tar.gz: d6dc3e11eec83fcbd5c045ff92b04e83ff80686ecc19eedf17a50b19b68d0511f2ec1514fa0f13081ba889509ae161f8f1121380a6e51baa1daf66fa6115f509
6
+ metadata.gz: f8f4fa7af94d5b317dc5efa9aea66d1fbcf84f689e9cb19435f6899b8af8c39fb25063a8d0ff40e4025f42014e4c18555e9d4b2e779132b0fc73afc3f6204baa
7
+ data.tar.gz: 815d5927abfa22e7acbdf7fa4353d9408b0b0add7f66a5e1cbf43b2b2aaa03a5ac4f925eb25b69bcf1060ff04c01e9cdc9c908e560a4e6e7df9db14339ed886a
@@ -13,7 +13,7 @@ module Braintree
13
13
  unless attributes[:customer_id]
14
14
  raise ArgumentError, "Expected hash to contain a :customer_id"
15
15
  end
16
- unless attributes[:customer_id] =~ /\A[0-9A-Za-z_-]+\z/
16
+ if Util.invalid_path_segment?(attributes[:customer_id])
17
17
  raise ArgumentError, ":customer_id contains invalid characters"
18
18
  end
19
19
  response = @config.http.post("#{@config.base_merchant_path}/customers/#{attributes.delete(:customer_id)}/addresses", :address => attributes)
@@ -32,13 +32,14 @@ module Braintree
32
32
 
33
33
  def delete(customer_or_customer_id, address_id)
34
34
  customer_id = _determine_customer_id(customer_or_customer_id)
35
+ address_id = _determine_address_id(address_id)
35
36
  @config.http.delete("#{@config.base_merchant_path}/customers/#{customer_id}/addresses/#{address_id}")
36
37
  SuccessfulResult.new
37
38
  end
38
39
 
39
40
  def find(customer_or_customer_id, address_id)
40
41
  customer_id = _determine_customer_id(customer_or_customer_id)
41
- raise ArgumentError if address_id.nil? || address_id.to_s.strip == ""
42
+ address_id = _determine_address_id(address_id)
42
43
  response = @config.http.get("#{@config.base_merchant_path}/customers/#{customer_id}/addresses/#{address_id}")
43
44
  Address._new(@gateway, response[:address])
44
45
  rescue NotFoundError
@@ -48,6 +49,7 @@ module Braintree
48
49
  def update(customer_or_customer_id, address_id, attributes)
49
50
  Util.verify_keys(AddressGateway._update_signature, attributes)
50
51
  customer_id = _determine_customer_id(customer_or_customer_id)
52
+ address_id = _determine_address_id(address_id)
51
53
  response = @config.http.put("#{@config.base_merchant_path}/customers/#{customer_id}/addresses/#{address_id}", :address => attributes)
52
54
  if response[:address]
53
55
  SuccessfulResult.new(:address => Address._new(@gateway, response[:address]))
@@ -64,12 +66,20 @@ module Braintree
64
66
 
65
67
  def _determine_customer_id(customer_or_customer_id)
66
68
  customer_id = customer_or_customer_id.is_a?(Customer) ? customer_or_customer_id.id : customer_or_customer_id
67
- unless customer_id =~ /\A[\w_-]+\z/
69
+ if Util.invalid_path_segment?(customer_id)
68
70
  raise ArgumentError, "customer_id contains invalid characters"
69
71
  end
70
72
  customer_id
71
73
  end
72
74
 
75
+ def _determine_address_id(address_id)
76
+ address_id = address_id.to_s
77
+ if Util.invalid_path_segment?(address_id)
78
+ raise ArgumentError, "address_id contains invalid characters"
79
+ end
80
+ address_id
81
+ end
82
+
73
83
  def self._create_signature
74
84
  _shared_signature + [:customer_id]
75
85
  end
@@ -9,12 +9,21 @@ module Braintree
9
9
  end
10
10
 
11
11
  def generate(options={})
12
+ options = options.dup
13
+
12
14
  _validate_options(options)
13
15
 
14
16
  options[:version] ||= ClientToken::DEFAULT_VERSION
15
17
 
16
18
  Util.verify_keys(ClientTokenGateway._generate_signature, options)
17
19
 
20
+ if options.has_key?(:preferred_payment_method_token)
21
+ options[:payment_method_id] = options.delete(:preferred_payment_method_token)
22
+ options.delete("preferred_payment_method_token")
23
+ elsif options.has_key?("preferred_payment_method_token")
24
+ options[:payment_method_id] = options.delete("preferred_payment_method_token")
25
+ end
26
+
18
27
  params = {:client_token => options}
19
28
  result = @config.http.post("#{@config.base_merchant_path}/client_token", params)
20
29
 
@@ -27,7 +36,7 @@ module Braintree
27
36
 
28
37
  def self._generate_signature
29
38
  [
30
- :address_id, :customer_id, :proxy_merchant_id, :merchant_account_id,
39
+ :address_id, :customer_id, :merchant_account_id, :preferred_payment_method_token, :proxy_merchant_id,
31
40
  :version,
32
41
  {:domains => [:_any_key_]},
33
42
  {:options => [:fail_on_duplicate_payment_method, :fail_on_duplicate_payment_method_for_customer, :make_default, :verify_card]}
@@ -39,6 +39,8 @@ module Braintree
39
39
  end
40
40
 
41
41
  def delete(token)
42
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
43
+
42
44
  @config.http.delete("#{@config.base_merchant_path}/payment_methods/credit_card/#{token}")
43
45
  end
44
46
 
@@ -55,7 +57,8 @@ module Braintree
55
57
  end
56
58
 
57
59
  def find(token)
58
- raise ArgumentError if token.nil? || token.to_s.strip == ""
60
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
61
+
59
62
  response = @config.http.get("#{@config.base_merchant_path}/payment_methods/credit_card/#{token}")
60
63
  CreditCard._new(@gateway, response[:credit_card])
61
64
  rescue NotFoundError
@@ -63,7 +66,8 @@ module Braintree
63
66
  end
64
67
 
65
68
  def from_nonce(nonce)
66
- raise ArgumentError if nonce.nil? || nonce.to_s.strip == ""
69
+ raise ArgumentError, "nonce contains invalid characters" if Util.invalid_path_segment?(nonce)
70
+
67
71
  response = @config.http.get("#{@config.base_merchant_path}/payment_methods/from_nonce/#{nonce}")
68
72
  CreditCard._new(@gateway, response[:credit_card])
69
73
  rescue NotFoundError
@@ -71,6 +75,8 @@ module Braintree
71
75
  end
72
76
 
73
77
  def update(token, attributes)
78
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
79
+
74
80
  # NEXT_MAJOR_VERSION remove this check
75
81
  if attributes.has_key?(:venmo_sdk_payment_method_code) || attributes.has_key?(:venmo_sdk_session)
76
82
  warn "[DEPRECATED] The Venmo SDK integration is Unsupported. Please update your integration to use Pay with Venmo instead."
@@ -129,6 +135,7 @@ module Braintree
129
135
  :directory_response,
130
136
  :cavv_algorithm,
131
137
  :ds_transaction_id,
138
+ :network,
132
139
  ]
133
140
  }
134
141
 
@@ -8,6 +8,8 @@ module Braintree
8
8
 
9
9
  def find(id)
10
10
  raise ArgumentError if id.nil? || id.to_s.strip == ""
11
+ raise ArgumentError, "id contains invalid characters" if Util.invalid_path_segment?(id)
12
+
11
13
  response = @config.http.get("#{@config.base_merchant_path}/verifications/#{id}")
12
14
  CreditCardVerification._new(response[:verification])
13
15
  rescue NotFoundError
@@ -81,6 +83,7 @@ module Braintree
81
83
  :directory_response,
82
84
  :ds_transaction_id,
83
85
  :eci_flag,
86
+ :network,
84
87
  :three_d_secure_version,
85
88
  :xid,
86
89
  ]},
@@ -23,15 +23,19 @@ module Braintree
23
23
  end
24
24
 
25
25
  def delete(customer_id)
26
+ raise ArgumentError, "customer_id contains invalid characters" if Util.invalid_path_segment?(customer_id)
27
+
26
28
  @config.http.delete("#{@config.base_merchant_path}/customers/#{customer_id}")
27
29
  SuccessfulResult.new
28
30
  end
29
31
 
30
32
  def find(customer_id, options = {})
31
- raise ArgumentError, "customer_id contains invalid characters" unless customer_id.to_s =~ /\A[\w-]+\z/
32
- raise ArgumentError, "customer_id cannot be blank" if customer_id.nil?|| customer_id.to_s.strip == ""
33
+ raise ArgumentError, "customer_id contains invalid characters" if Util.invalid_path_segment?(customer_id)
34
+
35
+ association_filter_id = options[:association_filter_id]
36
+ raise ArgumentError, "association_filter_id contains invalid characters" if association_filter_id && Util.invalid_path_segment?(association_filter_id)
33
37
 
34
- query_params = options[:association_filter_id].nil? ? "" : "?association_filter_id=#{options[:association_filter_id]}"
38
+ query_params = association_filter_id.nil? ? "" : "?association_filter_id=#{association_filter_id}"
35
39
  response = @config.http.get("#{@config.base_merchant_path}/customers/#{customer_id}#{query_params}")
36
40
  Customer._new(@gateway, response[:customer])
37
41
  rescue NotFoundError
@@ -47,11 +51,15 @@ module Braintree
47
51
  end
48
52
 
49
53
  def transactions(customer_id, options = {})
54
+ raise ArgumentError, "customer_id contains invalid characters" if Util.invalid_path_segment?(customer_id)
55
+
50
56
  response = @config.http.post("#{@config.base_merchant_path}/customers/#{customer_id}/transaction_ids")
51
57
  ResourceCollection.new(response) { |ids| _fetch_transactions(customer_id, ids) }
52
58
  end
53
59
 
54
60
  def update(customer_id, attributes)
61
+ raise ArgumentError, "customer_id contains invalid characters" if Util.invalid_path_segment?(customer_id)
62
+
55
63
  Util.verify_keys(CustomerGateway._update_signature, attributes)
56
64
  _do_update(:put, "/customers/#{customer_id}", :customer => attributes)
57
65
  end
@@ -7,7 +7,7 @@ module Braintree
7
7
  end
8
8
 
9
9
  def accept(dispute_id)
10
- raise ArgumentError, "dispute_id contains invalid characters" unless dispute_id.to_s =~ /\A[\w-]+\z/
10
+ raise ArgumentError, "dispute_id contains invalid characters" if Util.invalid_path_segment?(dispute_id)
11
11
  raise ArgumentError, "dispute_id cannot be blank" if dispute_id.nil? || dispute_id.to_s.strip == ""
12
12
 
13
13
  response = @config.http.put("#{@config.base_merchant_path}/disputes/#{dispute_id}/accept")
@@ -21,7 +21,7 @@ module Braintree
21
21
  end
22
22
 
23
23
  def add_file_evidence(dispute_id, document_id_or_request)
24
- raise ArgumentError, "dispute_id contains invalid characters" unless dispute_id.to_s =~ /\A[\w-]+\z/
24
+ raise ArgumentError, "dispute_id contains invalid characters" if Util.invalid_path_segment?(dispute_id)
25
25
  raise ArgumentError, "dispute_id cannot be blank" if dispute_id.nil? || dispute_id.to_s.strip == ""
26
26
  raise ArgumentError, "document_id_or_request cannot be blank" if document_id_or_request.nil?
27
27
 
@@ -51,7 +51,7 @@ module Braintree
51
51
  end
52
52
 
53
53
  def add_text_evidence(dispute_id, content_or_request)
54
- raise ArgumentError, "dispute_id contains invalid characters" unless dispute_id.to_s =~ /\A[\w-]+\z/
54
+ raise ArgumentError, "dispute_id contains invalid characters" if Util.invalid_path_segment?(dispute_id)
55
55
  raise ArgumentError, "dispute_id cannot be blank" if dispute_id.nil? || dispute_id.to_s.strip == ""
56
56
  raise ArgumentError, "content_or_request cannot be blank" if content_or_request.nil?
57
57
 
@@ -84,7 +84,7 @@ module Braintree
84
84
  end
85
85
 
86
86
  def finalize(dispute_id)
87
- raise ArgumentError, "dispute_id contains invalid characters" unless dispute_id.to_s =~ /\A[\w-]+\z/
87
+ raise ArgumentError, "dispute_id contains invalid characters" if Util.invalid_path_segment?(dispute_id)
88
88
  raise ArgumentError, "dispute_id cannot be blank" if dispute_id.nil? || dispute_id.to_s.strip == ""
89
89
 
90
90
  response = @config.http.put("#{@config.base_merchant_path}/disputes/#{dispute_id}/finalize")
@@ -98,7 +98,7 @@ module Braintree
98
98
  end
99
99
 
100
100
  def find(dispute_id)
101
- raise ArgumentError, "dispute_id contains invalid characters" unless dispute_id.to_s =~ /\A[\w-]+\z/
101
+ raise ArgumentError, "dispute_id contains invalid characters" if Util.invalid_path_segment?(dispute_id)
102
102
  raise ArgumentError, "dispute_id cannot be blank" if dispute_id.nil? || dispute_id.to_s.strip == ""
103
103
  response = @config.http.get("#{@config.base_merchant_path}/disputes/#{dispute_id}")
104
104
  Dispute._new(response[:dispute])
@@ -107,9 +107,9 @@ module Braintree
107
107
  end
108
108
 
109
109
  def remove_evidence(dispute_id, evidence_id)
110
- raise ArgumentError, "dispute_id contains invalid characters" unless dispute_id.to_s =~ /\A[\w-]+\z/
110
+ raise ArgumentError, "dispute_id contains invalid characters" if Util.invalid_path_segment?(dispute_id)
111
111
  raise ArgumentError, "dispute_id cannot be blank" if dispute_id.nil? || dispute_id.to_s.strip == ""
112
- raise ArgumentError, "evidence_id contains invalid characters" unless evidence_id.to_s =~ /\A[\w-]+\z/
112
+ raise ArgumentError, "evidence_id contains invalid characters" if Util.invalid_path_segment?(evidence_id)
113
113
  raise ArgumentError, "evidence_id cannot be blank" if evidence_id.nil? || evidence_id.to_s.strip == ""
114
114
 
115
115
  response = @config.http.delete("#{@config.base_merchant_path}/disputes/#{dispute_id}/evidence/#{evidence_id}")
@@ -216,6 +216,8 @@ module Braintree
216
216
  CannotVaultOneTimeUsePayPalAccount = "82902"
217
217
  ConsentCodeOrAccessTokenIsRequired = "82901"
218
218
  CustomerIdIsRequiredForVaulting = "82905"
219
+ EmailFormatIsInvalid = "92963"
220
+ EmailIsTooLong = "92964"
219
221
  IncompletePayPalAccount = "82901"
220
222
  InvalidFundingSourceSelection = "92913"
221
223
  InvalidParamsForPayPalAccountUpdate = "92915"
@@ -472,6 +474,10 @@ module Braintree
472
474
  ThreeDSecureEciFlagIsInvalid = "915114"
473
475
  ThreeDSecureEciFlagIsRequired = "915113"
474
476
  ThreeDSecureMerchantAccountDoesNotSupportCardType = "915131"
477
+ ThreeDSecureNetworkDoesNotMatchPaymentInstrument = "915139"
478
+ ThreeDSecureNetworkDoesNotSupportCurrency = "915239"
479
+ ThreeDSecureNetworkDoesNotSupportMerchantAccountCurrency = "915243"
480
+ ThreeDSecureNetworkIsInvalid = "915128"
475
481
  ThreeDSecureThreeDSecureVersionIsInvalid = "915119"
476
482
  ThreeDSecureTokenIsInvalid = "91568"
477
483
  ThreeDSecureTransactionDataDoesntMatchVerify = "91570"
@@ -502,6 +508,7 @@ module Braintree
502
508
 
503
509
 
504
510
  module Options
511
+ SubmitForSettlementIsNotSupportedForNetwork = "915261"
505
512
  SubmitForSettlementIsRequiredForCloning = "91544"
506
513
  SubmitForSettlementIsRequiredForPayPalUnilateral = "91582"
507
514
  VaultIsDisabled = "91525"
@@ -768,6 +775,10 @@ module Braintree
768
775
  DirectoryResponseIsInvalid = "942121"
769
776
  EciFlagIsInvalid = "942114"
770
777
  EciFlagIsRequired = "942113"
778
+ NetworkDoesNotMatchPaymentInstrument = "942139"
779
+ NetworkDoesNotSupportCurrency = "942129"
780
+ NetworkDoesNotSupportMerchantAccountCurrency = "942130"
781
+ NetworkIsInvalid = "942128"
771
782
  ThreeDSecureVersionIsInvalid = "942119"
772
783
  ThreeDSecureVersionIsRequired = "942117"
773
784
  end
@@ -8,7 +8,8 @@ module Braintree
8
8
  end
9
9
 
10
10
  def delete(path, query_params = {})
11
- response = _http_do Net::HTTP::Delete, path
11
+ full_path = path + _build_query_string(query_params)
12
+ response = _http_do Net::HTTP::Delete, full_path
12
13
  if response.code.to_i == 200 || response.code.to_i == 204
13
14
  true
14
15
  elsif response.code.to_i == 422
@@ -19,7 +20,8 @@ module Braintree
19
20
  end
20
21
 
21
22
  def get(path, query_params = {})
22
- response = _http_do Net::HTTP::Get, path
23
+ full_path = path + _build_query_string(query_params)
24
+ response = _http_do Net::HTTP::Get, full_path
23
25
  if response.code.to_i == 200 || response.code.to_i == 422
24
26
  Xml.hash_from_xml(_body(response))
25
27
  else
@@ -22,6 +22,8 @@ module Braintree
22
22
 
23
23
  def find(merchant_account_id)
24
24
  raise ArgumentError if merchant_account_id.nil? || merchant_account_id.to_s.strip == ""
25
+ raise ArgumentError, "merchant_account_id contains invalid characters" if Util.invalid_path_segment?(merchant_account_id)
26
+
25
27
  response = @config.http.get("#{@config.base_merchant_path}/merchant_accounts/#{merchant_account_id}")
26
28
  MerchantAccount._new(@gateway, response[:merchant_account])
27
29
  rescue NotFoundError
@@ -33,6 +33,8 @@ module Braintree
33
33
  end
34
34
 
35
35
  def delete(token, options = {})
36
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
37
+
36
38
  Util.verify_keys(PaymentMethodGateway._delete_signature, options)
37
39
  query_param = "?" + Util.hash_to_query_string(options) if not options.empty?
38
40
  @config.http.delete("#{@config.base_merchant_path}/payment_methods/any/#{token}#{query_param}")
@@ -40,7 +42,8 @@ module Braintree
40
42
  end
41
43
 
42
44
  def find(token)
43
- raise ArgumentError if token.nil? || token.to_s.strip == ""
45
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
46
+
44
47
  response = @config.http.get("#{@config.base_merchant_path}/payment_methods/any/#{token}")
45
48
  if response.has_key?(:credit_card)
46
49
  CreditCard._new(@gateway, response[:credit_card])
@@ -64,6 +67,8 @@ module Braintree
64
67
  end
65
68
 
66
69
  def update(token, attributes)
70
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
71
+
67
72
  # NEXT_MAJOR_VERSION remove this check
68
73
  if attributes.has_key?(:venmo_sdk_payment_method_code) || attributes.has_key?(:venmo_sdk_session)
69
74
  warn "[DEPRECATED] The Venmo SDK integration is Unsupported. Please update your integration to use Pay with Venmo instead."
@@ -199,6 +204,7 @@ module Braintree
199
204
  :directory_response,
200
205
  :cavv_algorithm,
201
206
  :ds_transaction_id,
207
+ :network,
202
208
  ]
203
209
  }
204
210
  signature << {
@@ -9,6 +9,8 @@ module Braintree
9
9
  end
10
10
 
11
11
  def create(payment_method_token, args = {payment_method_nonce: {}})
12
+ raise ArgumentError, "payment_method_token contains invalid characters" if Util.invalid_path_segment?(payment_method_token)
13
+
12
14
  Util.verify_keys(PaymentMethodNonceGateway._create_signature, args)
13
15
 
14
16
  response = @config.http.post("#{@config.base_merchant_path}/payment_methods/#{payment_method_token}/nonces", args)
@@ -30,6 +32,8 @@ module Braintree
30
32
  end
31
33
 
32
34
  def find(payment_method_nonce)
35
+ raise ArgumentError, "payment_method_nonce contains invalid characters" if Util.invalid_path_segment?(payment_method_nonce)
36
+
33
37
  response = @config.http.get("#{@config.base_merchant_path}/payment_method_nonces/#{payment_method_nonce}")
34
38
  payment_method_nonce = PaymentMethodNonce._new(@gateway, response.fetch(:payment_method_nonce))
35
39
  SuccessfulResult.new(:payment_method_nonce => payment_method_nonce)
@@ -7,7 +7,8 @@ module Braintree
7
7
  end
8
8
 
9
9
  def find(token)
10
- raise ArgumentError if token.nil? || token.to_s.strip == ""
10
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
11
+
11
12
  response = @config.http.get("#{@config.base_merchant_path}/payment_methods/paypal_account/#{token}")
12
13
  PayPalAccount._new(@gateway, response[:paypal_account])
13
14
  rescue NotFoundError
@@ -20,11 +21,15 @@ module Braintree
20
21
  end
21
22
 
22
23
  def update(token, attributes)
24
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
25
+
23
26
  Util.verify_keys(PayPalAccountGateway._update_signature, attributes)
24
27
  _do_update(:put, "/payment_methods/paypal_account/#{token}", :paypal_account => attributes)
25
28
  end
26
29
 
27
30
  def delete(token)
31
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
32
+
28
33
  @config.http.delete("#{@config.base_merchant_path}/payment_methods/paypal_account/#{token}")
29
34
  end
30
35
 
@@ -27,6 +27,8 @@ module Braintree
27
27
 
28
28
  def find(id)
29
29
  raise ArgumentError if id.nil? || id.to_s.strip == ""
30
+ raise ArgumentError, "id contains invalid characters" if Util.invalid_path_segment?(id)
31
+
30
32
  response = @config.http.get("#{@config.base_merchant_path}/plans/#{id}")
31
33
  Plan._new(@gateway, response[:plan])
32
34
  rescue NotFoundError
@@ -34,6 +36,8 @@ module Braintree
34
36
  end
35
37
 
36
38
  def update(plan_id, attributes)
39
+ raise ArgumentError, "plan_id contains invalid characters" if Util.invalid_path_segment?(plan_id)
40
+
37
41
  Util.verify_keys(PlanGateway._update_signature, attributes)
38
42
  response = @config.http.put("#{@config.base_merchant_path}/plans/#{plan_id}", :plan => attributes)
39
43
  if response[:plan]
@@ -8,6 +8,8 @@ module Braintree
8
8
 
9
9
  def find(token)
10
10
  raise ArgumentError if token.nil? || token.to_s.strip == ""
11
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
12
+
11
13
  response = @config.http.get("#{@config.base_merchant_path}/payment_methods/sepa_debit_account/#{token}")
12
14
  SepaDirectDebitAccount._new(@gateway, response[:sepa_debit_account])
13
15
  rescue NotFoundError
@@ -16,6 +18,8 @@ module Braintree
16
18
 
17
19
  def delete(token)
18
20
  raise ArgumentError if token.nil? || token.to_s.strip == ""
21
+ raise ArgumentError, "token contains invalid characters" if Util.invalid_path_segment?(token)
22
+
19
23
  @config.http.delete("#{@config.base_merchant_path}/payment_methods/sepa_debit_account/#{token}")
20
24
  SuccessfulResult.new
21
25
  rescue NotFoundError
@@ -9,6 +9,8 @@ module Braintree
9
9
  end
10
10
 
11
11
  def cancel(subscription_id)
12
+ raise ArgumentError, "subscription_id contains invalid characters" if Util.invalid_path_segment?(subscription_id)
13
+
12
14
  response = @config.http.put("#{@config.base_merchant_path}/subscriptions/#{subscription_id}/cancel")
13
15
  if response[:subscription]
14
16
  SuccessfulResult.new(:subscription => Subscription._new(@gateway, response[:subscription]))
@@ -36,6 +38,8 @@ module Braintree
36
38
 
37
39
  def find(id)
38
40
  raise ArgumentError if id.nil? || id.to_s.strip == ""
41
+ raise ArgumentError, "id contains invalid characters" if Util.invalid_path_segment?(id)
42
+
39
43
  response = @config.http.get("#{@config.base_merchant_path}/subscriptions/#{id}")
40
44
  Subscription._new(@gateway, response[:subscription])
41
45
  rescue NotFoundError
@@ -55,6 +59,8 @@ module Braintree
55
59
  end
56
60
 
57
61
  def update(subscription_id, attributes)
62
+ raise ArgumentError, "subscription_id contains invalid characters" if Util.invalid_path_segment?(subscription_id)
63
+
58
64
  Util.verify_keys(SubscriptionGateway._update_signature, attributes)
59
65
  response = @config.http.put("#{@config.base_merchant_path}/subscriptions/#{subscription_id}", :subscription => attributes)
60
66
  if response[:subscription]
@@ -10,6 +10,7 @@ module Braintree
10
10
 
11
11
  def settle(transaction_id)
12
12
  check_environment
13
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
13
14
 
14
15
  response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/settle")
15
16
  @transaction_gateway._handle_transaction_response(response)
@@ -17,6 +18,7 @@ module Braintree
17
18
 
18
19
  def settlement_confirm(transaction_id)
19
20
  check_environment
21
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
20
22
 
21
23
  response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/settlement_confirm")
22
24
  @transaction_gateway._handle_transaction_response(response)
@@ -24,6 +26,7 @@ module Braintree
24
26
 
25
27
  def settlement_decline(transaction_id)
26
28
  check_environment
29
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
27
30
 
28
31
  response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/settlement_decline")
29
32
  @transaction_gateway._handle_transaction_response(response)
@@ -31,6 +34,7 @@ module Braintree
31
34
 
32
35
  def settlement_pending(transaction_id)
33
36
  check_environment
37
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
34
38
 
35
39
  response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/settlement_pending")
36
40
  @transaction_gateway._handle_transaction_response(response)
@@ -0,0 +1,11 @@
1
+ module Braintree
2
+ module ThreeDSecurePassThru
3
+ module Network
4
+ Eftpos = "eftpos"
5
+ MasterCard = "Mastercard"
6
+ Visa = "Visa"
7
+
8
+ All = constants.map { |c| const_get(c) }
9
+ end
10
+ end
11
+ end
@@ -3,6 +3,12 @@ module Braintree
3
3
  include BaseModule
4
4
  include Braintree::Util::IdEquality
5
5
 
6
+ module AchType
7
+ SameDay = "same_day"
8
+ Standard = "standard"
9
+ All = constants.map { |c| const_get(c) }
10
+ end
11
+
6
12
  module CreatedUsing
7
13
  FullInformation = "full_information"
8
14
  Token = "token"
@@ -22,7 +22,7 @@ module Braintree
22
22
  end
23
23
 
24
24
  def cancel_release(transaction_id)
25
- raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/
25
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
26
26
  response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/cancel_release")
27
27
  _handle_transaction_response(response)
28
28
  end
@@ -42,6 +42,8 @@ module Braintree
42
42
  end
43
43
 
44
44
  def clone_transaction(transaction_id, attributes)
45
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
46
+
45
47
  Util.verify_keys(TransactionGateway._clone_signature, attributes)
46
48
  _do_create "/transactions/#{transaction_id}/clone", :transaction_clone => attributes
47
49
  end
@@ -59,7 +61,9 @@ module Braintree
59
61
  end
60
62
 
61
63
  def find(id)
62
- raise ArgumentError, "id can not be empty" if id.nil? || id.strip.to_s == ""
64
+ raise ArgumentError, "id can not be empty" if id.nil? || id.to_s.strip == ""
65
+ raise ArgumentError, "id contains invalid characters" if Util.invalid_path_segment?(id)
66
+
63
67
  response = @config.http.get("#{@config.base_merchant_path}/transactions/#{id}")
64
68
  Transaction._new(@gateway, response[:transaction])
65
69
  rescue NotFoundError
@@ -67,6 +71,8 @@ module Braintree
67
71
  end
68
72
 
69
73
  def refund(transaction_id, amount_or_options = nil)
74
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
75
+
70
76
  options = if amount_or_options.is_a?(Hash)
71
77
  amount_or_options
72
78
  else
@@ -103,7 +109,7 @@ module Braintree
103
109
  end
104
110
 
105
111
  def package_tracking(transaction_id, package_tracking_request)
106
- raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/
112
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
107
113
  Util.verify_keys(TransactionGateway._package_tracking_request_signature, package_tracking_request)
108
114
  _do_create "/transactions/#{transaction_id}/shipments", :shipment => package_tracking_request
109
115
  end
@@ -126,7 +132,7 @@ module Braintree
126
132
  end
127
133
 
128
134
  def submit_for_settlement(transaction_id, amount = nil, options = {})
129
- raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/
135
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
130
136
  Util.verify_keys(TransactionGateway._submit_for_settlement_signature, options)
131
137
  transaction_params = {:amount => amount}.merge(options)
132
138
  response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/submit_for_settlement", :transaction => transaction_params)
@@ -138,7 +144,7 @@ module Braintree
138
144
  end
139
145
 
140
146
  def adjust_authorization(transaction_id, amount)
141
- raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/
147
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
142
148
  Util.verify_keys(TransactionGateway._adjust_authorization_signature, {})
143
149
  transaction_params = {:amount => amount}
144
150
  response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/adjust_authorization", :transaction => transaction_params)
@@ -150,14 +156,14 @@ module Braintree
150
156
  end
151
157
 
152
158
  def update_details(transaction_id, options = {})
153
- raise ArgumentError, "transaction_id is invalid" unless transaction_id =~ /\A[0-9a-z]+\z/
159
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
154
160
  Util.verify_keys(TransactionGateway._update_details_signature, options)
155
161
  response = @config.http.put("#{@config.base_merchant_path}/transactions/#{transaction_id}/update_details", :transaction => options)
156
162
  _handle_transaction_response(response)
157
163
  end
158
164
 
159
165
  def submit_for_partial_settlement(authorized_transaction_id, amount = nil, options = {})
160
- raise ArgumentError, "authorized_transaction_id is invalid" unless authorized_transaction_id =~ /\A[0-9a-z]+\z/
166
+ raise ArgumentError, "authorized_transaction_id contains invalid characters" if Util.invalid_path_segment?(authorized_transaction_id)
161
167
  Util.verify_keys(TransactionGateway._submit_for_partial_settlement_signature, options)
162
168
  transaction_params = {:amount => amount}.merge(options)
163
169
  response = @config.http.post("#{@config.base_merchant_path}/transactions/#{authorized_transaction_id}/submit_for_partial_settlement", :transaction => transaction_params)
@@ -169,6 +175,8 @@ module Braintree
169
175
  end
170
176
 
171
177
  def void(transaction_id, options = {})
178
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
179
+
172
180
  transaction_params = options.empty? ? nil : options
173
181
  response = @config.http.put(
174
182
  "#{@config.base_merchant_path}/transactions/#{transaction_id}/void",
@@ -283,6 +291,7 @@ module Braintree
283
291
  :directory_response,
284
292
  :cavv_algorithm,
285
293
  :ds_transaction_id,
294
+ :network,
286
295
  ]
287
296
  },
288
297
  {
@@ -381,6 +390,7 @@ module Braintree
381
390
  :api_request_key,
382
391
  :merchant_account_id,
383
392
  :order_id,
393
+ :surcharge_amount,
384
394
  ]
385
395
  end
386
396
 
@@ -7,7 +7,9 @@ module Braintree
7
7
  end
8
8
 
9
9
  def find_all(transaction_id)
10
- raise ArgumentError, "transaction_id cannot be blank" if transaction_id.nil? || transaction_id.strip.to_s == ""
10
+ raise ArgumentError, "transaction_id cannot be blank" if transaction_id.nil? || transaction_id.to_s.strip == ""
11
+ raise ArgumentError, "transaction_id contains invalid characters" if Util.invalid_path_segment?(transaction_id)
12
+
11
13
  response = @config.http.get("#{@config.base_merchant_path}/transactions/#{transaction_id}/line_items")
12
14
  response[:line_items].map do |line_item_params|
13
15
  TransactionLineItem._new(@gateway, line_item_params)