braintree 2.24.0 → 2.25.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.
@@ -44,6 +44,8 @@ require "braintree/error_result"
44
44
  require "braintree/errors"
45
45
  require "braintree/gateway"
46
46
  require "braintree/http"
47
+ require "braintree/merchant_account"
48
+ require "braintree/merchant_account_gateway"
47
49
  require "braintree/plan"
48
50
  require "braintree/plan_gateway"
49
51
  require "braintree/settlement_batch_summary"
@@ -54,6 +56,7 @@ require "braintree/subscription_gateway"
54
56
  require "braintree/subscription_search"
55
57
  require "braintree/successful_result"
56
58
  require "braintree/test/credit_card"
59
+ require "braintree/test/merchant_account"
57
60
  require "braintree/test/venmo_sdk"
58
61
  require "braintree/test/transaction_amounts"
59
62
  require "braintree/transaction"
@@ -5,13 +5,13 @@ module Braintree
5
5
  module ErrorCodes
6
6
  # See http://www.braintreepayments.com/docs/ruby/addresses/validations
7
7
  module Address
8
- CannotBeBlank = "81801"
9
8
  CompanyIsInvalid = "91821"
10
- CompanyIsTooLong = "81802"
11
- CountryCodeAlpha2IsNotAccepted = "91814"
12
- CountryCodeAlpha3IsNotAccepted = "91816"
13
- CountryCodeNumericIsNotAccepted = "91817"
14
9
  CountryNameIsNotAccepted = "91803"
10
+ CountryCodeAlpha2IsNotAccepted = "91814"
11
+ CountryCodeAlpha3IsNotAccepted = "91816"
12
+ CountryCodeNumericIsNotAccepted = "91817"
13
+ CannotBeBlank = "81801"
14
+ CompanyIsTooLong = "81802"
15
15
  ExtendedAddressIsInvalid = "91823"
16
16
  ExtendedAddressIsTooLong = "81804"
17
17
  FirstNameIsInvalid = "91819"
@@ -37,77 +37,68 @@ module Braintree
37
37
  module CreditCard
38
38
  BillingAddressConflict = "91701"
39
39
  BillingAddressIdIsInvalid = "91702"
40
+ CustomerIdIsRequired = "91704"
41
+ CustomerIdIsInvalid = "91705"
42
+ ExpirationDateConflict = "91708"
43
+ TokenFormatIsInvalid = "91718"
44
+ TokenIsInUse = "91719"
45
+ TokenIsTooLong = "91720"
46
+ TokenIsNotAllowed = "91721"
47
+ TokenIsRequired = "91722"
40
48
  CardholderNameIsTooLong = "81723"
41
49
  CreditCardTypeIsNotAccepted = "81703"
42
50
  CreditCardTypeIsNotAcceptedBySubscriptionMerchantAccount = "81718"
43
- CustomerIdIsInvalid = "91705"
44
- CustomerIdIsRequired = "91704"
45
- CvvIsInvalid = "81707"
46
51
  CvvIsRequired = "81706"
52
+ CvvIsInvalid = "81707"
47
53
  DuplicateCardExists = "81724"
48
- ExpirationDateConflict = "91708"
49
- ExpirationDateIsInvalid = "81710"
50
54
  ExpirationDateIsRequired = "81709"
55
+ ExpirationDateIsInvalid = "81710"
51
56
  ExpirationDateYearIsInvalid = "81711"
52
57
  ExpirationMonthIsInvalid = "81712"
53
58
  ExpirationYearIsInvalid = "81713"
54
59
  InvalidVenmoSDKPaymentMethodCode = "91727"
55
- NumberHasInvalidLength = "81716"
56
- NumberLengthIsInvalid = "81716"
57
- NumberIsInvalid = "81715"
58
60
  NumberIsRequired = "81714"
61
+ NumberIsInvalid = "81715"
62
+ NumberLengthIsInvalid = "81716"
59
63
  NumberMustBeTestNumber = "81717"
60
64
  PaymentMethodConflict = "81725"
61
- TokenInvalid = "91718"
62
- TokenFormatIsInvalid = "91718"
63
- TokenIsInUse = "91719"
64
- TokenIsNotAllowed = "91721"
65
- TokenIsRequired = "91722"
66
- TokenIsTooLong = "91720"
67
65
  VenmoSDKPaymentMethodCodeCardTypeIsNotAccepted = "91726"
