stripe-ruby-mock 1.10.1.6 → 1.10.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  In your gemfile:
10
10
 
11
- gem 'stripe-ruby-mock', '~> 1.10.1.6'
11
+ gem 'stripe-ruby-mock', '~> 1.10.1.7'
12
12
 
13
13
  ## Features
14
14
 
@@ -22,8 +22,9 @@ module StripeMock
22
22
  customers[ params[:id] ] = Data.mock_customer(cards, params)
23
23
 
24
24
  if params[:plan]
25
- plan = plans[ params[:plan] ]
26
- assert_existance :plan, params[:plan], plan
25
+ plan_id = params[:plan].to_s
26
+ plan = plans[plan_id]
27
+ assert_existance :plan, plan_id, plan
27
28
 
28
29
  if params[:default_card].nil? && plan[:trial_period_days].nil? && plan[:amount] != 0
29
30
  raise Stripe::InvalidRequestError.new('You must supply a valid card', nil, 400)
@@ -11,7 +11,7 @@ module StripeMock
11
11
  end
12
12
 
13
13
  def new_plan(route, method_url, params, headers)
14
- params[:id] ||= new_id('plan')
14
+ params[:id] = ( params[:id] || new_id('plan') ).to_s
15
15
  plans[ params[:id] ] = Data.mock_plan(params)
16
16
  end
17
17
 
@@ -19,6 +19,12 @@ module StripeMock
19
19
  plan = plans[params[:plan]]
20
20
  assert_existance :plan, params[:plan], plan
21
21
 
22
+ if params[:card]
23
+ new_card = get_card_by_token(params.delete(:card))
24
+ add_card_to_customer(new_card, customer)
25
+ customer[:default_card] = new_card[:id]
26
+ end
27
+
22
28
  # Ensure customer has card to charge if plan has no trial and is not free
23
29
  verify_card_present(customer, plan)
24
30
 
@@ -119,4 +125,4 @@ module StripeMock
119
125
 
120
126
  end
121
127
  end
122
- end
128
+ end
@@ -1,4 +1,4 @@
1
1
  module StripeMock
2
2
  # stripe-ruby-mock version
3
- VERSION = "1.10.1.6"
3
+ VERSION = "1.10.1.7"
4
4
  end
@@ -47,6 +47,20 @@ shared_examples 'Customer API' do
47
47
  expect(customer.subscriptions.first.customer).to eq(customer.id)
48
48
  end
49
49
 
50
+ it "creates a customer with a plan (string/symbol agnostic)" do
51
+ plan = Stripe::Plan.create(id: 'string_id')
52
+ customer = Stripe::Customer.create(id: 'test_cus_plan', card: 'tk', :plan => :string_id)
53
+
54
+ customer = Stripe::Customer.retrieve('test_cus_plan')
55
+ expect(customer.subscriptions.first.plan.id).to eq('string_id')
56
+
57
+ plan = Stripe::Plan.create(:id => :sym_id)
58
+ customer = Stripe::Customer.create(id: 'test_cus_plan', card: 'tk', :plan => 'sym_id')
59
+
60
+ customer = Stripe::Customer.retrieve('test_cus_plan')
61
+ expect(customer.subscriptions.first.plan.id).to eq('sym_id')
62
+ end
63
+
50
64
  context "create customer" do
51
65
 
52
66
  it "with a trial when trial_end is set" do
@@ -107,7 +107,7 @@ shared_examples 'Invoice API' do
107
107
  expect(@upcoming.total).to eq(@upcoming.lines.data[0].amount)
108
108
  expect(@upcoming.period_end).to eq(@upcoming.lines.data[0].period.start)
109
109
  expect(Time.at(@upcoming.period_start).to_datetime >> 1).to eq(Time.at(@upcoming.period_end).to_datetime) # +1 month
110
- expect(Time.at(@upcoming.period_end).to_datetime >> 1).to eq(Time.at(@upcoming.lines.data[0].period.end).to_datetime) # +1 month
110
+ expect(Time.at(@upcoming.period_start).to_datetime >> 2).to eq(Time.at(@upcoming.lines.data[0].period.end).to_datetime) # +1 month
111
111
  expect(@upcoming.next_payment_attempt).to eq(@upcoming.period_end + 3600) # +1 hour
112
112
  expect(@upcoming.subscription).to eq(@subscription.id)
113
113
  end
@@ -66,6 +66,22 @@ shared_examples 'Customer Subscriptions' do
66
66
  expect(customer.subscriptions.data.last.customer).to eq(customer.id)
67
67
  end
68
68
 
69
+ it "subscribes a cardless customer when specifing a card token" do
70
+ plan = Stripe::Plan.create(id: 'enterprise', amount: 499)
71
+ customer = Stripe::Customer.create(id: 'cardless')
72
+
73
+ sub = customer.subscriptions.create({ :plan => 'enterprise', :card => 'card_token' })
74
+ customer = Stripe::Customer.retrieve('cardless')
75
+
76
+ expect(customer.subscriptions.data.first.id).to eq(sub.id)
77
+ expect(customer.subscriptions.data.first.customer).to eq(customer.id)
78
+
79
+ expect(customer.cards.count).to eq(1)
80
+ expect(customer.cards.data.length).to eq(1)
81
+ expect(customer.default_card).to_not be_nil
82
+ expect(customer.default_card).to eq customer.cards.data.first.id
83
+ end
84
+
69
85
  it "throws an error when plan does not exist" do
70
86
  customer = Stripe::Customer.create(id: 'cardless')
71
87
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.1.6
4
+ version: 1.10.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-31 00:00:00.000000000 Z
12
+ date: 2014-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe