fake_braintree 0.4 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/Gemfile +9 -0
- data/NEWS.md +5 -1
- data/README.md +22 -19
- data/fake_braintree.gemspec +0 -4
- data/lib/fake_braintree/address.rb +1 -1
- data/lib/fake_braintree/credit_card.rb +5 -5
- data/lib/fake_braintree/customer.rb +4 -4
- data/lib/fake_braintree/redirect.rb +2 -2
- data/lib/fake_braintree/server.rb +1 -1
- data/lib/fake_braintree/sinatra_app.rb +28 -17
- data/lib/fake_braintree/subscription.rb +4 -3
- data/lib/fake_braintree/version.rb +1 -1
- data/spec/fake_braintree/address_spec.rb +1 -1
- data/spec/fake_braintree/credit_card_spec.rb +30 -28
- data/spec/fake_braintree/customer_spec.rb +32 -36
- data/spec/fake_braintree/subscription_spec.rb +33 -16
- data/spec/fake_braintree/transaction_spec.rb +26 -25
- data/spec/fake_braintree/transparent_redirect_spec.rb +21 -21
- data/spec/fake_braintree_spec.rb +23 -22
- data/spec/support/braintree_helpers.rb +4 -4
- data/spec/support/customer_helpers.rb +1 -1
- data/spec/support/subscription_helpers.rb +7 -3
- metadata +27 -41
@@ -5,9 +5,9 @@ describe 'Braintree::Customer.create' do
|
|
5
5
|
|
6
6
|
it 'successfully creates a customer' do
|
7
7
|
result = Braintree::Customer.create(
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
8
|
+
credit_card: {
|
9
|
+
number: TEST_CC_NUMBER,
|
10
|
+
expiration_date: '04/2016'
|
11
11
|
}
|
12
12
|
)
|
13
13
|
result.should be_success
|
@@ -15,9 +15,9 @@ describe 'Braintree::Customer.create' do
|
|
15
15
|
|
16
16
|
it 'associates a created credit card with the customer' do
|
17
17
|
result = Braintree::Customer.create(
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
18
|
+
credit_card: {
|
19
|
+
number: TEST_CC_NUMBER,
|
20
|
+
expiration_date: '04/2016'
|
21
21
|
}
|
22
22
|
)
|
23
23
|
credit_cards = Braintree::Customer.find(result.customer.id).credit_cards
|
@@ -27,9 +27,9 @@ describe 'Braintree::Customer.create' do
|
|
27
27
|
|
28
28
|
it "successfully creates the customer's credit card" do
|
29
29
|
result = Braintree::Customer.create(
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
30
|
+
credit_card: {
|
31
|
+
number: TEST_CC_NUMBER,
|
32
|
+
expiration_date: '04/2016'
|
33
33
|
}
|
34
34
|
)
|
35
35
|
|
@@ -39,9 +39,9 @@ describe 'Braintree::Customer.create' do
|
|
39
39
|
|
40
40
|
it "sets a default credit card for the customer" do
|
41
41
|
result = Braintree::Customer.create(
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
42
|
+
credit_card: {
|
43
|
+
number: TEST_CC_NUMBER,
|
44
|
+
expiration_date: '04/2016'
|
45
45
|
}
|
46
46
|
)
|
47
47
|
|
@@ -50,7 +50,7 @@ describe 'Braintree::Customer.create' do
|
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'can handle an empty credit card hash' do
|
53
|
-
result = Braintree::Customer.create(:
|
53
|
+
result = Braintree::Customer.create(credit_card: {})
|
54
54
|
result.should be_success
|
55
55
|
end
|
56
56
|
|
@@ -62,10 +62,10 @@ describe 'Braintree::Customer.create' do
|
|
62
62
|
|
63
63
|
it 'creates a customer using an expiration month and year' do
|
64
64
|
result = Braintree::Customer.create(
|
65
|
-
:
|
66
|
-
:
|
67
|
-
:
|
68
|
-
:
|
65
|
+
credit_card: {
|
66
|
+
number: TEST_CC_NUMBER,
|
67
|
+
expiration_month: '04',
|
68
|
+
expiration_year: '2016'
|
69
69
|
}
|
70
70
|
)
|
71
71
|
result.should be_success
|
@@ -73,13 +73,13 @@ describe 'Braintree::Customer.create' do
|
|
73
73
|
|
74
74
|
it 'records the billing address' do
|
75
75
|
result = create_customer(
|
76
|
-
:
|
77
|
-
:
|
78
|
-
:
|
79
|
-
:
|
80
|
-
:
|
81
|
-
:
|
82
|
-
:
|
76
|
+
billing_address: {
|
77
|
+
street_address: '1 E Main St',
|
78
|
+
extended_address: 'Suite 3',
|
79
|
+
locality: 'Chicago',
|
80
|
+
region: 'Illinois',
|
81
|
+
postal_code: '60622',
|
82
|
+
country_code_alpha2: 'US'
|
83
83
|
}
|
84
84
|
)
|
85
85
|
|
@@ -90,13 +90,13 @@ describe 'Braintree::Customer.create' do
|
|
90
90
|
end
|
91
91
|
end
|
92
92
|
|
93
|
-
describe 'Braintree::Customer.create', 'when passed :
|
93
|
+
describe 'Braintree::Customer.create', 'when passed verify_card: true' do
|
94
94
|
it 'accepts valid cards' do
|
95
|
-
create_customer(:
|
95
|
+
create_customer(options: { verify_card: true }).should be_success
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'rejects invalid cards' do
|
99
|
-
create_customer_with_invalid_card(:
|
99
|
+
create_customer_with_invalid_card(options: { verify_card: true }).should_not be_success
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
@@ -115,8 +115,8 @@ end
|
|
115
115
|
describe 'Braintree::Customer.find' do
|
116
116
|
it 'successfully finds a customer' do
|
117
117
|
result = Braintree::Customer.create(
|
118
|
-
:
|
119
|
-
:
|
118
|
+
first_name: 'Bob',
|
119
|
+
last_name: 'Smith'
|
120
120
|
)
|
121
121
|
|
122
122
|
Braintree::Customer.find(result.customer.id).first_name.should == 'Bob'
|
@@ -130,14 +130,14 @@ end
|
|
130
130
|
describe 'Braintree::Customer.update' do
|
131
131
|
it 'successfully updates a customer' do
|
132
132
|
customer_id = create_customer.customer.id
|
133
|
-
result = Braintree::Customer.update(customer_id, :
|
133
|
+
result = Braintree::Customer.update(customer_id, first_name: 'Jerry')
|
134
134
|
|
135
135
|
result.should be_success
|
136
136
|
Braintree::Customer.find(customer_id).first_name.should == 'Jerry'
|
137
137
|
end
|
138
138
|
|
139
139
|
it 'raises an error for a nonexistent customer' do
|
140
|
-
|
140
|
+
expect { Braintree::Customer.update('foo', {first_name: 'Bob'}) }.to raise_error(Braintree::NotFoundError)
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'does not allow a customer to be updated to a failing credit card' do
|
@@ -146,11 +146,7 @@ describe 'Braintree::Customer.update' do
|
|
146
146
|
|
147
147
|
customer = create_customer
|
148
148
|
result = Braintree::Customer.update(customer.customer.id,
|
149
|
-
{
|
150
|
-
:credit_card => {
|
151
|
-
:number => bad_credit_card
|
152
|
-
}
|
153
|
-
}
|
149
|
+
credit_card: { number: bad_credit_card }
|
154
150
|
)
|
155
151
|
result.should_not be_success
|
156
152
|
end
|
@@ -6,8 +6,8 @@ describe 'Braintree::Subscription.create' do
|
|
6
6
|
|
7
7
|
it 'successfully creates a subscription' do
|
8
8
|
Braintree::Subscription.create(
|
9
|
-
:
|
10
|
-
:
|
9
|
+
payment_method_token: cc_token,
|
10
|
+
plan_id: 'my_plan_id'
|
11
11
|
).should be_success
|
12
12
|
end
|
13
13
|
|
@@ -15,16 +15,20 @@ describe 'Braintree::Subscription.create' do
|
|
15
15
|
create_subscription.subscription.id.should =~ /^[a-z0-9]{6}$/
|
16
16
|
end
|
17
17
|
|
18
|
+
it 'supports custom IDs' do
|
19
|
+
create_subscription('id' => 'custom1').subscription.id.should == 'custom1'
|
20
|
+
end
|
21
|
+
|
18
22
|
it 'assigns unique IDs to each subscription' do
|
19
23
|
cc_token_1 = cc_token
|
20
24
|
cc_token_2 = braintree_credit_card_token(TEST_CC_NUMBER.sub('1', '5'), expiration_date)
|
21
25
|
first_result = Braintree::Subscription.create(
|
22
|
-
:
|
23
|
-
:
|
26
|
+
payment_method_token: cc_token_1,
|
27
|
+
plan_id: plan_id
|
24
28
|
)
|
25
29
|
second_result = Braintree::Subscription.create(
|
26
|
-
:
|
27
|
-
:
|
30
|
+
payment_method_token: cc_token_2,
|
31
|
+
plan_id: plan_id
|
28
32
|
)
|
29
33
|
|
30
34
|
first_result.subscription.id.should_not == second_result.subscription.id
|
@@ -45,8 +49,10 @@ describe 'Braintree::Subscription.find' do
|
|
45
49
|
it 'can find a created subscription' do
|
46
50
|
payment_method_token = cc_token
|
47
51
|
plan_id = 'abc123'
|
48
|
-
subscription_id =
|
49
|
-
|
52
|
+
subscription_id = create_subscription(
|
53
|
+
payment_method_token: payment_method_token,
|
54
|
+
plan_id: plan_id
|
55
|
+
).subscription.id
|
50
56
|
subscription = Braintree::Subscription.find(subscription_id)
|
51
57
|
subscription.should_not be_nil
|
52
58
|
subscription.payment_method_token.should == payment_method_token
|
@@ -60,7 +66,7 @@ describe 'Braintree::Subscription.find' do
|
|
60
66
|
|
61
67
|
it 'returns add-ons added with the subscription' do
|
62
68
|
add_on_id = 'def456'
|
63
|
-
subscription_id = create_subscription(:
|
69
|
+
subscription_id = create_subscription(add_ons: { add: [{ inherited_from_id: add_on_id }] }).subscription.id
|
64
70
|
subscription = Braintree::Subscription.find(subscription_id)
|
65
71
|
add_ons = subscription.add_ons
|
66
72
|
add_ons.size.should == 1
|
@@ -69,7 +75,7 @@ describe 'Braintree::Subscription.find' do
|
|
69
75
|
|
70
76
|
it 'returns discounts added with the subscription' do
|
71
77
|
discount_id = 'def456'
|
72
|
-
subscription_id = create_subscription(:
|
78
|
+
subscription_id = create_subscription(discounts: { add: [{ inherited_from_id: discount_id, amount: BigDecimal.new('15.00') }]}).subscription.id
|
73
79
|
subscription = Braintree::Subscription.find(subscription_id)
|
74
80
|
discounts = subscription.discounts
|
75
81
|
discounts.size.should == 1
|
@@ -79,16 +85,30 @@ end
|
|
79
85
|
|
80
86
|
describe 'Braintree::Subscription.update' do
|
81
87
|
it 'can update a subscription' do
|
82
|
-
|
88
|
+
subscription_id = create_subscription.subscription.id
|
89
|
+
|
90
|
+
Braintree::Subscription.update(subscription_id, plan_id: 'a_new_plan')
|
83
91
|
Braintree::Subscription.find(subscription_id).plan_id.should == 'a_new_plan'
|
84
92
|
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'Braintree::Subscription.retry_charge' do
|
96
|
+
it 'can submit for settlement' do
|
97
|
+
subscription_id = create_subscription.subscription.id
|
85
98
|
|
86
|
-
|
87
|
-
|
99
|
+
authorized_transaction = Braintree::Subscription.retry_charge(subscription_id, 42.0).transaction
|
100
|
+
result = Braintree::Transaction.submit_for_settlement(
|
101
|
+
authorized_transaction.id
|
102
|
+
)
|
103
|
+
result.should be_success
|
104
|
+
end
|
88
105
|
end
|
89
106
|
|
107
|
+
|
90
108
|
describe 'Braintree::Subscription.cancel' do
|
91
109
|
it 'can cancel a subscription' do
|
110
|
+
subscription_id = create_subscription.subscription.id
|
111
|
+
|
92
112
|
Braintree::Subscription.cancel(subscription_id).should be_success
|
93
113
|
Braintree::Subscription.find(subscription_id).status.should == Braintree::Subscription::Status::Canceled
|
94
114
|
end
|
@@ -96,7 +116,4 @@ describe 'Braintree::Subscription.cancel' do
|
|
96
116
|
it 'cannot cancel an unknown subscription' do
|
97
117
|
expect { Braintree::Subscription.cancel('totally-bogus-id') }.to raise_error(Braintree::NotFoundError)
|
98
118
|
end
|
99
|
-
|
100
|
-
let(:subscription_id) { subscription.subscription.id }
|
101
|
-
let(:subscription) { create_subscription }
|
102
119
|
end
|
@@ -4,8 +4,8 @@ describe FakeBraintree::SinatraApp do
|
|
4
4
|
context 'Braintree::Transaction.sale' do
|
5
5
|
it 'successfully creates a transaction' do
|
6
6
|
result = Braintree::Transaction.sale(
|
7
|
-
:
|
8
|
-
:
|
7
|
+
payment_method_token: cc_token,
|
8
|
+
amount: 10.00
|
9
9
|
)
|
10
10
|
result.should be_success
|
11
11
|
result.transaction.type.should == 'sale'
|
@@ -16,8 +16,8 @@ describe FakeBraintree::SinatraApp do
|
|
16
16
|
|
17
17
|
it 'fails' do
|
18
18
|
result = Braintree::Transaction.sale(
|
19
|
-
:
|
20
|
-
:
|
19
|
+
payment_method_token: cc_token,
|
20
|
+
amount: 10.00
|
21
21
|
)
|
22
22
|
result.should_not be_success
|
23
23
|
end
|
@@ -25,7 +25,7 @@ describe FakeBraintree::SinatraApp do
|
|
25
25
|
|
26
26
|
context "when the options hash is nil" do
|
27
27
|
it "returns a transaction with a status of authorized" do
|
28
|
-
result = Braintree::Transaction.sale(:
|
28
|
+
result = Braintree::Transaction.sale(payment_method_token: cc_token, amount: 10.00)
|
29
29
|
result.transaction.status.should == 'authorized'
|
30
30
|
end
|
31
31
|
end
|
@@ -33,10 +33,10 @@ describe FakeBraintree::SinatraApp do
|
|
33
33
|
context "when submit_for_settlement is not true" do
|
34
34
|
it "returns a transaction with a status of authorized" do
|
35
35
|
result = Braintree::Transaction.sale(
|
36
|
-
:
|
37
|
-
:
|
38
|
-
:
|
39
|
-
:
|
36
|
+
payment_method_token: cc_token,
|
37
|
+
amount: 10.00,
|
38
|
+
options: {
|
39
|
+
submit_for_settlement: false
|
40
40
|
}
|
41
41
|
)
|
42
42
|
result.transaction.status.should == 'authorized'
|
@@ -46,10 +46,10 @@ describe FakeBraintree::SinatraApp do
|
|
46
46
|
context "when submit_for_settlement does not exist" do
|
47
47
|
it "returns a transaction with a status of authorized" do
|
48
48
|
result = Braintree::Transaction.sale(
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:
|
49
|
+
payment_method_token: cc_token,
|
50
|
+
amount: 10.00,
|
51
|
+
options: {
|
52
|
+
add_billing_address_to_payment_method: true
|
53
53
|
}
|
54
54
|
)
|
55
55
|
result.transaction.status.should == 'authorized'
|
@@ -59,10 +59,10 @@ describe FakeBraintree::SinatraApp do
|
|
59
59
|
context "when submit_for_settlement is true" do
|
60
60
|
it "returns a transaction with a status of submitted_for_settlement" do
|
61
61
|
result = Braintree::Transaction.sale(
|
62
|
-
:
|
63
|
-
:
|
64
|
-
:
|
65
|
-
:
|
62
|
+
payment_method_token: cc_token,
|
63
|
+
amount: 10.00,
|
64
|
+
options: {
|
65
|
+
submit_for_settlement: true
|
66
66
|
}
|
67
67
|
)
|
68
68
|
result.transaction.status.should == 'submitted_for_settlement'
|
@@ -84,8 +84,8 @@ describe FakeBraintree::SinatraApp do
|
|
84
84
|
context 'Braintree::Transaction.void' do
|
85
85
|
it 'successfully voids a transaction' do
|
86
86
|
sale = Braintree::Transaction.sale(
|
87
|
-
:
|
88
|
-
:
|
87
|
+
payment_method_token: cc_token,
|
88
|
+
amount: 10.00
|
89
89
|
)
|
90
90
|
result = Braintree::Transaction.void(sale.transaction.id)
|
91
91
|
result.should be_success
|
@@ -97,9 +97,9 @@ end
|
|
97
97
|
describe FakeBraintree::SinatraApp do
|
98
98
|
context 'Braintree::Transaction.find' do
|
99
99
|
it 'can find a created sale' do
|
100
|
-
id = create_transaction.id
|
100
|
+
id = create_transaction(10.00).id
|
101
101
|
result = Braintree::Transaction.find(id)
|
102
|
-
result.amount.should ==
|
102
|
+
result.amount.should == 10.00
|
103
103
|
end
|
104
104
|
|
105
105
|
it 'can find >1 transaction' do
|
@@ -111,10 +111,11 @@ describe FakeBraintree::SinatraApp do
|
|
111
111
|
expect { Braintree::Transaction.find('foobar') }.to raise_error(Braintree::NotFoundError)
|
112
112
|
end
|
113
113
|
|
114
|
-
def create_transaction
|
115
|
-
Braintree::Transaction.sale(
|
114
|
+
def create_transaction(amount = 10.00)
|
115
|
+
Braintree::Transaction.sale(
|
116
|
+
payment_method_token: cc_token,
|
117
|
+
amount: amount
|
118
|
+
).transaction
|
116
119
|
end
|
117
|
-
|
118
|
-
let(:amount) { 10.00 }
|
119
120
|
end
|
120
121
|
end
|
@@ -5,7 +5,7 @@ describe FakeBraintree::SinatraApp do
|
|
5
5
|
it 'returns a URL that will redirect with a token for the specified request' do
|
6
6
|
redirect_url = 'http://example.com/redirect_path'
|
7
7
|
|
8
|
-
response = post_transparent_redirect(:create_customer_data, :
|
8
|
+
response = post_transparent_redirect(:create_customer_data, redirect_url: redirect_url, customer: build_customer_hash)
|
9
9
|
|
10
10
|
response.code.should == '303'
|
11
11
|
response['Location'].should =~ %r{http://example\.com/redirect_path}
|
@@ -20,8 +20,8 @@ describe FakeBraintree::SinatraApp do
|
|
20
20
|
|
21
21
|
response = post_transparent_redirect(
|
22
22
|
:create_customer_data,
|
23
|
-
:
|
24
|
-
:
|
23
|
+
redirect_url: redirect_url,
|
24
|
+
customer: build_customer_hash
|
25
25
|
)
|
26
26
|
|
27
27
|
params = parse_redirect(response)
|
@@ -38,8 +38,8 @@ describe FakeBraintree::SinatraApp do
|
|
38
38
|
describe 'Creating customers' do
|
39
39
|
it 'confirms and runs the specified request' do
|
40
40
|
number = '4111111111111111'
|
41
|
-
customer_hash = build_customer_hash(:
|
42
|
-
response = post_transparent_redirect(:create_customer_data, :
|
41
|
+
customer_hash = build_customer_hash(credit_card: { number: number })
|
42
|
+
response = post_transparent_redirect(:create_customer_data, customer: customer_hash)
|
43
43
|
query = parse_query(response)
|
44
44
|
|
45
45
|
result = Braintree::TransparentRedirect.confirm(query)
|
@@ -55,8 +55,8 @@ describe FakeBraintree::SinatraApp do
|
|
55
55
|
it 'confirms and runs the specified request' do
|
56
56
|
customer = create_customer.customer
|
57
57
|
number = '4111111111111337'
|
58
|
-
credit_card_hash = build_credit_card_hash({ :
|
59
|
-
response = post_transparent_redirect(:create_credit_card_data, :
|
58
|
+
credit_card_hash = build_credit_card_hash({ number: number, customer_id: customer.id})
|
59
|
+
response = post_transparent_redirect(:create_credit_card_data, credit_card: credit_card_hash)
|
60
60
|
query = parse_query(response)
|
61
61
|
|
62
62
|
result = Braintree::TransparentRedirect.confirm(query)
|
@@ -71,25 +71,25 @@ describe FakeBraintree::SinatraApp do
|
|
71
71
|
|
72
72
|
def build_customer_hash(options = {})
|
73
73
|
{
|
74
|
-
:
|
75
|
-
:
|
76
|
-
:
|
77
|
-
:
|
74
|
+
credit_card: {
|
75
|
+
number: '4111111111111111',
|
76
|
+
expiration_date: '4/2015',
|
77
|
+
cardholder_name: 'Susie Spender'
|
78
78
|
}.update(options[:credit_card] || {})
|
79
79
|
}
|
80
80
|
end
|
81
81
|
|
82
82
|
def build_credit_card_hash(options = {})
|
83
83
|
{
|
84
|
-
:
|
85
|
-
:
|
86
|
-
:
|
87
|
-
:
|
88
|
-
:
|
89
|
-
:
|
90
|
-
:
|
91
|
-
:
|
92
|
-
:
|
84
|
+
number: '4111111111111111',
|
85
|
+
expiration_date: '4/2015',
|
86
|
+
cardholder_name: 'Susie Spender',
|
87
|
+
cvv: '123',
|
88
|
+
billing_address: {
|
89
|
+
street_address: '123 Sesame Street',
|
90
|
+
locality: 'San Francisco',
|
91
|
+
region: 'CA',
|
92
|
+
postal_code: '94110'
|
93
93
|
}
|
94
94
|
}.update(options || {})
|
95
95
|
end
|
@@ -97,7 +97,7 @@ describe FakeBraintree::SinatraApp do
|
|
97
97
|
def post_transparent_redirect(type, data)
|
98
98
|
params = data.dup
|
99
99
|
redirect_url = params.delete(:redirect_url) || 'http://example.com/redirect_path'
|
100
|
-
params[:tr_data] = Braintree::TransparentRedirect.send(type, {:
|
100
|
+
params[:tr_data] = Braintree::TransparentRedirect.send(type, {redirect_url: redirect_url}.merge(params))
|
101
101
|
post_transparent_redirect_params(params)
|
102
102
|
end
|
103
103
|
|