66
+ VerificationNotSupportedOnThisMerchantAccount = "91730"
68
67
 
69
68
  module Options
70
69
  UpdateExistingTokenIsInvalid = "91723"
71
70
  VerificationMerchantAccountIdIsInvalid = "91728"
71
+ UpdateExistingTokenNotAllowed = "91729"
72
72
  end
73
73
  end
74
74
 
75
75
  # See http://www.braintreepayments.com/docs/ruby/customers/validations
76
76
  module Customer
77
- CompanyIsTooLong = "81601"
78
77
  CustomFieldIsInvalid = "91602"
79
- CustomFieldIsTooLong = "81603"
80
- EmailIsInvalid = "81604"
81
- EmailFormatIsInvalid = "81604"
82
- EmailIsRequired = "81606"
83
- EmailIsTooLong = "81605"
84
- FaxIsTooLong = "81607"
85
- FirstNameIsTooLong = "81608"
86
78
  IdIsInUse = "91609"
87
- IdIsInvaild = "91610" # Deprecated
88
79
  IdIsInvalid = "91610"
89
80
  IdIsNotAllowed = "91611"
90
81
  IdIsRequired = "91613"
91
82
  IdIsTooLong = "91612"
83
+ CompanyIsTooLong = "81601"
84
+ CustomFieldIsTooLong = "81603"
85
+ EmailFormatIsInvalid = "81604"
86
+ EmailIsTooLong = "81605"
87
+ EmailIsRequired = "81606"
88
+ FaxIsTooLong = "81607"
89
+ FirstNameIsTooLong = "81608"
92
90
  LastNameIsTooLong = "81613"
93
91
  PhoneIsTooLong = "81614"
94
- WebsiteIsInvalid = "81616"
95
- WebsiteFormatIsInvalid = "81616"
96
92
  WebsiteIsTooLong = "81615"
93
+ WebsiteFormatIsInvalid = "81616"
97
94
  end
98
95
 
99
96
  module Descriptor
100
- DynamicDescriptorsDisabled = "92203"
101
- InternationalPhoneFormatIsInvalid = "92205"
102
- InternationalNameFormatIsInvalid = "92204"
103
97
  NameFormatIsInvalid = "92201"
104
98
  PhoneFormatIsInvalid = "92202"
105
- end
106
-
107
- module SettlementBatchSummary
108
- CustomFieldIsInvalid = "82303"
109
- SettlementDateIsInvalid = "82302"
110
- SettlementDateIsRequired = "82301"
99
+ DynamicDescriptorsDisabled = "92203"
100
+ InternationalNameFormatIsInvalid = "92204"
101
+ InternationalPhoneFormatIsInvalid = "92205"
111
102
  end
112
103
 
113
104
  # See http://www.braintreepayments.com/docs/ruby/subscriptions/validations
@@ -173,22 +164,26 @@ module Braintree
173
164
  # See http://www.braintreepayments.com/docs/ruby/transactions/validations
174
165
  module Transaction
175
166
  AmountCannotBeNegative = "81501"
176
- AmountIsInvalid = "81503"
177
- AmountFormatIsInvalid = "81503"
167
+ AmountFormatIsInvalid = "81503" # Keep for backwards compatibility
168
+ AmountIsInvalid = "81503" # Keep for backwards compatibility
178
169
  AmountIsRequired = "81502"
179
170
  AmountIsTooLarge = "81528"
180
171
  AmountMustBeGreaterThanZero = "81531"
181
172
  BillingAddressConflict = "91530"
182
173
  CannotBeVoided = "91504"
174
+ CannotCancelRelease = "91562"
183
175
  CannotCloneCredit = "91543"
184
176
  CannotCloneTransactionWithVaultCreditCard = "91540"
185
177
  CannotCloneUnsuccessfulTransaction = "91542"
186
178
  CannotCloneVoiceAuthorizations = "91541"
179
+ CannotHoldInEscrow = "91560"
180
+ CannotPartiallyRefundEscrowedTransaction = "91563"
187
181
  CannotRefundCredit = "91505"
188
182
  CannotRefundUnlessSettled = "91506"
183
+ CannotRefundWithPendingMerchantAccount = "91559"
189
184
  CannotRefundWithSuspendedMerchantAccount = "91538"
185
+ CannotReleaseFromEscrow = "91561"
190
186
  CannotSubmitForSettlement = "91507"
191
- ChannelIsTooLong = "91550"
192
187
  CreditCardIsRequired = "91508"
193
188
  CustomFieldIsInvalid = "91526"
194
189
  CustomFieldIsTooLong = "81527"
@@ -196,11 +191,12 @@ module Braintree
196
191
  CustomerDoesNotHaveCreditCard = "91511"
197
192
  CustomerIdIsInvalid = "91510"
198
193
  HasAlreadyBeenRefunded = "91512"
194
+ MerchantAccountDoesNotSupportRefunds = "91547"
195
+ MerchantAccountDoesNotSupportMOTO = "91558"
199
196
  MerchantAccountIdIsInvalid = "91513"
200
197
  MerchantAccountIsSuspended = "91514"
201
- MerchantAccountDoesNotSupportRefunds = "91547"
202
- MerchantAccountNameIsInvalid = "91513" # Deprecated
203
198
  OrderIdIsTooLong = "91501"
199
+ ChannelIsTooLong = "91550"
204
200
  PaymentMethodConflict = "91515"
205
201
  PaymentMethodConflictWithVenmoSDK = "91549"
206
202
  PaymentMethodDoesNotBelongToCustomer = "91516"
@@ -211,10 +207,17 @@ module Braintree
211
207
  ProcessorAuthorizationCodeIsInvalid = "81520"
212
208
  ProcessorDoesNotSupportCredits = "91546"
213
209
  ProcessorDoesNotSupportVoiceAuthorizations = "91545"
214
- PurchaseOrderNumberIsTooLong = "91537"
215
210
  PurchaseOrderNumberIsInvalid = "91548"
211
+ PurchaseOrderNumberIsTooLong = "91537"
216
212
  RefundAmountIsTooLarge = "91521"
213
+ ServiceFeeAmountCannotBeNegative = "91554"
214
+ ServiceFeeAmountFormatIsInvalid = "91555"
215
+ ServiceFeeAmountIsTooLarge = "91556"
216
+ ServiceFeeIsNotAllowedOnCredits = "91552"
217
+ ServiceFeeAmountNotAllowedOnMasterMerchantAccount = "91557"
218
+ SettlementAmountIsLessThanServiceFeeAmount = "91551"
217
219
  SettlementAmountIsTooLarge = "91522"
220
+ SubMerchantAccountRequiresServiceFeeAmount = "91553"
218
221
  SubscriptionDoesNotBelongToCustomer = "91529"
219
222
  SubscriptionIdIsInvalid = "91528"
220
223
  SubscriptionStatusMustBePastDue = "91531"
@@ -230,5 +233,56 @@ module Braintree
230
233
  VaultIsDisabled = "91525"
231
234
  end
232
235
  end
236
+
237
+ module MerchantAccount
238
+ IdIsTooLong = "82602"
239
+ IdFormatIsInvalid = "82603"
240
+ IdIsInUse = "82604"
241
+ IdIsNotAllowed = "82605"
242
+ MasterMerchantAccountIdIsRequired = "82606"
243
+ MasterMerchantAccountIdIsInvalid = "82607"
244
+ MasterMerchantAccountMustBeActive = "82608"
245
+ TosAcceptedIsRequired = "82610"
246
+
247
+ module ApplicantDetails
248
+ FirstNameIsRequired = "82609"
249
+ LastNameIsRequired = "82611"
250
+ DateOfBirthIsRequired = "82612"
251
+ RoutingNumberIsRequired = "82613"
252
+ AccountNumberIsRequired = "82614"
253
+ SsnIsInvalid = "82615"
254
+ EmailAddressIsInvalid = "82616"
255
+ FirstNameIsInvalid = "82627"
256
+ LastNameIsInvalid = "82628"
257
+ CompanyNameIsInvalid = "82631"
258
+ TaxIdIsInvalid = "82632"
259
+ CompanyNameIsRequiredWithTaxId = "82633"
260
+ TaxIdIsRequiredWithCompanyName = "82634"
261
+ RoutingNumberIsInvalid = "82635"
262
+ DeclinedOFAC = "82621"
263
+ DeclinedMasterCardMatch = "82622"
264
+ DeclinedFailedKYC = "82623"
265
+ DeclinedSsnInvalid = "82624"
266
+ DeclinedSsnMatchesDeceased = "82625"
267
+ Declined = "82626"
268
+ PhoneIsInvalid = "82636"
269
+
270
+ module Address
271
+ StreetAddressIsRequired = "82617"
272
+ LocalityIsRequired = "82618"
273
+ PostalCodeIsRequired = "82619"
274
+ RegionIsRequired = "82620"
275
+ StreetAddressIsInvalid = "82629"
276
+ PostalCodeIsInvalid = "82630"
277
+ end
278
+ end
279
+ end
280
+
281
+ module SettlementBatchSummary
282
+ SettlementDateIsRequired = "82301"
283
+ SettlementDateIsInvalid = "82302"
284
+ CustomFieldIsInvalid = "82303"
285
+ end
233
286
  end
