Skip to content

Commit 9095351

Browse files
Merge remote-tracking branch 'upstream/master'
2 parents 1c47cc9 + f7dbeb3 commit 9095351

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ rvm:
33
- 1.9.3
44
- 2.0.0
55
- 2.1.6
6+
before_install:
7+
- gem install bundler
68
before_script:
79
- "sudo touch /var/log/stripe-mock-server.log"
810
- "sudo chown travis /var/log/stripe-mock-server.log"

lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def custom_subscription_params(plan, cus, options = {})
2626
end
2727

2828
def add_subscription_to_customer(cus, sub)
29+
id = new_id('ch')
30+
charges[id] = Data.mock_charge(:id => id, :customer => cus[:id], :amount => sub[:plan][:amount])
2931
cus[:subscriptions][:total_count] = (cus[:subscriptions][:total_count] || 0) + 1
3032
cus[:subscriptions][:data].unshift sub
3133
end
@@ -41,14 +43,14 @@ def delete_subscription_from_customer(cus, subscription)
4143
# `intervals` is set to 2 when calculating Stripe::Invoice.upcoming end from current_period_start & plan
4244
def get_ending_time(start_time, plan, intervals = 1)
4345
case plan[:interval]
44-
when "week"
45-
start_time + (604800 * (plan[:interval_count] || 1) * intervals)
46-
when "month"
47-
(Time.at(start_time).to_datetime >> ((plan[:interval_count] || 1) * intervals)).to_time.to_i
48-
when "year"
49-
(Time.at(start_time).to_datetime >> (12 * intervals)).to_time.to_i # max period is 1 year
50-
else
51-
start_time
46+
when "week"
47+
start_time + (604800 * (plan[:interval_count] || 1) * intervals)
48+
when "month"
49+
(Time.at(start_time).to_datetime >> ((plan[:interval_count] || 1) * intervals)).to_time.to_i
50+
when "year"
51+
(Time.at(start_time).to_datetime >> (12 * intervals)).to_time.to_i # max period is 1 year
52+
else
53+
start_time
5254
end
5355
end
5456

spec/shared_stripe_examples/subscription_examples.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def gen_card_tk
2525
expect(customer.subscriptions.data).to_not be_empty
2626
expect(customer.subscriptions.count).to eq(1)
2727
expect(customer.subscriptions.data.length).to eq(1)
28+
expect(customer.charges.data.length).to eq(1)
2829

2930
expect(customer.subscriptions.data.first.id).to eq(sub.id)
3031
expect(customer.subscriptions.data.first.plan.to_hash).to eq(plan.to_hash)
@@ -33,6 +34,17 @@ def gen_card_tk
3334
expect(customer.subscriptions.data.first.metadata.example).to eq( "yes" )
3435

3536
end
37+
38+
it 'creates a charge for the customer', live: true do
39+
stripe_helper.create_plan(id: 'silver', name: 'Silver Plan', amount: 4999)
40+
41+
customer = Stripe::Customer.create(source: gen_card_tk)
42+
customer.subscriptions.create({ :plan => 'silver', :metadata => { :foo => "bar", :example => "yes" } })
43+
customer = Stripe::Customer.retrieve(customer.id)
44+
45+
expect(customer.charges.data.length).to eq(1)
46+
expect(customer.charges.data.first.amount).to eq(4999)
47+
end
3648

3749
it 'contains coupon object', live: true do
3850
plan = stripe_helper.create_plan(id: 'plan_with_coupon', name: 'One More Test Plan', amount: 777)

0 commit comments

Comments
 (0)