braintree-rails 1.3.0 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +48 -34
- data/braintree-rails.gemspec +7 -7
- data/lib/braintree_rails/address.rb +1 -1
- data/lib/braintree_rails/address_validator.rb +1 -1
- data/lib/braintree_rails/api_error.rb +1 -1
- data/lib/braintree_rails/billing_address.rb +5 -1
- data/lib/braintree_rails/business_details.rb +1 -1
- data/lib/braintree_rails/credit_card.rb +2 -2
- data/lib/braintree_rails/customer.rb +2 -2
- data/lib/braintree_rails/individual_details.rb +1 -1
- data/lib/braintree_rails/merchant_account.rb +6 -2
- data/lib/braintree_rails/model.rb +7 -9
- data/lib/braintree_rails/persistence.rb +2 -20
- data/lib/braintree_rails/shipping_address.rb +5 -1
- data/lib/braintree_rails/transaction.rb +5 -5
- data/lib/braintree_rails/transaction_validator.rb +1 -1
- data/lib/braintree_rails/validator.rb +1 -1
- data/lib/braintree_rails/version.rb +1 -1
- data/spec/fixtures/merchant_account.xml +1 -1
- data/spec/fixtures/transaction_error.xml +65 -20
- data/spec/integration/braintree_rails/address_integration_spec.rb +6 -6
- data/spec/integration/braintree_rails/credit_card_integration_spec.rb +17 -17
- data/spec/integration/braintree_rails/customer_integration_spec.rb +17 -17
- data/spec/integration/braintree_rails/merchant_account_integration_spec.rb +11 -11
- data/spec/integration/braintree_rails/transaction_integration_spec.rb +24 -25
- data/spec/integration/integration_spec_helper.rb +2 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/support/helper.rb +16 -2
- data/spec/unit/braintree_rails/add_on_spec.rb +10 -11
- data/spec/unit/braintree_rails/add_ons_spec.rb +3 -3
- data/spec/unit/braintree_rails/address_details_spec.rb +3 -3
- data/spec/unit/braintree_rails/address_spec.rb +26 -26
- data/spec/unit/braintree_rails/addresses_spec.rb +7 -7
- data/spec/unit/braintree_rails/business_details_spec.rb +8 -8
- data/spec/unit/braintree_rails/configuration_spec.rb +6 -6
- data/spec/unit/braintree_rails/credit_card_spec.rb +76 -76
- data/spec/unit/braintree_rails/credit_cards_spec.rb +11 -11
- data/spec/unit/braintree_rails/customer_spec.rb +44 -44
- data/spec/unit/braintree_rails/discount_spec.rb +10 -11
- data/spec/unit/braintree_rails/discounts_spec.rb +3 -3
- data/spec/unit/braintree_rails/funding_details_spec.rb +12 -12
- data/spec/unit/braintree_rails/individual_details_spec.rb +5 -5
- data/spec/unit/braintree_rails/luhn_10_validator_spec.rb +5 -5
- data/spec/unit/braintree_rails/merchant_account_spec.rb +14 -14
- data/spec/unit/braintree_rails/plan_spec.rb +12 -12
- data/spec/unit/braintree_rails/subscription_spec.rb +53 -53
- data/spec/unit/braintree_rails/subscriptions_spec.rb +4 -5
- data/spec/unit/braintree_rails/transaction_spec.rb +67 -55
- data/spec/unit/braintree_rails/transactions_spec.rb +9 -9
- data/spec/unit/braintree_rails/validation_error_spec.rb +4 -4
- data/spec/unit/braintree_rails/validator_spec.rb +7 -7
- metadata +35 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: beb78e264daf6f5aa910f0f22a037a401de719ee
|
4
|
+
data.tar.gz: 964ddabe92b7e24904d9fc2a7611c3eb7f57721f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45abffe047116fef0dff574b3bc833afa11e1c44af7c1019776b387f5f80123d0e4bf186200fa0f6bac331d1cda858080ef50d864d7656d367afb5d74c133c4e
|
7
|
+
data.tar.gz: 1c45542fe5e4ce03cd46a8b2e00f0a289c4f5fdbc643b7af83624c21962b317a09636c019eda5bd7b1b5fecd421ce1ddb300bfa5c126ab272b25e3e730af3745
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,18 @@
|
|
1
1
|
## Unreleased (master)
|
2
|
+
### Enhancements
|
3
|
+
* Added `service_fee_amount` to `BraintreeRails::Transaction`. (Thanks, @KELiON)
|
4
|
+
* Enhanced validation error parsing so that they can be customized/i18n-ed
|
5
|
+
|
6
|
+
### Bug Fixes
|
7
|
+
* Fixed deprecation warnings about validator setup. (Thanks, @JWesorick)
|
8
|
+
|
9
|
+
## v1.3.0 (74bd8df), Apr 18 2014
|
2
10
|
### Enhancements
|
3
11
|
* Added Braintree Marketplace related models
|
12
|
+
* Allow device_data to be passed through for Fraud tools integration
|
13
|
+
|
14
|
+
### Bug Fixes
|
15
|
+
* Fixed a bug where it failed to load some models under some circumstances. (Thanks, @mbhnyc and @tmak)
|
4
16
|
|
5
17
|
## v1.2.3 (a9f5bf4), Jan 21 2014
|
6
18
|
### Enhancements
|
data/Gemfile.lock
CHANGED
@@ -1,50 +1,64 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
activemodel (
|
5
|
-
activesupport (=
|
6
|
-
builder (~> 3.
|
7
|
-
activesupport (
|
8
|
-
i18n (
|
9
|
-
|
10
|
-
|
11
|
-
|
4
|
+
activemodel (4.1.8)
|
5
|
+
activesupport (= 4.1.8)
|
6
|
+
builder (~> 3.1)
|
7
|
+
activesupport (4.1.8)
|
8
|
+
i18n (~> 0.6, >= 0.6.9)
|
9
|
+
json (~> 1.7, >= 1.7.7)
|
10
|
+
minitest (~> 5.1)
|
11
|
+
thread_safe (~> 0.1)
|
12
|
+
tzinfo (~> 1.1)
|
13
|
+
addressable (2.3.6)
|
14
|
+
braintree (2.38.0)
|
12
15
|
builder (>= 2.0.0)
|
13
|
-
builder (3.
|
14
|
-
coveralls (0.7.
|
16
|
+
builder (3.2.2)
|
17
|
+
coveralls (0.7.2)
|
15
18
|
multi_json (~> 1.3)
|
16
|
-
rest-client
|
19
|
+
rest-client (= 1.6.7)
|
17
20
|
simplecov (>= 0.7)
|
18
|
-
term-ansicolor
|
19
|
-
thor
|
20
|
-
crack (0.
|
21
|
+
term-ansicolor (= 1.2.2)
|
22
|
+
thor (= 0.18.1)
|
23
|
+
crack (0.4.2)
|
24
|
+
safe_yaml (~> 1.0.0)
|
21
25
|
diff-lcs (1.2.5)
|
22
|
-
docile (1.1.
|
23
|
-
i18n (0.6.
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
docile (1.1.5)
|
27
|
+
i18n (0.6.11)
|
28
|
+
json (1.8.1)
|
29
|
+
mime-types (2.4.3)
|
30
|
+
minitest (5.4.3)
|
31
|
+
multi_json (1.10.1)
|
32
|
+
rake (10.4.2)
|
27
33
|
rest-client (1.6.7)
|
28
34
|
mime-types (>= 1.16)
|
29
|
-
rspec (
|
30
|
-
rspec-core (~>
|
31
|
-
rspec-expectations (~>
|
32
|
-
rspec-mocks (~>
|
33
|
-
rspec-core (
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
rspec (3.1.0)
|
36
|
+
rspec-core (~> 3.1.0)
|
37
|
+
rspec-expectations (~> 3.1.0)
|
38
|
+
rspec-mocks (~> 3.1.0)
|
39
|
+
rspec-core (3.1.7)
|
40
|
+
rspec-support (~> 3.1.0)
|
41
|
+
rspec-expectations (3.1.2)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.1.0)
|
44
|
+
rspec-mocks (3.1.3)
|
45
|
+
rspec-support (~> 3.1.0)
|
46
|
+
rspec-support (3.1.2)
|
47
|
+
safe_yaml (1.0.4)
|
48
|
+
simplecov (0.9.1)
|
38
49
|
docile (~> 1.1.0)
|
39
|
-
multi_json
|
50
|
+
multi_json (~> 1.0)
|
40
51
|
simplecov-html (~> 0.8.0)
|
41
52
|
simplecov-html (0.8.0)
|
42
|
-
term-ansicolor (1.
|
43
|
-
tins (~>
|
53
|
+
term-ansicolor (1.2.2)
|
54
|
+
tins (~> 0.8)
|
44
55
|
thor (0.18.1)
|
45
|
-
|
46
|
-
|
47
|
-
|
56
|
+
thread_safe (0.3.4)
|
57
|
+
tins (0.13.2)
|
58
|
+
tzinfo (1.2.2)
|
59
|
+
thread_safe (~> 0.1)
|
60
|
+
webmock (1.20.4)
|
61
|
+
addressable (>= 2.3.6)
|
48
62
|
crack (>= 0.3.2)
|
49
63
|
|
50
64
|
PLATFORMS
|
data/braintree-rails.gemspec
CHANGED
@@ -12,11 +12,11 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.test_files = Dir['spec/**']
|
13
13
|
spec.homepage = 'https://github.com/lyang/braintree-rails'
|
14
14
|
spec.required_ruby_version = '>= 1.9.2'
|
15
|
-
spec.add_runtime_dependency 'braintree', '>= 2.28.0'
|
16
|
-
spec.add_runtime_dependency 'activemodel', '>= 3.0'
|
17
|
-
spec.add_runtime_dependency 'activesupport', '>= 3.0'
|
18
|
-
spec.add_development_dependency 'rake'
|
19
|
-
spec.add_development_dependency 'rspec'
|
20
|
-
spec.add_development_dependency 'webmock'
|
21
|
-
spec.add_development_dependency 'coveralls'
|
15
|
+
spec.add_runtime_dependency 'braintree', '>= 2.28.0', '< 3'
|
16
|
+
spec.add_runtime_dependency 'activemodel', '>= 3.0', '< 5'
|
17
|
+
spec.add_runtime_dependency 'activesupport', '>= 3.0', '< 5'
|
18
|
+
spec.add_development_dependency 'rake', '~> 10'
|
19
|
+
spec.add_development_dependency 'rspec', '~> 3'
|
20
|
+
spec.add_development_dependency 'webmock', '~> 1'
|
21
|
+
spec.add_development_dependency 'coveralls', '~> 0'
|
22
22
|
end
|
@@ -45,7 +45,7 @@ module BraintreeRails
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def add_errors(validation_errors)
|
48
|
-
billing_address.add_errors(validation_errors
|
48
|
+
billing_address.add_errors(extract_errors(validation_errors)) if billing_address
|
49
49
|
super(validation_errors)
|
50
50
|
end
|
51
51
|
|
@@ -75,4 +75,4 @@ module BraintreeRails
|
|
75
75
|
changed.include?(:expiration_month) || changed.include?(:expiration_year)
|
76
76
|
end
|
77
77
|
end
|
78
|
-
end
|
78
|
+
end
|
@@ -29,7 +29,7 @@ module BraintreeRails
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def add_errors(validation_errors)
|
32
|
-
credit_card.add_errors(validation_errors
|
32
|
+
credit_card.add_errors(extract_errors(validation_errors)) if credit_card
|
33
33
|
super(validation_errors)
|
34
34
|
end
|
35
35
|
|
@@ -45,4 +45,4 @@ module BraintreeRails
|
|
45
45
|
credit_card.present? ? {:credit_card => credit_card.attributes_for(action).except(:customer_id, :token)} : {}
|
46
46
|
end
|
47
47
|
end
|
48
|
-
end
|
48
|
+
end
|
@@ -20,9 +20,13 @@ module BraintreeRails
|
|
20
20
|
after_create :reload, :if => :persisted?
|
21
21
|
|
22
22
|
def add_errors(validation_errors)
|
23
|
+
propergate_errors_to_associations(extract_errors(validation_errors))
|
24
|
+
super(validation_errors)
|
25
|
+
end
|
26
|
+
|
27
|
+
def propergate_errors_to_associations(validation_errors)
|
23
28
|
[individual, business, funding].each do |association|
|
24
|
-
association.add_errors(validation_errors
|
25
|
-
super(validation_errors)
|
29
|
+
association.add_errors(validation_errors) if association
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
@@ -40,17 +40,15 @@ module BraintreeRails
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def add_errors(validation_errors)
|
43
|
-
validation_errors.each do |
|
44
|
-
|
45
|
-
Array(message).each do |msg|
|
46
|
-
self.errors.add(attribute, msg)
|
47
|
-
end
|
48
|
-
elsif respond_to?(attribute)
|
49
|
-
self.errors.add(attribute, message)
|
50
|
-
end
|
43
|
+
Array(extract_errors(validation_errors)).each do |error|
|
44
|
+
self.errors.add(error.attribute.to_sym, error.code.to_sym, message:BraintreeRails::ApiError.new(error.message, error.code))
|
51
45
|
end
|
52
46
|
end
|
53
47
|
|
48
|
+
def extract_errors(validation_errors)
|
49
|
+
validation_errors.for(self.class.braintree_model_name.to_sym)
|
50
|
+
end
|
51
|
+
|
54
52
|
def ==(other)
|
55
53
|
return false unless other.is_a?(self.class) || other.is_a?(self.class.braintree_model_class)
|
56
54
|
id == other.id
|
@@ -73,4 +71,4 @@ module BraintreeRails
|
|
73
71
|
receiver.extend ClassMethods
|
74
72
|
end
|
75
73
|
end
|
76
|
-
end
|
74
|
+
end
|
@@ -116,7 +116,7 @@ module BraintreeRails
|
|
116
116
|
run_callbacks context do
|
117
117
|
result = yield
|
118
118
|
if result.respond_to?(:success?) && !result.success?
|
119
|
-
add_errors(
|
119
|
+
add_errors(result.errors)
|
120
120
|
false
|
121
121
|
else
|
122
122
|
new_record = result.respond_to?(self.class.braintree_model_name) ? result.send(self.class.braintree_model_name) : result
|
@@ -124,24 +124,6 @@ module BraintreeRails
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
end
|
127
|
-
|
128
|
-
def extract_errors(result)
|
129
|
-
base_errors(result).merge(attribute_errors(result))
|
130
|
-
end
|
131
|
-
|
132
|
-
def base_errors(result)
|
133
|
-
all_messages = result.message.split("\n")
|
134
|
-
base_messages = all_messages - attribute_errors(result).values.map(&:to_s)
|
135
|
-
base_messages.empty? ? {} : {'base' => base_messages}
|
136
|
-
end
|
137
|
-
|
138
|
-
def attribute_errors(result)
|
139
|
-
result.errors.inject({}) do |hash, error|
|
140
|
-
next hash if error.attribute.to_s == 'base'
|
141
|
-
hash[error.attribute.to_s] = BraintreeRails::ApiError.new(error.message, error.code)
|
142
|
-
hash
|
143
|
-
end
|
144
|
-
end
|
145
127
|
end
|
146
128
|
|
147
129
|
def self.included(receiver)
|
@@ -154,4 +136,4 @@ module BraintreeRails
|
|
154
136
|
end
|
155
137
|
end
|
156
138
|
end
|
157
|
-
end
|
139
|
+
end
|
@@ -6,7 +6,7 @@ module BraintreeRails
|
|
6
6
|
|
7
7
|
define_attributes(
|
8
8
|
:create => [
|
9
|
-
:amount, :billing, :channel, :custom_fields, :customer_id, :descriptor, :merchant_account_id,
|
9
|
+
:amount, :billing, :channel, :custom_fields, :customer_id, :descriptor, :merchant_account_id, :service_fee_amount,
|
10
10
|
:options, :order_id, :payment_method_token, :purchase_order_number, :recurring, :shipping,
|
11
11
|
:tax_amount, :tax_exempt, :type, :venmo_sdk_payment_method_code, :device_data
|
12
12
|
],
|
@@ -64,7 +64,7 @@ module BraintreeRails
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def add_errors(validation_errors)
|
67
|
-
propergate_errors_to_associations(validation_errors)
|
67
|
+
propergate_errors_to_associations(extract_errors(validation_errors))
|
68
68
|
super(validation_errors)
|
69
69
|
end
|
70
70
|
|
@@ -80,9 +80,9 @@ module BraintreeRails
|
|
80
80
|
|
81
81
|
protected
|
82
82
|
|
83
|
-
def propergate_errors_to_associations(
|
83
|
+
def propergate_errors_to_associations(errors)
|
84
84
|
[customer, credit_card, billing, shipping].each do |association|
|
85
|
-
association.add_errors(
|
85
|
+
association.add_errors(errors) if association
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -116,4 +116,4 @@ module BraintreeRails
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
119
|
-
end
|
119
|
+
end
|
@@ -8,7 +8,7 @@ module BraintreeRails
|
|
8
8
|
[:status, :inclusion => {:in => [Braintree::Transaction::Status::Authorized, Braintree::Transaction::Status::SubmittedForSettlement]}, :on => :void]
|
9
9
|
]
|
10
10
|
|
11
|
-
def
|
11
|
+
def initialize(*)
|
12
12
|
self.class.model_class.class_eval do
|
13
13
|
define_model_callbacks :submit_for_settlement, :refund, :void
|
14
14
|
end
|
@@ -1,44 +1,89 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<api-error-response>
|
3
|
-
<message>Credit card type is not accepted by this merchant account.
|
4
|
-
Credit card number is invalid.</message>
|
5
3
|
<errors>
|
4
|
+
<errors type="array"/>
|
6
5
|
<transaction>
|
6
|
+
<errors type="array">
|
7
|
+
<error>
|
8
|
+
<code>91577</code>
|
9
|
+
<attribute type="symbol">merchant_account_id</attribute>
|
10
|
+
<message>Merchant account does not support payment instrument.</message>
|
11
|
+
</error>
|
12
|
+
</errors>
|
13
|
+
<billing>
|
14
|
+
<errors type="array">
|
15
|
+
<error>
|
16
|
+
<code>81809</code>
|
17
|
+
<attribute type="symbol">postal_code</attribute>
|
18
|
+
<message>Postal code may contain no more than 9 letter or number characters.</message>
|
19
|
+
</error>
|
20
|
+
</errors>
|
21
|
+
</billing>
|
22
|
+
<shipping>
|
23
|
+
<errors type="array">
|
24
|
+
<error>
|
25
|
+
<code>81809</code>
|
26
|
+
<attribute type="symbol">postal_code</attribute>
|
27
|
+
<message>Postal code may contain no more than 9 letter or number characters.</message>
|
28
|
+
</error>
|
29
|
+
</errors>
|
30
|
+
</shipping>
|
7
31
|
<credit-card>
|
8
32
|
<errors type="array">
|
9
33
|
<error>
|
10
|
-
<code>
|
11
|
-
<message>Credit card number is invalid.</message>
|
34
|
+
<code>81703</code>
|
12
35
|
<attribute type="symbol">number</attribute>
|
36
|
+
<message>Credit card type is not accepted by this merchant account.</message>
|
37
|
+
</error>
|
38
|
+
<error>
|
39
|
+
<code>81714</code>
|
40
|
+
<attribute type="symbol">number</attribute>
|
41
|
+
<message>Credit card number is required.</message>
|
42
|
+
</error>
|
43
|
+
<error>
|
44
|
+
<code>81725</code>
|
45
|
+
<attribute type="symbol">base</attribute>
|
46
|
+
<message>Credit card must include number, payment_method_nonce, or venmo_sdk_payment_method_code.</message>
|
13
47
|
</error>
|
14
48
|
</errors>
|
15
49
|
</credit-card>
|
16
|
-
<errors type="array"/>
|
17
|
-
<billing>
|
18
|
-
<errors type="array"/>
|
19
|
-
</billing>
|
20
50
|
</transaction>
|
21
|
-
<errors type="array"/>
|
22
51
|
</errors>
|
23
52
|
<params>
|
24
53
|
<transaction>
|
25
|
-
<
|
54
|
+
<device-session-id>66866b285afd0d816de617983444f13d</device-session-id>
|
55
|
+
<fraud-merchant-id>600000</fraud-merchant-id>
|
56
|
+
<amount>7</amount>
|
26
57
|
<billing>
|
27
|
-
<
|
58
|
+
<company>BraintreeRails</company>
|
59
|
+
<country-name>United States of America</country-name>
|
60
|
+
<first-name>Braintree</first-name>
|
61
|
+
<last-name>Rails</last-name>
|
62
|
+
<locality>San Francisco</locality>
|
63
|
+
<postal-code>1234567890</postal-code>
|
28
64
|
<region>California</region>
|
29
|
-
<
|
30
|
-
<company>Pixar</company>
|
31
|
-
<locality>Junk Montain</locality>
|
32
|
-
<street-address>Junk Rd</street-address>
|
33
|
-
<last-name>E</last-name>
|
34
|
-
<postal-code>12345</postal-code>
|
65
|
+
<street-address>185 Berry St</street-address>
|
35
66
|
</billing>
|
36
|
-
<
|
67
|
+
<shipping>
|
68
|
+
<company>BraintreeRails</company>
|
69
|
+
<country-name>United States of America</country-name>
|
70
|
+
<first-name>Braintree</first-name>
|
71
|
+
<last-name>Rails</last-name>
|
72
|
+
<locality>San Francisco</locality>
|
73
|
+
<postal-code>0123456789</postal-code>
|
74
|
+
<region>California</region>
|
75
|
+
<street-address>185 Berry St</street-address>
|
76
|
+
</shipping>
|
77
|
+
<type>sale</type>
|
37
78
|
<credit-card>
|
38
79
|
<expiration-month>01</expiration-month>
|
39
|
-
<cardholder-name>Wall-E</cardholder-name>
|
40
80
|
<expiration-year>1976</expiration-year>
|
41
81
|
</credit-card>
|
42
82
|
</transaction>
|
43
83
|
</params>
|
44
|
-
|
84
|
+
<message>Merchant account does not support payment instrument.
|
85
|
+
Credit card type is not accepted by this merchant account.
|
86
|
+
Credit card number is required.
|
87
|
+
Credit card must include number, payment_method_nonce, or venmo_sdk_payment_method_code.
|
88
|
+
Postal code may contain no more than 9 letter or number characters.</message>
|
89
|
+
</api-error-response>
|