Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
knowmalaria
stripe-ruby-mock
Commits
df299f0f
Commit
df299f0f
authored
Feb 18, 2016
by
Alexander Mamonchik
Browse files
Merge pull request #307 from slash7/add_customer_currency
Added `currency` attribute to customer
parents
92bedc9b
5835a4d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
lib/stripe_mock/data.rb
View file @
df299f0f
...
...
@@ -32,6 +32,7 @@ module StripeMock
delinquent:
false
,
discount:
nil
,
account_balance:
0
,
currency:
nil
,
sources:
{
object:
"list"
,
total_count:
sources
.
size
,
...
...
lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb
View file @
df299f0f
...
...
@@ -28,6 +28,11 @@ module StripeMock
def
add_subscription_to_customer
(
cus
,
sub
)
id
=
new_id
(
'ch'
)
charges
[
id
]
=
Data
.
mock_charge
(
:id
=>
id
,
:customer
=>
cus
[
:id
],
:amount
=>
sub
[
:plan
][
:amount
])
if
cus
[
:currency
].
nil?
cus
[
:currency
]
=
sub
[
:plan
][
:currency
]
elsif
cus
[
:currency
]
!=
sub
[
:plan
][
:currency
]
raise
Stripe
::
InvalidRequestError
.
new
(
"Can't combine currencies on a single customer. This customer has had a subscription, coupon, or invoice item with currency
#{
cus
[
:currency
]
}
"
,
'currency'
,
400
)
end
cus
[
:subscriptions
][
:total_count
]
=
(
cus
[
:subscriptions
][
:total_count
]
||
0
)
+
1
cus
[
:subscriptions
][
:data
].
unshift
sub
end
...
...
spec/shared_stripe_examples/subscription_examples.rb
View file @
df299f0f
...
...
@@ -8,7 +8,7 @@ shared_examples 'Customer Subscriptions' do
context
"creating a new subscription"
do
it
"adds a new subscription to customer with none"
,
:live
=>
true
do
plan
=
stripe_helper
.
create_plan
(
id:
'silver'
,
name:
'Silver Plan'
,
amount:
4999
)
plan
=
stripe_helper
.
create_plan
(
id:
'silver'
,
name:
'Silver Plan'
,
amount:
4999
,
currency:
'usd'
)
customer
=
Stripe
::
Customer
.
create
(
source:
gen_card_tk
)
expect
(
customer
.
subscriptions
.
data
).
to
be_empty
...
...
@@ -26,15 +26,15 @@ shared_examples 'Customer Subscriptions' do
expect
(
customer
.
subscriptions
.
count
).
to
eq
(
1
)
expect
(
customer
.
subscriptions
.
data
.
length
).
to
eq
(
1
)
expect
(
customer
.
charges
.
data
.
length
).
to
eq
(
1
)
expect
(
customer
.
currency
).
to
eq
(
"usd"
)
expect
(
customer
.
subscriptions
.
data
.
first
.
id
).
to
eq
(
sub
.
id
)
expect
(
customer
.
subscriptions
.
data
.
first
.
plan
.
to_hash
).
to
eq
(
plan
.
to_hash
)
expect
(
customer
.
subscriptions
.
data
.
first
.
customer
).
to
eq
(
customer
.
id
)
expect
(
customer
.
subscriptions
.
data
.
first
.
metadata
.
foo
).
to
eq
(
"bar"
)
expect
(
customer
.
subscriptions
.
data
.
first
.
metadata
.
example
).
to
eq
(
"yes"
)
end
it
'creates a charge for the customer'
,
live:
true
do
stripe_helper
.
create_plan
(
id:
'silver'
,
name:
'Silver Plan'
,
amount:
4999
)
...
...
@@ -155,6 +155,19 @@ shared_examples 'Customer Subscriptions' do
expect
(
customer
.
subscriptions
.
count
).
to
eq
(
0
)
end
it
"throws an error when subscribing the customer to a second plan in a different currency"
do
usd_plan
=
stripe_helper
.
create_plan
(
id:
'enterprise_usd'
,
amount:
499
,
currency:
'usd'
)
customer
=
Stripe
::
Customer
.
create
(
id:
'test_customer_sub'
,
source:
gen_card_tk
)
usd_subscription
=
customer
.
subscriptions
.
create
({
:plan
=>
'enterprise_usd'
})
eur_plan
=
stripe_helper
.
create_plan
(
id:
'enterprise_eur'
,
amount:
499
,
currency:
'eur'
)
expect
{
customer
.
subscriptions
.
create
({
:plan
=>
'enterprise_eur'
})
}.
to
raise_error
{
|
e
|
expect
(
e
).
to
be_a
Stripe
::
InvalidRequestError
expect
(
e
.
http_status
).
to
eq
(
400
)
expect
(
e
.
message
).
to_not
be_nil
}
end
it
"subscribes a customer with no card to a plan with a free trial"
do
plan
=
stripe_helper
.
create_plan
(
id:
'trial'
,
amount:
999
,
trial_period_days:
14
)
customer
=
Stripe
::
Customer
.
create
(
id:
'cardless'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment