braintree-rails 1.2.3 → 1.3.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.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.travis.yml +13 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile +3 -4
- data/Gemfile.lock +33 -14
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/braintree-rails.gemspec +4 -5
- data/lib/braintree_rails/address.rb +1 -1
- data/lib/braintree_rails/address_details.rb +14 -0
- data/lib/braintree_rails/address_details_validator.rb +7 -0
- data/lib/braintree_rails/association.rb +2 -2
- data/lib/braintree_rails/braintree_ext.rb +27 -1
- data/lib/braintree_rails/business_details.rb +29 -0
- data/lib/braintree_rails/business_details_validator.rb +12 -0
- data/lib/braintree_rails/configuration.rb +1 -1
- data/lib/braintree_rails/credit_card.rb +6 -6
- data/lib/braintree_rails/credit_card_validator.rb +2 -17
- data/lib/braintree_rails/customer.rb +6 -6
- data/lib/braintree_rails/customer_validator.rb +1 -12
- data/lib/braintree_rails/funding_details.rb +17 -0
- data/lib/braintree_rails/funding_details_validator.rb +10 -0
- data/lib/braintree_rails/individual_details.rb +32 -0
- data/lib/braintree_rails/individual_details_validator.rb +11 -0
- data/lib/braintree_rails/merchant_account.rb +45 -0
- data/lib/braintree_rails/merchant_account_validator.rb +14 -0
- data/lib/braintree_rails/plan.rb +3 -3
- data/lib/braintree_rails/subscription.rb +5 -5
- data/lib/braintree_rails/transaction.rb +9 -9
- data/lib/braintree_rails/transaction_validator.rb +1 -5
- data/lib/braintree_rails/validator.rb +13 -0
- data/lib/braintree_rails/version.rb +1 -1
- data/lib/tasks/ci.rake +7 -0
- data/lib/tasks/spec.rake +18 -0
- data/lib/test_env.rb +1 -7
- data/{test → spec}/config/braintree_auth.yml.example +0 -0
- data/{test → spec}/fixtures/add_ons.xml +0 -0
- data/{test → spec}/fixtures/address.xml +0 -0
- data/{test → spec}/fixtures/credit_card.xml +0 -0
- data/{test → spec}/fixtures/credit_card_validation_error.xml +0 -0
- data/{test → spec}/fixtures/customer.xml +0 -0
- data/{test → spec}/fixtures/discounts.xml +0 -0
- data/spec/fixtures/merchant_account.xml +7 -0
- data/{test → spec}/fixtures/plans.xml +0 -0
- data/{test → spec}/fixtures/subscription.xml +0 -0
- data/{test → spec}/fixtures/subscription_ids.xml +0 -0
- data/{test → spec}/fixtures/subscriptions.xml +0 -0
- data/{test → spec}/fixtures/transaction.xml +0 -0
- data/{test → spec}/fixtures/transaction_error.xml +0 -0
- data/{test → spec}/fixtures/transaction_ids.xml +0 -0
- data/{test → spec}/fixtures/transactions.xml +0 -0
- data/{test/integration/braintree_rails/address_integration_test.rb → spec/integration/braintree_rails/address_integration_spec.rb} +8 -8
- data/{test/integration/braintree_rails/credit_card_integration_test.rb → spec/integration/braintree_rails/credit_card_integration_spec.rb} +20 -20
- data/{test/integration/braintree_rails/customer_integration_test.rb → spec/integration/braintree_rails/customer_integration_spec.rb} +20 -20
- data/spec/integration/braintree_rails/merchant_account_integration_spec.rb +37 -0
- data/{test/integration/braintree_rails/transaction_integration_test.rb → spec/integration/braintree_rails/transaction_integration_spec.rb} +27 -27
- data/spec/integration/integration_spec_helper.rb +23 -0
- data/spec/spec_helper.rb +17 -0
- data/{test/test_helper.rb → spec/support/helper.rb} +42 -21
- data/spec/support/string_ext.rb +5 -0
- data/{test/unit/braintree_rails/add_on_test.rb → spec/unit/braintree_rails/add_on_spec.rb} +10 -10
- data/{test/unit/braintree_rails/add_ons_test.rb → spec/unit/braintree_rails/add_ons_spec.rb} +4 -4
- data/spec/unit/braintree_rails/address_details_spec.rb +13 -0
- data/{test/unit/braintree_rails/address_test.rb → spec/unit/braintree_rails/address_spec.rb} +26 -26
- data/{test/unit/braintree_rails/addresses_test.rb → spec/unit/braintree_rails/addresses_spec.rb} +7 -7
- data/spec/unit/braintree_rails/business_details_spec.rb +28 -0
- data/{test/unit/braintree_rails/configuration_test.rb → spec/unit/braintree_rails/configuration_spec.rb} +6 -6
- data/{test/unit/braintree_rails/credit_card_test.rb → spec/unit/braintree_rails/credit_card_spec.rb} +78 -72
- data/{test/unit/braintree_rails/credit_cards_test.rb → spec/unit/braintree_rails/credit_cards_spec.rb} +15 -10
- data/{test/unit/braintree_rails/customer_test.rb → spec/unit/braintree_rails/customer_spec.rb} +46 -46
- data/{test/unit/braintree_rails/discount_test.rb → spec/unit/braintree_rails/discount_spec.rb} +10 -10
- data/{test/unit/braintree_rails/discounts_test.rb → spec/unit/braintree_rails/discounts_spec.rb} +4 -4
- data/spec/unit/braintree_rails/funding_details_spec.rb +36 -0
- data/spec/unit/braintree_rails/individual_details_spec.rb +19 -0
- data/{test/unit/braintree_rails/luhn_10_validator_test.rb → spec/unit/braintree_rails/luhn_10_validator_spec.rb} +5 -5
- data/spec/unit/braintree_rails/merchant_account_spec.rb +50 -0
- data/{test/unit/braintree_rails/plan_test.rb → spec/unit/braintree_rails/plan_spec.rb} +12 -12
- data/{test/unit/braintree_rails/subscription_test.rb → spec/unit/braintree_rails/subscription_spec.rb} +55 -55
- data/{test/unit/braintree_rails/subscriptions_test.rb → spec/unit/braintree_rails/subscriptions_spec.rb} +4 -4
- data/{test/unit/braintree_rails/transaction_test.rb → spec/unit/braintree_rails/transaction_spec.rb} +55 -55
- data/{test/unit/braintree_rails/transactions_test.rb → spec/unit/braintree_rails/transactions_spec.rb} +9 -9
- data/{test/unit/braintree_rails/validation_error_test.rb → spec/unit/braintree_rails/validation_error_spec.rb} +4 -4
- data/{test/unit/braintree_rails/validator_test.rb → spec/unit/braintree_rails/validator_spec.rb} +7 -7
- data/spec/unit/unit_spec_helper.rb +4 -0
- metadata +69 -63
- data/lib/tasks/test.rake +0 -18
- data/test/integration/integration_test_helper.rb +0 -13
- data/test/unit/unit_test_helper.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dabcaf3edf7c518f2ded8a0382de5ac2ef468ab
|
4
|
+
data.tar.gz: 3e02fa5749ed2dbcfa863328cc2266312372a844
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 431039d31483f5e450b067e32349b6987a843a4fd481000e8a8bebde02491af3baa54cf8b7b4e08b89eb20644c01a30d22924c14a781de20ed0ffd8be1d0a50f
|
7
|
+
data.tar.gz: 2a113fb29727e0108217f22a72e7392b19f98d47d6d3a20c545a4dd5c44992df5000b6290eba874975e508fd5e078b100072edd74905b5c29f8fc6e01e08e7f8
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
script: bundle exec rake ci:travis
|
2
4
|
rvm:
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
- 1.9.2
|
6
|
+
- 1.9.3
|
7
|
+
- 2.0.0
|
8
|
+
- 2.1.0
|
9
|
+
- jruby-19mode
|
10
|
+
env:
|
11
|
+
global:
|
12
|
+
- secure: KV6QO8+zlfSlnZW9LhmDAeTUqnbdGu7axYyI0qAFjfHdROKTV/BaF8ZvOcX3CsveBjmEMLroIUu8G/pBUWJCQ/XC+TrEafhLQUHF8bo1xZdOJmMkjBiKsl3tu9ys2St3Oc2WIbo7YL7SeOuMlDG6xemIxs0H9kZjFxfqPBqS8Ew=
|
13
|
+
- secure: NVDIEcg9Yj87cbv9YZ294mPZx6ousZerha78jUJtVAMXnbhb/Lg8BrZFK5y8aiExc/LMKfdw28FdhcSkq002OxaUdA8Zcwr7ZjsGsKHasu2Dr2FzdzZgLXOedingZ1FyuzhqW40Q/aM0GgO0WGn+z2P9KLXRx7fxHg/R0QhIB+g=
|
14
|
+
- secure: r7NPGCo5yN6uXz6Zosov/x4iHpMMTq2mRTKhtfczEsu39L0S4+egsvbPf1bjobFWOgNu9fzCublphl/pXFf3Hv1JQfizS0escCMq9z0PUBJ2x1JzEZGqz5os2NqSCdoTRR3P7hzFNKCTF+JZJklvGxyKwev8kP3gcAtxb4GQypg=
|
15
|
+
- secure: mXj8rHJcSlLDseru8FsbcCVNHUTpdxG9PNxLqIvfn4SQnROrMYtd4IFuEGQn/wuzatsgFisB6uGpEqs6m0wUCPrMfShyN8ZnNPbF0qTvnq0uQemAIaoK2BSjPExWod6uNTe0sEg1Z+dX+SNfkkOruHXJ9t/ERsK52er1qodYJiE=
|
data/CHANGELOG.md
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
## Unreleased (master)
|
2
|
+
### Enhancements
|
3
|
+
* Added Braintree Marketplace related models
|
4
|
+
|
5
|
+
## v1.2.3 (a9f5bf4), Jan 21 2014
|
2
6
|
### Enhancements
|
3
7
|
* Customer create/update now accepts an optional :credit_card params.
|
4
8
|
|
5
9
|
### Bug Fixes
|
6
10
|
* Fixed a bug where it failed to update credit card expiry date when only expiration year changed. (Thanks, @vedanova)
|
7
11
|
|
8
|
-
## v1.2.2 (
|
12
|
+
## v1.2.2 (dc21ba6), Oct 14 2013
|
9
13
|
### Bug Fixes
|
10
14
|
* Fixed gemspec to only package necessary files to reduce the gem file size. (Thanks, @ivankocienski)
|
11
15
|
|
data/Gemfile
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
source 'http://rubygems.org'
|
2
|
-
gem 'braintree', '>= 2.
|
2
|
+
gem 'braintree', '>= 2.28.0'
|
3
3
|
gem 'activemodel', '>= 3.0'
|
4
4
|
gem 'activesupport', '>= 3.0'
|
5
5
|
|
6
6
|
group :test do
|
7
7
|
gem 'rake'
|
8
|
-
gem '
|
8
|
+
gem 'rspec'
|
9
9
|
gem 'webmock'
|
10
|
-
gem '
|
11
|
-
gem 'simplecov'
|
10
|
+
gem 'coveralls', require: false
|
12
11
|
end
|
data/Gemfile.lock
CHANGED
@@ -8,21 +8,41 @@ GEM
|
|
8
8
|
i18n (= 0.6.1)
|
9
9
|
multi_json (~> 1.0)
|
10
10
|
addressable (2.3.4)
|
11
|
-
|
12
|
-
braintree (2.22.0)
|
11
|
+
braintree (2.28.0)
|
13
12
|
builder (>= 2.0.0)
|
14
13
|
builder (3.0.4)
|
14
|
+
coveralls (0.7.0)
|
15
|
+
multi_json (~> 1.3)
|
16
|
+
rest-client
|
17
|
+
simplecov (>= 0.7)
|
18
|
+
term-ansicolor
|
19
|
+
thor
|
15
20
|
crack (0.3.2)
|
21
|
+
diff-lcs (1.2.5)
|
22
|
+
docile (1.1.3)
|
16
23
|
i18n (0.6.1)
|
17
|
-
|
18
|
-
multi_json (1.
|
24
|
+
mime-types (2.1)
|
25
|
+
multi_json (1.9.0)
|
19
26
|
rake (10.0.4)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
rest-client (1.6.7)
|
28
|
+
mime-types (>= 1.16)
|
29
|
+
rspec (2.14.1)
|
30
|
+
rspec-core (~> 2.14.0)
|
31
|
+
rspec-expectations (~> 2.14.0)
|
32
|
+
rspec-mocks (~> 2.14.0)
|
33
|
+
rspec-core (2.14.8)
|
34
|
+
rspec-expectations (2.14.5)
|
35
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
36
|
+
rspec-mocks (2.14.6)
|
37
|
+
simplecov (0.8.2)
|
38
|
+
docile (~> 1.1.0)
|
39
|
+
multi_json
|
40
|
+
simplecov-html (~> 0.8.0)
|
41
|
+
simplecov-html (0.8.0)
|
42
|
+
term-ansicolor (1.3.0)
|
43
|
+
tins (~> 1.0)
|
44
|
+
thor (0.18.1)
|
45
|
+
tins (1.0.0)
|
26
46
|
webmock (1.11.0)
|
27
47
|
addressable (>= 2.2.7)
|
28
48
|
crack (>= 0.3.2)
|
@@ -33,9 +53,8 @@ PLATFORMS
|
|
33
53
|
DEPENDENCIES
|
34
54
|
activemodel (>= 3.0)
|
35
55
|
activesupport (>= 3.0)
|
36
|
-
braintree (>= 2.
|
37
|
-
|
56
|
+
braintree (>= 2.28.0)
|
57
|
+
coveralls
|
38
58
|
rake
|
39
|
-
|
40
|
-
turn
|
59
|
+
rspec
|
41
60
|
webmock
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#
|
1
|
+
# [](http://travis-ci.org/lyang/braintree-rails) [](https://coveralls.io/r/lyang/braintree-rails?branch=master) [](https://codeclimate.com/github/lyang/braintree-rails) [](http://badge.fury.io/rb/braintree-rails)
|
2
2
|
braintree-rails is a framework that wraps the official [braintree_ruby](https://github.com/braintree/braintree_ruby) client library and provides ActiveModel compatible models that can be easily fit into an rails app.
|
3
3
|
|
4
4
|
BraintreeRails models have the same CRUD interface, can be used in Rails form helpers and url helpers. In addition, it has built in validations and callbacks. Even more, you can customize those quite easily.
|
data/Rakefile
CHANGED
data/braintree-rails.gemspec
CHANGED
@@ -9,15 +9,14 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = 'github@linyang.me'
|
10
10
|
spec.license = 'MIT'
|
11
11
|
spec.files = `git ls-files`.split($/)
|
12
|
-
spec.test_files = Dir['
|
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.
|
15
|
+
spec.add_runtime_dependency 'braintree', '>= 2.28.0'
|
16
16
|
spec.add_runtime_dependency 'activemodel', '>= 3.0'
|
17
17
|
spec.add_runtime_dependency 'activesupport', '>= 3.0'
|
18
18
|
spec.add_development_dependency 'rake'
|
19
|
-
spec.add_development_dependency '
|
19
|
+
spec.add_development_dependency 'rspec'
|
20
20
|
spec.add_development_dependency 'webmock'
|
21
|
-
spec.add_development_dependency '
|
22
|
-
spec.add_development_dependency 'simplecov'
|
21
|
+
spec.add_development_dependency 'coveralls'
|
23
22
|
end
|
@@ -8,7 +8,7 @@ module BraintreeRails
|
|
8
8
|
:as_association => [:company, :country_name, :extended_address, :first_name, :last_name, :locality, :postal_code, :region, :street_address]
|
9
9
|
)
|
10
10
|
|
11
|
-
belongs_to :customer, :
|
11
|
+
belongs_to :customer, :class_name => "BraintreeRails::Customer", :foreign_key => :customer_id
|
12
12
|
|
13
13
|
CountryNames = {
|
14
14
|
:country_name => 0,
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class AddressDetails
|
3
|
+
include Model
|
4
|
+
|
5
|
+
singleton_class.not_supported_apis(:delete)
|
6
|
+
not_supported_apis(:create, :create!, :update, :update!, :destroy)
|
7
|
+
|
8
|
+
define_attributes(:as_association => [:street_address, :locality, :region, :postal_code])
|
9
|
+
|
10
|
+
def self.braintree_model_name
|
11
|
+
"merchant_account/#{name.demodulize.underscore}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -30,14 +30,14 @@ module BraintreeRails
|
|
30
30
|
if value = instance_variable_get("@#{name}")
|
31
31
|
return value
|
32
32
|
elsif options[:foreign_key] && value = send(options[:foreign_key])
|
33
|
-
instance_variable_set("@#{name}", options[:
|
33
|
+
instance_variable_set("@#{name}", options[:class_name].constantize.new(value))
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def define_association_writer(name, options)
|
39
39
|
define_method("#{name}=") do |value|
|
40
|
-
value &&= options[:
|
40
|
+
value &&= options[:class_name].constantize.new(value)
|
41
41
|
instance_variable_set("@#{name}", value)
|
42
42
|
end
|
43
43
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
[Braintree::Plan, Braintree::Modification].each do |model|
|
2
2
|
model.class_eval do
|
3
3
|
def self.find(id)
|
4
|
-
all.find {|
|
4
|
+
all.find {|model| model.id == id}
|
5
5
|
end
|
6
6
|
end
|
7
7
|
end
|
@@ -64,3 +64,29 @@ module Braintree
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
67
|
+
|
68
|
+
module Braintree
|
69
|
+
class MerchantAccount
|
70
|
+
alias_method :individual, :individual_details
|
71
|
+
alias_method :business, :business_details
|
72
|
+
alias_method :funding, :funding_details
|
73
|
+
|
74
|
+
class IndividualDetails
|
75
|
+
attr_reader :id
|
76
|
+
alias_method :address, :address_details
|
77
|
+
end
|
78
|
+
|
79
|
+
class BusinessDetails
|
80
|
+
attr_reader :id
|
81
|
+
alias_method :address, :address_details
|
82
|
+
end
|
83
|
+
|
84
|
+
class FundingDetails
|
85
|
+
attr_reader :id
|
86
|
+
end
|
87
|
+
|
88
|
+
class AddressDetails
|
89
|
+
attr_reader :id
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class BusinessDetails
|
3
|
+
include Model
|
4
|
+
|
5
|
+
singleton_class.not_supported_apis(:delete)
|
6
|
+
not_supported_apis(:create, :create!, :update, :update!, :destroy)
|
7
|
+
|
8
|
+
define_attributes(:as_association => [:dba_name, :legal_name, :tax_id, :address])
|
9
|
+
|
10
|
+
has_one :address, :class_name => "BraintreeRails::AddressDetails"
|
11
|
+
|
12
|
+
def self.braintree_model_name
|
13
|
+
"merchant_account/#{name.demodulize.underscore}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_errors(validation_errors)
|
17
|
+
address.add_errors(validation_errors) if address
|
18
|
+
super(validation_errors)
|
19
|
+
end
|
20
|
+
|
21
|
+
def attributes_for(action)
|
22
|
+
super.merge(address_attributes)
|
23
|
+
end
|
24
|
+
|
25
|
+
def address_attributes
|
26
|
+
address.present? ? {:address => address.attributes_for(:as_association)} : {}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class BusinessDetailsValidator < Validator
|
3
|
+
Validations = [
|
4
|
+
[:legal_name, :presence => true, :if => Proc.new {|business| business.tax_id.present?}],
|
5
|
+
[:tax_id, :presence => true, :if => Proc.new {|business| business.legal_name.present?}],
|
6
|
+
]
|
7
|
+
|
8
|
+
def validate(business)
|
9
|
+
validate_association(business, :address)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -10,7 +10,7 @@ module BraintreeRails
|
|
10
10
|
singleton_class.class_eval do
|
11
11
|
delegate :custom_user_agent, :environment, :merchant_id, :public_key, :private_key, :logger, :to => Braintree::Configuration
|
12
12
|
delegate :custom_user_agent=, :environment=, :merchant_id=, :public_key=, :private_key=, :logger=, :to => Braintree::Configuration
|
13
|
-
attr_accessor :mode, :require_postal_code, :require_street_address, :client_side_encryption_key
|
13
|
+
attr_accessor :mode, :require_postal_code, :require_street_address, :client_side_encryption_key, :default_merchant_account_id
|
14
14
|
end
|
15
15
|
|
16
16
|
self.custom_user_agent = "braintree-rails-#{Version}"
|
@@ -2,8 +2,8 @@ module BraintreeRails
|
|
2
2
|
class CreditCard
|
3
3
|
include Model
|
4
4
|
define_attributes(
|
5
|
-
:create => [:billing_address, :cardholder_name, :customer_id, :expiration_date, :expiration_month, :expiration_year, :number, :cvv, :options, :token],
|
6
|
-
:update => [:billing_address, :cardholder_name, :expiration_date, :expiration_month, :expiration_year, :options, :number, :cvv],
|
5
|
+
:create => [:billing_address, :cardholder_name, :customer_id, :expiration_date, :expiration_month, :expiration_year, :number, :cvv, :options, :token, :device_data],
|
6
|
+
:update => [:billing_address, :cardholder_name, :expiration_date, :expiration_month, :expiration_year, :options, :number, :cvv, :device_data],
|
7
7
|
:readonly => [
|
8
8
|
:bin, :card_type, :commercial, :country_of_issuance, :created_at, :debit, :durbin_regulated, :default,
|
9
9
|
:expired, :healthcare, :issuing_bank, :last_4, :payroll, :prepaid, :unique_number_identifier, :updated_at
|
@@ -11,10 +11,10 @@ module BraintreeRails
|
|
11
11
|
:as_association => [:cardholder_name, :cvv, :expiration_date, :expiration_month, :expiration_year, :number]
|
12
12
|
)
|
13
13
|
|
14
|
-
has_many :transactions, :
|
15
|
-
has_many :subscriptions, :
|
16
|
-
belongs_to :customer, :
|
17
|
-
has_one :billing_address, :
|
14
|
+
has_many :transactions, :class_name => "BraintreeRails::Transactions"
|
15
|
+
has_many :subscriptions, :class_name => "BraintreeRails::Subscriptions"
|
16
|
+
belongs_to :customer, :class_name => "BraintreeRails::Customer", :foreign_key => :customer_id
|
17
|
+
has_one :billing_address, :class_name => "BraintreeRails::BillingAddress"
|
18
18
|
|
19
19
|
alias_method :id, :token
|
20
20
|
alias_method :id=, :token=
|
@@ -12,26 +12,11 @@ module BraintreeRails
|
|
12
12
|
[:expiration_date, :presence => true, :if => Proc.new { |credit_card| credit_card.new_record? && credit_card.expiration_month.blank? }],
|
13
13
|
[:expiration_month, :numericality => { :only_integer => true, :greater_than_or_equal_to => 1, :less_than_or_equal_to => 12 }, :if => Proc.new { Configuration.mode == Configuration::Mode::S2S }],
|
14
14
|
[:expiration_year, :numericality => { :only_integer => true, :greater_than_or_equal_to => 1976, :less_than_or_equal_to => 2200 }, :if => Proc.new { Configuration.mode == Configuration::Mode::S2S }],
|
15
|
+
[:billing_address, :presence => true, :if => Proc.new {Configuration.require_postal_code || Configuration.require_street_address}],
|
15
16
|
]
|
16
17
|
|
17
18
|
def validate(credit_card)
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
def has_valid_billing_address(credit_card)
|
22
|
-
credit_card.instance_eval do
|
23
|
-
errors.add(:billing_address, "is empty") and return if billing_address.blank?
|
24
|
-
if billing_address.invalid?
|
25
|
-
errors.add(:billing_address, "is invalid")
|
26
|
-
billing_address.errors.full_messages.each do |message|
|
27
|
-
errors.add(:base, message)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
def validate_billing_address?
|
34
|
-
Configuration.require_postal_code || Configuration.require_street_address
|
19
|
+
validate_association(credit_card, :billing_address)
|
35
20
|
end
|
36
21
|
end
|
37
22
|
end
|
@@ -3,16 +3,16 @@ module BraintreeRails
|
|
3
3
|
include Model
|
4
4
|
|
5
5
|
define_attributes(
|
6
|
-
:create => [:company, :custom_fields, :email, :fax, :first_name, :id, :last_name, :options, :phone, :website, :credit_card],
|
7
|
-
:update => [:company, :custom_fields, :email, :fax, :first_name, :last_name, :options, :phone, :website, :credit_card],
|
6
|
+
:create => [:company, :custom_fields, :email, :fax, :first_name, :id, :last_name, :options, :phone, :website, :credit_card, :device_data],
|
7
|
+
:update => [:company, :custom_fields, :email, :fax, :first_name, :last_name, :options, :phone, :website, :credit_card, :device_data],
|
8
8
|
:readonly => [:created_at, :updated_at],
|
9
9
|
:as_association => [:id, :company, :email, :fax, :first_name, :last_name, :phone, :website]
|
10
10
|
)
|
11
11
|
|
12
|
-
has_many :addresses, :
|
13
|
-
has_many :transactions, :
|
14
|
-
has_many :credit_cards, :
|
15
|
-
has_one :credit_card, :
|
12
|
+
has_many :addresses, :class_name => "BraintreeRails::Addresses"
|
13
|
+
has_many :transactions, :class_name => "BraintreeRails::Transactions"
|
14
|
+
has_many :credit_cards, :class_name => "BraintreeRails::CreditCards"
|
15
|
+
has_one :credit_card, :class_name => "BraintreeRails::CreditCard"
|
16
16
|
|
17
17
|
def ensure_model(model)
|
18
18
|
if Braintree::Transaction::CustomerDetails === model
|
@@ -6,18 +6,7 @@ module BraintreeRails
|
|
6
6
|
]
|
7
7
|
|
8
8
|
def validate(customer)
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def validate_credit_card(customer)
|
13
|
-
customer.instance_eval do
|
14
|
-
if credit_card.invalid?
|
15
|
-
errors.add(:credit_card, "is invalid")
|
16
|
-
credit_card.errors.full_messages.each do |message|
|
17
|
-
errors.add(:base, message)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
9
|
+
validate_association(customer, :credit_card)
|
21
10
|
end
|
22
11
|
end
|
23
12
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class FundingDetails
|
3
|
+
include Model
|
4
|
+
|
5
|
+
singleton_class.not_supported_apis(:delete)
|
6
|
+
not_supported_apis(:create, :create!, :update, :update!, :destroy)
|
7
|
+
|
8
|
+
define_attributes(
|
9
|
+
:readonly => [:account_number_last_4],
|
10
|
+
:as_association => [:destination, :email, :mobile_phone, :account_number, :routing_number]
|
11
|
+
)
|
12
|
+
|
13
|
+
def self.braintree_model_name
|
14
|
+
"merchant_account/#{name.demodulize.underscore}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class FundingDetailsValidator < Validator
|
3
|
+
Validations = [
|
4
|
+
[:destination, :presence => true, :inclusion => {:in => [Braintree::MerchantAccount::FundingDestination::Bank, Braintree::MerchantAccount::FundingDestination::Email, Braintree::MerchantAccount::FundingDestination::MobilePhone]}],
|
5
|
+
[:email, :presence => true, :if => Proc.new {|business| business.destination == Braintree::MerchantAccount::FundingDestination::Email}],
|
6
|
+
[:mobile_phone, :presence => true, :if => Proc.new {|business| business.destination == Braintree::MerchantAccount::FundingDestination::MobilePhone}],
|
7
|
+
[:account_number, :routing_number, :presence => true, :if => Proc.new {|business| business.destination == Braintree::MerchantAccount::FundingDestination::Bank}],
|
8
|
+
]
|
9
|
+
end
|
10
|
+
end
|