234
287
  end
288
+
@@ -2,12 +2,13 @@ module Braintree
2
2
  # See http://www.braintreepayments.com/docs/ruby/general/result_objects
3
3
  class ErrorResult
4
4
 
5
- attr_reader :credit_card_verification, :transaction, :subscription, :errors, :params, :message
5
+ attr_reader :credit_card_verification, :merchant_account, :transaction, :subscription, :errors, :params, :message
6
6
 
7
7
  def initialize(gateway, data) # :nodoc:
8
8
  @gateway = gateway
9
9
  @params = data[:params]
10
10
  @credit_card_verification = CreditCardVerification._new(data[:verification]) if data[:verification]
11
+ @merchant_account = MerchantAccount._new(gateway, data[:merchant_account]) if data[:merchant_account]
11
12
  @message = data[:message]
12
13
  @transaction = Transaction._new(gateway, data[:transaction]) if data[:transaction]
13
14
  @subscription = Subscription._new(gateway, data[:subscription]) if data[:subscription]
@@ -36,6 +36,10 @@ module Braintree
36
36
  PlanGateway.new(self)
37
37
  end
38
38
 
39
+ def merchant_account
40
+ MerchantAccountGateway.new(self)
41
+ end
42
+
39
43
  def settlement_batch_summary
40
44
  SettlementBatchSummaryGateway.new(self)
41
45
  end
@@ -0,0 +1,38 @@
1
+ module Braintree
2
+ class MerchantAccount
3
+ include BaseModule
4
+
5
+ module Status
6
+ Pending = "pending"
7
+ Active = "active"
8
+ Suspended = "suspended"
9
+ end
10
+
11
+ attr_reader :status, :id, :master_merchant_account
12
+
13
+ def self.create(attributes)
14
+ Configuration.gateway.merchant_account.create(attributes)
15
+ end
16
+
17
+ def initialize(gateway, attributes) # :nodoc
18
+ @gateway = gateway
19
+ @master_merchant_account = MerchantAccount._new(@gateway, attributes.delete(:master_merchant_account)) if attributes[:master_merchant_account]
20
+ set_instance_variables_from_hash(attributes)
21
+ end
22
+
23
+ class << self
24
+ protected :new
25
+ def _new(*args) # :nodoc:
26
+ self.new *args
27
+ end
28
+ end
29
+
30
+ def inspect
31
+ order = [:id, :status, :master_merchant_account]
32
+ nice_attributes = order.map do |attr|
33
+ "#{attr}: #{send(attr).inspect}"
34
+ end
35
+ "#<#{self.class}: #{nice_attributes.join(', ')}>"
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,33 @@
1
+ module Braintree
2
+ class MerchantAccountGateway # :nodoc:
3
+ def initialize(gateway)
4
+ @gateway = gateway
5
+ @config = gateway.config
6
+ end
7
+
8
+ def create(attributes)
9
+ Util.verify_keys(MerchantAccountGateway._create_signature, attributes)
10
+ _do_create "/merchant_accounts/create_via_api", :merchant_account => attributes
11
+ end
12
+
13
+ def _do_create(url, params=nil) # :nodoc:
14
+ response = @config.http.post url, params
15
+ if response[:api_error_response]
16
+ ErrorResult.new(@gateway, response[:api_error_response])
17
+ else
18
+ SuccessfulResult.new(:merchant_account => MerchantAccount._new(@gateway, response[:merchant_account]))
19
+ end
20
+ end
21
+
22
+ def self._create_signature # :nodoc:
23
+ [
24
+ {:applicant_details => [
25
+ :first_name, :last_name, :email, :date_of_birth, :ssn, :routing_number,
26
+ :account_number, :tax_id, :company_name, :phone,
27
+ {:address => [:street_address, :postal_code, :locality, :region]}]
28
+ },
29
+ :tos_accepted, :master_merchant_account_id, :id
30
+ ]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ module Braintree
2
+ module Test # :nodoc:
3
+ module MerchantAccount
4
+ Approve = "approve_me"
5
+ end
6
+ end
7
+ end
@@ -8,6 +8,14 @@ module Braintree
8
8
  Token = 'token'
