braintree-rails 1.2.3 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,32 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class IndividualDetails
|
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 => [:ssn_last_4],
|
10
|
+
:as_association => [:first_name, :last_name, :email, :phone, :date_of_birth, :ssn, :address]
|
11
|
+
)
|
12
|
+
|
13
|
+
has_one :address, :class_name => "BraintreeRails::AddressDetails"
|
14
|
+
|
15
|
+
def self.braintree_model_name
|
16
|
+
"merchant_account/#{name.demodulize.underscore}"
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_errors(validation_errors)
|
20
|
+
address.add_errors(validation_errors) if address
|
21
|
+
super(validation_errors)
|
22
|
+
end
|
23
|
+
|
24
|
+
def attributes_for(action)
|
25
|
+
super.merge(address_attributes)
|
26
|
+
end
|
27
|
+
|
28
|
+
def address_attributes
|
29
|
+
address.present? ? {:address => address.attributes_for(:as_association)} : {}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class IndividualDetailsValidator < Validator
|
3
|
+
Validations = [
|
4
|
+
[:first_name, :last_name, :email, :date_of_birth, :address, :presence => true]
|
5
|
+
]
|
6
|
+
|
7
|
+
def validate(individual)
|
8
|
+
validate_association(individual, :address)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class MerchantAccount
|
3
|
+
include Model
|
4
|
+
|
5
|
+
# Need to remove the ! methods as those are not provided by the API
|
6
|
+
singleton_class.not_supported_apis(:delete, :create!, :update!)
|
7
|
+
not_supported_apis(:destroy, :create!, :update!)
|
8
|
+
|
9
|
+
define_attributes(
|
10
|
+
:create => [:tos_accepted, :master_merchant_account_id, :id, :individual, :business, :funding],
|
11
|
+
:readonly => [:status, :created_at, :updated_at]
|
12
|
+
)
|
13
|
+
|
14
|
+
belongs_to :master_merchant_account, :class_name => "BraintreeRails::MerchantAccount"
|
15
|
+
has_one :individual, :class_name => "BraintreeRails::IndividualDetails"
|
16
|
+
has_one :business, :class_name => "BraintreeRails::BusinessDetails"
|
17
|
+
has_one :funding, :class_name => "BraintreeRails::FundingDetails"
|
18
|
+
|
19
|
+
# Need to reload to populate association values as there's an inconsistency in the API
|
20
|
+
after_create :reload, :if => :persisted?
|
21
|
+
|
22
|
+
def add_errors(validation_errors)
|
23
|
+
[individual, business, funding].each do |association|
|
24
|
+
association.add_errors(validation_errors.except(:base)) if association
|
25
|
+
super(validation_errors)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def attributes_for(action)
|
30
|
+
super.merge(individual_attributes).merge(business_attributes).merge(funding_attributes)
|
31
|
+
end
|
32
|
+
|
33
|
+
def individual_attributes
|
34
|
+
individual.present? ? {:individual => individual.attributes_for(:as_association)} : {}
|
35
|
+
end
|
36
|
+
|
37
|
+
def business_attributes
|
38
|
+
business.present? ? {:business => business.attributes_for(:as_association)} : {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def funding_attributes
|
42
|
+
funding.present? ? {:funding => funding.attributes_for(:as_association)} : {}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module BraintreeRails
|
2
|
+
class MerchantAccountValidator < Validator
|
3
|
+
Validations = [
|
4
|
+
[:id, :format => {:with => /\A[-_a-z0-9]*\z/i}, :length => {:maximum => 32}, :exclusion => {:in => %w(all new)}],
|
5
|
+
[:tos_accepted, :master_merchant_account_id, :individual, :funding, :presence => true],
|
6
|
+
]
|
7
|
+
|
8
|
+
def validate(merchant_account)
|
9
|
+
[:individual, :business, :funding].each do |association_name|
|
10
|
+
validate_association(merchant_account, association_name)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/braintree_rails/plan.rb
CHANGED
@@ -11,9 +11,9 @@ module BraintreeRails
|
|
11
11
|
:number_of_billing_cycles, :price, :trial_duration, :trial_duration_unit, :trial_period, :updated_at
|
12
12
|
]
|
13
13
|
)
|
14
|
-
has_many :add_ons, :
|
15
|
-
has_many :discounts, :
|
16
|
-
has_many :subscriptions, :
|
14
|
+
has_many :add_ons, :class_name => "BraintreeRails::AddOns"
|
15
|
+
has_many :discounts, :class_name => "BraintreeRails::Discounts"
|
16
|
+
has_many :subscriptions, :class_name => "BraintreeRails::Subscriptions"
|
17
17
|
|
18
18
|
def self.all
|
19
19
|
braintree_model_class.all.map{ |plan| new(plan) }
|
@@ -17,11 +17,11 @@ module BraintreeRails
|
|
17
17
|
]
|
18
18
|
)
|
19
19
|
|
20
|
-
has_many :add_ons, :
|
21
|
-
has_many :discounts, :
|
22
|
-
has_many :transactions, :
|
23
|
-
belongs_to :plan, :
|
24
|
-
belongs_to :credit_card, :
|
20
|
+
has_many :add_ons, :class_name => "BraintreeRails::AddOns"
|
21
|
+
has_many :discounts, :class_name => "BraintreeRails::Discounts"
|
22
|
+
has_many :transactions, :class_name => "BraintreeRails::Transactions"
|
23
|
+
belongs_to :plan, :class_name => "BraintreeRails::Plan", :foreign_key => :plan_id
|
24
|
+
belongs_to :credit_card, :class_name => "BraintreeRails::CreditCard", :foreign_key => :payment_method_token
|
25
25
|
|
26
26
|
def self.cancel(id)
|
27
27
|
delete(id)
|
@@ -8,7 +8,7 @@ module BraintreeRails
|
|
8
8
|
:create => [
|
9
9
|
:amount, :billing, :channel, :custom_fields, :customer_id, :descriptor, :merchant_account_id,
|
10
10
|
:options, :order_id, :payment_method_token, :purchase_order_number, :recurring, :shipping,
|
11
|
-
:tax_amount, :tax_exempt, :type, :venmo_sdk_payment_method_code
|
11
|
+
:tax_amount, :tax_exempt, :type, :venmo_sdk_payment_method_code, :device_data
|
12
12
|
],
|
13
13
|
:readonly => [
|
14
14
|
:avs_error_response_code, :avs_postal_code_response_code, :avs_street_address_response_code, :billing_details,
|
@@ -18,14 +18,14 @@ module BraintreeRails
|
|
18
18
|
]
|
19
19
|
)
|
20
20
|
|
21
|
-
has_many :add_ons, :
|
22
|
-
has_many :discounts, :
|
23
|
-
has_one :billing, :
|
24
|
-
has_one :shipping, :
|
25
|
-
belongs_to :customer, :
|
26
|
-
belongs_to :credit_card, :
|
27
|
-
belongs_to :subscription, :
|
28
|
-
belongs_to :plan, :
|
21
|
+
has_many :add_ons, :class_name => "BraintreeRails::AddOns"
|
22
|
+
has_many :discounts, :class_name => "BraintreeRails::Discounts"
|
23
|
+
has_one :billing, :class_name => "BraintreeRails::BillingAddress", :foreign_key => :billing_details
|
24
|
+
has_one :shipping, :class_name => "BraintreeRails::ShippingAddress", :foreign_key => :shipping_details
|
25
|
+
belongs_to :customer, :class_name => "BraintreeRails::Customer", :foreign_key => :customer_details
|
26
|
+
belongs_to :credit_card, :class_name => "BraintreeRails::CreditCard", :foreign_key => :credit_card_details
|
27
|
+
belongs_to :subscription, :class_name => "BraintreeRails::Subscription", :foreign_key => :subscription_id
|
28
|
+
belongs_to :plan, :class_name => "BraintreeRails::Plan", :foreign_key => :plan_id
|
29
29
|
|
30
30
|
around_persist :clear_encryped_attributes
|
31
31
|
|
@@ -37,11 +37,7 @@ module BraintreeRails
|
|
37
37
|
|
38
38
|
def validate_new_credit_card(transaction)
|
39
39
|
transaction.credit_card.billing_address = transaction.billing
|
40
|
-
|
41
|
-
transaction.credit_card.errors.full_messages.each do |message|
|
42
|
-
transaction.errors.add(:base, message)
|
43
|
-
end
|
44
|
-
end
|
40
|
+
validate_association(transaction, :credit_card)
|
45
41
|
end
|
46
42
|
end
|
47
43
|
end
|
@@ -33,5 +33,18 @@ module BraintreeRails
|
|
33
33
|
|
34
34
|
def validate(record)
|
35
35
|
end
|
36
|
+
|
37
|
+
def validate_association(record, name)
|
38
|
+
record.instance_eval do
|
39
|
+
association = record.send(name)
|
40
|
+
return unless association.present?
|
41
|
+
if association.invalid?
|
42
|
+
errors.add(name, "is invalid")
|
43
|
+
association.errors.full_messages.each do |message|
|
44
|
+
errors.add(:base, message)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
36
49
|
end
|
37
50
|
end
|
data/lib/tasks/ci.rake
ADDED
data/lib/tasks/spec.rake
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rspec/core/rake_task'
|
2
|
+
|
3
|
+
namespace :spec do
|
4
|
+
desc "Run unit specs"
|
5
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
6
|
+
t.pattern = 'spec/unit/**/*_spec.rb'
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "Run integration specs"
|
11
|
+
RSpec::Core::RakeTask.new(:integration) do |t|
|
12
|
+
t.pattern = 'spec/integration/**/*_spec.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc "Run all specs"
|
17
|
+
task :all => [:unit, :integration]
|
18
|
+
end
|
data/lib/test_env.rb
CHANGED
@@ -1,10 +1,4 @@
|
|
1
1
|
require 'simplecov'
|
2
|
-
SimpleCov.start
|
3
|
-
add_filter "/test/"
|
4
|
-
end
|
5
|
-
|
2
|
+
SimpleCov.start {add_filter '/spec/'}
|
6
3
|
require File.join(File.dirname(__FILE__), 'env')
|
7
|
-
require 'minitest/autorun'
|
8
4
|
require 'braintree-rails'
|
9
|
-
require 'turn/autorun'
|
10
|
-
require 'active_support/core_ext/date/calculations'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../integration_spec_helper'))
|
2
2
|
|
3
3
|
describe 'Address Integration' do
|
4
4
|
before do
|
@@ -13,7 +13,7 @@ describe 'Address Integration' do
|
|
13
13
|
braintree_address = braintree_customer.addresses.first
|
14
14
|
|
15
15
|
attributes.each do |key, value|
|
16
|
-
braintree_address.send(key).
|
16
|
+
braintree_address.send(key).should == value
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -24,26 +24,26 @@ describe 'Address Integration' do
|
|
24
24
|
|
25
25
|
braintree_customer = Braintree::Customer.find(customer.id)
|
26
26
|
braintree_address = braintree_customer.addresses.first
|
27
|
-
braintree_address.first_name.
|
27
|
+
braintree_address.first_name.should == 'Foo'
|
28
28
|
|
29
29
|
address.last_name = 'Bar'
|
30
30
|
address.save!
|
31
31
|
|
32
32
|
braintree_customer = Braintree::Customer.find(customer.id)
|
33
33
|
braintree_address = braintree_customer.addresses.first
|
34
|
-
braintree_address.last_name.
|
34
|
+
braintree_address.last_name.should == 'Bar'
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should be able to destroy existing address' do
|
38
38
|
customer = BraintreeRails::Customer.create!(customer_hash)
|
39
39
|
address = customer.addresses.create!(address_hash)
|
40
40
|
address.destroy
|
41
|
-
|
42
|
-
address.
|
43
|
-
address.
|
41
|
+
expect { Braintree::Address.find(customer.id, address.id) }.to raise_error(Braintree::NotFoundError)
|
42
|
+
address.should_not be_persisted
|
43
|
+
address.should be_frozen
|
44
44
|
|
45
45
|
address = customer.addresses.create!(address_hash)
|
46
46
|
BraintreeRails::Address.delete(customer.id, address.id)
|
47
|
-
|
47
|
+
expect { Braintree::Address.find(customer.id, address.id) }.to raise_error(Braintree::NotFoundError)
|
48
48
|
end
|
49
49
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../integration_spec_helper'))
|
2
2
|
|
3
3
|
describe 'Credit Card Integration' do
|
4
4
|
before do
|
@@ -12,11 +12,11 @@ describe 'Credit Card Integration' do
|
|
12
12
|
credit_card = BraintreeRails::CreditCard.new(braintree_customer.credit_cards.first.token)
|
13
13
|
|
14
14
|
attributes.except(:number, :cvv, :billing_address).each do |key, value|
|
15
|
-
credit_card.send(key).
|
15
|
+
credit_card.send(key).should == value
|
16
16
|
end
|
17
17
|
|
18
18
|
attributes[:billing_address].each do |key, value|
|
19
|
-
credit_card.billing_address.send(key).
|
19
|
+
credit_card.billing_address.send(key).should == value
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -27,12 +27,12 @@ describe 'Credit Card Integration' do
|
|
27
27
|
|
28
28
|
braintree_credit_card = Braintree::CreditCard.find(credit_card.id)
|
29
29
|
attributes.except(:number, :cvv, :billing_address).each do |key, value|
|
30
|
-
braintree_credit_card.send(key).
|
30
|
+
braintree_credit_card.send(key).should == value
|
31
31
|
end
|
32
32
|
|
33
33
|
braintree_address = braintree_credit_card.billing_address
|
34
34
|
attributes[:billing_address].each do |key, value|
|
35
|
-
braintree_address.send(key).
|
35
|
+
braintree_address.send(key).should == value
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -42,8 +42,8 @@ describe 'Credit Card Integration' do
|
|
42
42
|
|
43
43
|
credit_card.update_attributes!(:cardholder_name => 'Foo Bar', :number => '4111111111111111', :options => {:verify_card => true}, :billing_address => address_hash.merge(:postal_code => '56789'))
|
44
44
|
braintree_credit_card = Braintree::CreditCard.find(credit_card.id)
|
45
|
-
braintree_credit_card.cardholder_name.
|
46
|
-
braintree_credit_card.billing_address.postal_code.
|
45
|
+
braintree_credit_card.cardholder_name.should == 'Foo Bar'
|
46
|
+
braintree_credit_card.billing_address.postal_code.should == '56789'
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'should be able to update just expiration year' do
|
@@ -52,10 +52,10 @@ describe 'Credit Card Integration' do
|
|
52
52
|
|
53
53
|
credit_card.update_attributes!(:cardholder_name => 'Foo Bar', :number => '4111111111111111', :options => {:verify_card => true}, :expiration_month => '07', :expiration_year => '2013', :billing_address => address_hash.merge(:postal_code => '56789'))
|
54
54
|
braintree_credit_card = Braintree::CreditCard.find(credit_card.id)
|
55
|
-
braintree_credit_card.cardholder_name.
|
56
|
-
braintree_credit_card.billing_address.postal_code.
|
57
|
-
braintree_credit_card.expiration_month.
|
58
|
-
braintree_credit_card.expiration_year.
|
55
|
+
braintree_credit_card.cardholder_name.should == 'Foo Bar'
|
56
|
+
braintree_credit_card.billing_address.postal_code.should == '56789'
|
57
|
+
braintree_credit_card.expiration_month.should == '07'
|
58
|
+
braintree_credit_card.expiration_year.should == '2013'
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should be able to update by expiration date' do
|
@@ -64,11 +64,11 @@ describe 'Credit Card Integration' do
|
|
64
64
|
|
65
65
|
credit_card.update_attributes!(:cardholder_name => 'Foo Bar', :number => '4111111111111111', :options => {:verify_card => true}, :expiration_date => '08/2013', :billing_address => address_hash.merge(:postal_code => '56789'))
|
66
66
|
braintree_credit_card = Braintree::CreditCard.find(credit_card.id)
|
67
|
-
braintree_credit_card.cardholder_name.
|
68
|
-
braintree_credit_card.billing_address.postal_code.
|
69
|
-
braintree_credit_card.expiration_month.
|
70
|
-
braintree_credit_card.expiration_year.
|
71
|
-
braintree_credit_card.expiration_date.
|
67
|
+
braintree_credit_card.cardholder_name.should == 'Foo Bar'
|
68
|
+
braintree_credit_card.billing_address.postal_code.should == '56789'
|
69
|
+
braintree_credit_card.expiration_month.should == '08'
|
70
|
+
braintree_credit_card.expiration_year.should == '2013'
|
71
|
+
braintree_credit_card.expiration_date.should == '08/2013'
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'should be able to destroy existing credit card' do
|
@@ -76,13 +76,13 @@ describe 'Credit Card Integration' do
|
|
76
76
|
credit_card = BraintreeRails::CreditCard.new(braintree_customer.credit_cards.first.token)
|
77
77
|
|
78
78
|
credit_card.destroy!
|
79
|
-
|
80
|
-
credit_card.
|
81
|
-
credit_card.
|
79
|
+
expect { Braintree::CreditCard.find(credit_card.token) }.to raise_error(Braintree::NotFoundError)
|
80
|
+
credit_card.should_not be_persisted
|
81
|
+
credit_card.should be_frozen
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'should be able to capture braintree api errors' do
|
85
85
|
customer = BraintreeRails::Customer.create!(:id => 'customer_id', :first_name => 'Brain', :last_name => 'Tree')
|
86
|
-
|
86
|
+
expect {customer.credit_cards.create!(credit_card_hash.merge(:number => 'foo'))}.to raise_error(Braintree::ValidationsFailed)
|
87
87
|
end
|
88
88
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.expand_path(File.join(File.dirname(__FILE__), '../
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../integration_spec_helper'))
|
2
2
|
|
3
3
|
describe 'Customer Integration' do
|
4
4
|
before do
|
@@ -8,24 +8,24 @@ describe 'Customer Integration' do
|
|
8
8
|
it 'should fetch customer from Braintree for given id' do
|
9
9
|
braintree_customer = Braintree::Customer.create!(:first_name => 'Brain', :last_name => 'Tree')
|
10
10
|
customer = BraintreeRails::Customer.new(braintree_customer.id)
|
11
|
-
customer.id.
|
12
|
-
customer.first_name.
|
13
|
-
customer.last_name.
|
14
|
-
customer.
|
11
|
+
customer.id.should == braintree_customer.id
|
12
|
+
customer.first_name.should == 'Brain'
|
13
|
+
customer.last_name.should == 'Tree'
|
14
|
+
customer.should be_persisted
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should be able to create new customer' do
|
18
18
|
customer = BraintreeRails::Customer.create(:first_name => 'Brain', :last_name => 'Tree')
|
19
19
|
braintree_customer = Braintree::Customer.find(customer.id)
|
20
20
|
|
21
|
-
braintree_customer.first_name.
|
22
|
-
braintree_customer.last_name.
|
21
|
+
braintree_customer.first_name.should == 'Brain'
|
22
|
+
braintree_customer.last_name.should == 'Tree'
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'should be able to create new customer with a credit card' do
|
26
26
|
customer = BraintreeRails::Customer.create(:first_name => 'Brain', :last_name => 'Tree', :credit_card => credit_card_hash)
|
27
27
|
braintree_customer = Braintree::Customer.find(customer.id)
|
28
|
-
braintree_customer.credit_cards.count.
|
28
|
+
braintree_customer.credit_cards.count.should == 1
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should be able to update existing customer' do
|
@@ -33,8 +33,8 @@ describe 'Customer Integration' do
|
|
33
33
|
customer.update_attributes!(:first_name => 'Foo', :last_name => 'Bar')
|
34
34
|
|
35
35
|
braintree_customer = Braintree::Customer.find(customer.id)
|
36
|
-
braintree_customer.first_name.
|
37
|
-
braintree_customer.last_name.
|
36
|
+
braintree_customer.first_name.should == 'Foo'
|
37
|
+
braintree_customer.last_name.should == 'Bar'
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'should be able to update existing customer with new credit card' do
|
@@ -42,35 +42,35 @@ describe 'Customer Integration' do
|
|
42
42
|
customer.update_attributes!(:first_name => 'Foo', :last_name => 'Bar', :credit_card => credit_card_hash.merge(:cardholder_name => "FooBar"))
|
43
43
|
|
44
44
|
braintree_customer = Braintree::Customer.find(customer.id)
|
45
|
-
braintree_customer.credit_cards.first.cardholder_name.
|
45
|
+
braintree_customer.credit_cards.first.cardholder_name.should == "FooBar"
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should be able to destroy existing customer' do
|
49
49
|
customer = BraintreeRails::Customer.create!(:first_name => 'Brain', :last_name => 'Tree')
|
50
50
|
customer.destroy
|
51
|
-
|
52
|
-
customer.
|
53
|
-
customer.
|
51
|
+
expect { Braintree::Customer.find(customer.id) }.to raise_error(Braintree::NotFoundError)
|
52
|
+
customer.should_not be_persisted
|
53
|
+
customer.should be_frozen
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'should not throw error when trying to destory an already destoryed customer' do
|
57
57
|
customer = BraintreeRails::Customer.create!(:first_name => 'Brain', :last_name => 'Tree')
|
58
58
|
customer.destroy
|
59
|
-
|
60
|
-
customer.
|
61
|
-
customer.
|
59
|
+
expect { customer.destroy }.not_to raise_error()
|
60
|
+
customer.should_not be_persisted
|
61
|
+
customer.should be_frozen
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should be able to reload the customer attributes" do
|
65
65
|
customer = BraintreeRails::Customer.create!(:first_name => 'Brain', :last_name => 'Tree')
|
66
66
|
customer.first_name = 'new name'
|
67
|
-
customer.reload.first_name.
|
67
|
+
customer.reload.first_name.should == 'Brain'
|
68
68
|
end
|
69
69
|
|
70
70
|
it "should be able to reload associations" do
|
71
71
|
customer = BraintreeRails::Customer.create!(:first_name => 'Brain', :last_name => 'Tree')
|
72
|
-
customer.credit_cards.
|
72
|
+
customer.credit_cards.should be_empty
|
73
73
|
Braintree::CreditCard.create(credit_card_hash.merge(:customer_id => customer.id))
|
74
|
-
customer.reload.credit_cards.size.
|
74
|
+
customer.reload.credit_cards.size.should == 1
|
75
75
|
end
|
76
76
|
end
|