braintree 2.6.1 → 2.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/braintree/credit_card_gateway.rb +2 -1
- data/lib/braintree/subscription.rb +8 -0
- data/lib/braintree/subscription_search.rb +1 -0
- data/lib/braintree/transaction.rb +1 -1
- data/lib/braintree/version.rb +1 -1
- data/spec/integration/braintree/credit_card_spec.rb +16 -0
- data/spec/integration/braintree/customer_spec.rb +24 -0
- data/spec/integration/braintree/subscription_spec.rb +97 -0
- data/spec/unit/braintree/credit_card_spec.rb +2 -0
- data/spec/unit/braintree/customer_spec.rb +2 -0
- data/spec/unit/braintree/subscription_search_spec.rb +16 -0
- metadata +4 -11
@@ -76,7 +76,8 @@ module Braintree
|
|
76
76
|
def self._signature(type) # :nodoc:
|
77
77
|
billing_address_params = AddressGateway._shared_signature
|
78
78
|
signature = [
|
79
|
-
:cardholder_name, :cvv, :expiration_date,
|
79
|
+
:billing_address_id, :cardholder_name, :cvv, :expiration_date,
|
80
|
+
:expiration_month, :expiration_year, :number, :token,
|
80
81
|
{:options => [:make_default, :verification_merchant_account_id, :verify_card]},
|
81
82
|
{:billing_address => billing_address_params}
|
82
83
|
]
|
@@ -38,6 +38,10 @@ module Braintree
|
|
38
38
|
Configuration.gateway.subscription.create(attributes)
|
39
39
|
end
|
40
40
|
|
41
|
+
def self.create!(attributes)
|
42
|
+
return_object_or_raise(:subscription) { create(attributes) }
|
43
|
+
end
|
44
|
+
|
41
45
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/subscriptions/search
|
42
46
|
def self.find(id)
|
43
47
|
Configuration.gateway.subscription.find(id)
|
@@ -57,6 +61,10 @@ module Braintree
|
|
57
61
|
Configuration.gateway.subscription.update(subscription_id, attributes)
|
58
62
|
end
|
59
63
|
|
64
|
+
def self.update!(subscription_id, attributes)
|
65
|
+
return_object_or_raise(:subscription) { update(subscription_id, attributes) }
|
66
|
+
end
|
67
|
+
|
60
68
|
def initialize(gateway, attributes) # :nodoc:
|
61
69
|
@gateway = gateway
|
62
70
|
set_instance_variables_from_hash(attributes)
|
data/lib/braintree/version.rb
CHANGED
@@ -57,6 +57,22 @@ describe Braintree::CreditCard do
|
|
57
57
|
credit_card.expiration_date.should == "05/2009"
|
58
58
|
end
|
59
59
|
|
60
|
+
it "accepts billing_address_id" do
|
61
|
+
customer = Braintree::Customer.create!
|
62
|
+
address = Braintree::Address.create!(:customer_id => customer.id, :first_name => "Bobby", :last_name => "Tables")
|
63
|
+
|
64
|
+
credit_card = Braintree::CreditCard.create(
|
65
|
+
:customer_id => customer.id,
|
66
|
+
:number => Braintree::Test::CreditCardNumbers::FailsSandboxVerification::Visa,
|
67
|
+
:expiration_date => "05/2009",
|
68
|
+
:billing_address_id => address.id
|
69
|
+
).credit_card
|
70
|
+
|
71
|
+
credit_card.billing_address.id.should == address.id
|
72
|
+
credit_card.billing_address.first_name.should == "Bobby"
|
73
|
+
credit_card.billing_address.last_name.should == "Tables"
|
74
|
+
end
|
75
|
+
|
60
76
|
it "verifies the credit card if options[verify_card]=true" do
|
61
77
|
customer = Braintree::Customer.create!
|
62
78
|
result = Braintree::CreditCard.create(
|
@@ -744,6 +744,30 @@ describe Braintree::Customer do
|
|
744
744
|
credit_card.billing_address.postal_code.should == "60666"
|
745
745
|
end
|
746
746
|
|
747
|
+
it "can update the nested billing address with billing_address_id" do
|
748
|
+
customer = Braintree::Customer.create!
|
749
|
+
|
750
|
+
address = Braintree::Address.create!(
|
751
|
+
:customer_id => customer.id,
|
752
|
+
:first_name => "John",
|
753
|
+
:last_name => "Doe"
|
754
|
+
)
|
755
|
+
|
756
|
+
customer = Braintree::Customer.update(
|
757
|
+
customer.id,
|
758
|
+
:credit_card => {
|
759
|
+
:number => Braintree::Test::CreditCardNumbers::Visa,
|
760
|
+
:expiration_date => "12/2009",
|
761
|
+
:billing_address_id => address.id
|
762
|
+
}
|
763
|
+
).customer
|
764
|
+
|
765
|
+
billing_address = customer.credit_cards.first.billing_address
|
766
|
+
billing_address.id.should == address.id
|
767
|
+
billing_address.first_name.should == "John"
|
768
|
+
billing_address.last_name.should == "Doe"
|
769
|
+
end
|
770
|
+
|
747
771
|
it "returns an error response if invalid" do
|
748
772
|
customer = Braintree::Customer.create!(:email => "valid@email.com")
|
749
773
|
result = Braintree::Customer.update(
|
@@ -522,6 +522,40 @@ describe Braintree::Subscription do
|
|
522
522
|
end
|
523
523
|
end
|
524
524
|
|
525
|
+
describe "self.create!" do
|
526
|
+
it "returns the subscription if valid" do
|
527
|
+
subscription = Braintree::Subscription.create!(
|
528
|
+
:payment_method_token => @credit_card.token,
|
529
|
+
:plan_id => SpecHelper::TriallessPlan[:id]
|
530
|
+
)
|
531
|
+
|
532
|
+
date_format = /^\d{4}\D\d{1,2}\D\d{1,2}$/
|
533
|
+
subscription.id.should =~ /^\w{6}$/
|
534
|
+
subscription.status.should == Braintree::Subscription::Status::Active
|
535
|
+
subscription.plan_id.should == "integration_trialless_plan"
|
536
|
+
|
537
|
+
subscription.first_billing_date.should match(date_format)
|
538
|
+
subscription.next_billing_date.should match(date_format)
|
539
|
+
subscription.billing_period_start_date.should match(date_format)
|
540
|
+
subscription.billing_period_end_date.should match(date_format)
|
541
|
+
subscription.paid_through_date.should match(date_format)
|
542
|
+
|
543
|
+
subscription.failure_count.should == 0
|
544
|
+
subscription.next_bill_amount.should == "12.34"
|
545
|
+
subscription.next_billing_period_amount.should == "12.34"
|
546
|
+
subscription.payment_method_token.should == @credit_card.token
|
547
|
+
end
|
548
|
+
|
549
|
+
it "raises a ValidationsFailed if invalid" do
|
550
|
+
expect do
|
551
|
+
Braintree::Subscription.create!(
|
552
|
+
:payment_method_token => @credit_card.token,
|
553
|
+
:plan_id => 'not_a_plan_id'
|
554
|
+
)
|
555
|
+
end.to raise_error(Braintree::ValidationsFailed)
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
525
559
|
describe "self.find" do
|
526
560
|
it "finds a subscription" do
|
527
561
|
result = Braintree::Subscription.create(
|
@@ -921,6 +955,38 @@ describe Braintree::Subscription do
|
|
921
955
|
end
|
922
956
|
end
|
923
957
|
|
958
|
+
describe "self.update!" do
|
959
|
+
before(:each) do
|
960
|
+
@subscription = Braintree::Subscription.create(
|
961
|
+
:payment_method_token => @credit_card.token,
|
962
|
+
:price => 54.32,
|
963
|
+
:plan_id => SpecHelper::TriallessPlan[:id]
|
964
|
+
).subscription
|
965
|
+
end
|
966
|
+
|
967
|
+
it "returns the updated subscription if valid" do
|
968
|
+
new_id = rand(36**9).to_s(36)
|
969
|
+
subscription = Braintree::Subscription.update!(@subscription.id,
|
970
|
+
:id => new_id,
|
971
|
+
:price => 9999.88,
|
972
|
+
:plan_id => SpecHelper::TrialPlan[:id]
|
973
|
+
)
|
974
|
+
|
975
|
+
subscription.id.should =~ /#{new_id}/
|
976
|
+
subscription.plan_id.should == SpecHelper::TrialPlan[:id]
|
977
|
+
subscription.price.should == BigDecimal.new("9999.88")
|
978
|
+
end
|
979
|
+
|
980
|
+
it "raises a ValidationsFailed if invalid" do
|
981
|
+
expect do
|
982
|
+
Braintree::Subscription.update!(@subscription.id,
|
983
|
+
:plan_id => 'not_a_plan_id'
|
984
|
+
)
|
985
|
+
end.to raise_error(Braintree::ValidationsFailed)
|
986
|
+
end
|
987
|
+
|
988
|
+
end
|
989
|
+
|
924
990
|
describe "self.cancel" do
|
925
991
|
it "returns a success response with the updated subscription if valid" do
|
926
992
|
subscription = Braintree::Subscription.create(
|
@@ -958,6 +1024,37 @@ describe Braintree::Subscription do
|
|
958
1024
|
end
|
959
1025
|
|
960
1026
|
describe "self.search" do
|
1027
|
+
describe "in_trial_period" do
|
1028
|
+
it "works in the affirmative" do
|
1029
|
+
id = rand(36**8).to_s(36)
|
1030
|
+
subscription_with_trial = Braintree::Subscription.create(
|
1031
|
+
:payment_method_token => @credit_card.token,
|
1032
|
+
:plan_id => SpecHelper::TrialPlan[:id],
|
1033
|
+
:id => "subscription1_#{id}"
|
1034
|
+
).subscription
|
1035
|
+
|
1036
|
+
subscription_without_trial = Braintree::Subscription.create(
|
1037
|
+
:payment_method_token => @credit_card.token,
|
1038
|
+
:plan_id => SpecHelper::TriallessPlan[:id],
|
1039
|
+
:id => "subscription2_#{id}"
|
1040
|
+
).subscription
|
1041
|
+
|
1042
|
+
subscriptions_in_trial_period = Braintree::Subscription.search do |search|
|
1043
|
+
search.in_trial_period.is true
|
1044
|
+
end
|
1045
|
+
|
1046
|
+
subscriptions_in_trial_period.should include(subscription_with_trial)
|
1047
|
+
subscriptions_in_trial_period.should_not include(subscription_without_trial)
|
1048
|
+
|
1049
|
+
subscriptions_not_in_trial_period = Braintree::Subscription.search do |search|
|
1050
|
+
search.in_trial_period.is false
|
1051
|
+
end
|
1052
|
+
|
1053
|
+
subscriptions_not_in_trial_period.should_not include(subscription_with_trial)
|
1054
|
+
subscriptions_not_in_trial_period.should include(subscription_without_trial)
|
1055
|
+
end
|
1056
|
+
end
|
1057
|
+
|
961
1058
|
describe "id" do
|
962
1059
|
it "works using the is operator" do
|
963
1060
|
id = rand(36**8).to_s(36)
|
@@ -12,6 +12,7 @@ describe Braintree::CreditCard do
|
|
12
12
|
describe "self.create_signature" do
|
13
13
|
it "should be what we expect" do
|
14
14
|
Braintree::CreditCardGateway._create_signature.should == [
|
15
|
+
:billing_address_id,
|
15
16
|
:cardholder_name,
|
16
17
|
:cvv,
|
17
18
|
:expiration_date,
|
@@ -42,6 +43,7 @@ describe Braintree::CreditCard do
|
|
42
43
|
describe "self.update_signature" do
|
43
44
|
it "should be what we expect" do
|
44
45
|
Braintree::CreditCardGateway._update_signature.should == [
|
46
|
+
:billing_address_id,
|
45
47
|
:cardholder_name,
|
46
48
|
:cvv,
|
47
49
|
:expiration_date,
|
@@ -61,6 +61,7 @@ describe Braintree::Customer do
|
|
61
61
|
:phone,
|
62
62
|
:website,
|
63
63
|
{:credit_card => [
|
64
|
+
:billing_address_id,
|
64
65
|
:cardholder_name,
|
65
66
|
:cvv,
|
66
67
|
:expiration_date,
|
@@ -101,6 +102,7 @@ describe Braintree::Customer do
|
|
101
102
|
:phone,
|
102
103
|
:website,
|
103
104
|
{:credit_card => [
|
105
|
+
:billing_address_id,
|
104
106
|
:cardholder_name,
|
105
107
|
:cvv,
|
106
108
|
:expiration_date,
|
@@ -17,6 +17,22 @@ module Braintree
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
+
context "in_trial_period" do
|
21
|
+
it "allows true" do
|
22
|
+
search = SubscriptionSearch.new
|
23
|
+
search.in_trial_period.is true
|
24
|
+
|
25
|
+
search.to_hash.should == {:in_trial_period => [true]}
|
26
|
+
end
|
27
|
+
|
28
|
+
it "allows false" do
|
29
|
+
search = SubscriptionSearch.new
|
30
|
+
search.in_trial_period.is false
|
31
|
+
|
32
|
+
search.to_hash.should == {:in_trial_period => [false]}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
20
36
|
context "days_past_due" do
|
21
37
|
it "correctly builds a hash with the criteria" do
|
22
38
|
search = SubscriptionSearch.new
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: braintree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 21
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 2
|
8
7
|
- 6
|
9
|
-
-
|
10
|
-
version: 2.6.
|
8
|
+
- 2
|
9
|
+
version: 2.6.2
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Braintree Payment Solutions
|
@@ -15,18 +14,16 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-
|
17
|
+
date: 2010-11-05 00:00:00 -05:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: builder
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ">="
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
27
|
segments:
|
31
28
|
- 0
|
32
29
|
version: "0"
|
@@ -146,27 +143,23 @@ rdoc_options: []
|
|
146
143
|
require_paths:
|
147
144
|
- lib
|
148
145
|
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
146
|
requirements:
|
151
147
|
- - ">="
|
152
148
|
- !ruby/object:Gem::Version
|
153
|
-
hash: 3
|
154
149
|
segments:
|
155
150
|
- 0
|
156
151
|
version: "0"
|
157
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
-
none: false
|
159
153
|
requirements:
|
160
154
|
- - ">="
|
161
155
|
- !ruby/object:Gem::Version
|
162
|
-
hash: 3
|
163
156
|
segments:
|
164
157
|
- 0
|
165
158
|
version: "0"
|
166
159
|
requirements: []
|
167
160
|
|
168
161
|
rubyforge_project: braintree
|
169
|
-
rubygems_version: 1.3.
|
162
|
+
rubygems_version: 1.3.6
|
170
163
|
signing_key:
|
171
164
|
specification_version: 3
|
172
165
|
summary: Braintree Gateway Ruby Client Library
|