9
9
  end
10
10
 
11
+ module EscrowStatus
12
+ HoldPending = 'hold_pending'
13
+ Held = 'held'
14
+ ReleasePending = 'release_pending'
15
+ Released = 'released'
16
+ Refunded = 'refunded'
17
+ end
18
+
11
19
  module GatewayRejectionReason
12
20
  AVS = "avs"
13
21
  AVSAndCVV = "avs_and_cvv"
@@ -44,12 +52,13 @@ module Braintree
44
52
  end
45
53
 
46
54
  attr_reader :avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code
47
- attr_reader :amount, :created_at, :credit_card_details, :customer_details, :subscription_details, :id
55
+ attr_reader :amount, :created_at, :credit_card_details, :customer_details, :subscription_details, :service_fee_amount, :id
48
56
  attr_reader :currency_iso_code
49
57
  attr_reader :custom_fields
50
58
  attr_reader :cvv_response_code
51
59
  attr_reader :disbursement_details
52
60
  attr_reader :descriptor
61
+ attr_reader :escrow_status
53
62
  attr_reader :gateway_rejection_reason
54
63
  attr_reader :merchant_account_id
55
64
  attr_reader :order_id
@@ -87,6 +96,14 @@ module Braintree
87
96
  return_object_or_raise(:transaction) { create(attributes) }
88
97
  end
89
98
 
99
+ def self.cancel_release(transaction_id)
100
+ Configuration.gateway.transaction.cancel_release(transaction_id)
101
+ end
102
+
103
+ def self.cancel_release!(transaction_id)
104
+ return_object_or_raise(:transaction) { cancel_release(transaction_id) }
105
+ end
106
+
90
107
  def self.clone_transaction(transaction_id, attributes)
91
108
  Configuration.gateway.transaction.clone_transaction(transaction_id, attributes)
92
109
  end
@@ -124,6 +141,14 @@ module Braintree
124
141
  Configuration.gateway.transaction.find(id)
125
142
  end
126
143
 
144
+ def self.hold_in_escrow(id)
145
+ Configuration.gateway.transaction.hold_in_escrow(id)
146
+ end
147
+
148
+ def self.hold_in_escrow!(id)
149
+ return_object_or_raise(:transaction) { hold_in_escrow(id) }
150
+ end
151
+
127
152
  # See http://www.braintreepayments.com/docs/ruby/transactions/refund
128
153
  def self.refund(id, amount = nil)
129
154
  Configuration.gateway.transaction.refund(id, amount)
@@ -149,6 +174,14 @@ module Braintree
149
174
  Configuration.gateway.transaction.search(&block)
150
175
  end
151
176
 
177
+ def self.release_from_escrow(transaction_id)
178
+ Configuration.gateway.transaction.release_from_escrow(transaction_id)
179
+ end
180
+
181
+ def self.release_from_escrow!(transaction_id)
182
+ return_object_or_raise(:transaction) { release_from_escrow(transaction_id) }
183
+ end
184
+
152
185
  # See http://www.braintreepayments.com/docs/ruby/transactions/submit_for_settlement
153
186
  def self.submit_for_settlement(transaction_id, amount = nil)
154
187
  Configuration.gateway.transaction.submit_for_settlement(transaction_id, amount)
@@ -174,6 +207,7 @@ module Braintree
174
207
  set_instance_variables_from_hash(attributes)
175
208
  @amount = Util.to_big_decimal(amount)
176
209
  @credit_card_details = CreditCardDetails.new(@credit_card)
210
+ @service_fee_amount = Util.to_big_decimal(service_fee_amount)
177
211
  @subscription_details = SubscriptionDetails.new(@subscription)
178
212
  @customer_details = CustomerDetails.new(@customer)
179
213
  @billing_details = AddressDetails.new(@billing)
@@ -27,6 +27,10 @@ module Braintree
27
27
  def masked_number
28
28
  "#{bin}******#{last_4}"
29
29
  end
30
+
31
+ def venmo_sdk?
32
+ @venmo_sdk
33
+ end
30
34
  end
31
35
  end
32
36
  end