Commit df299f0f authored by Alexander Mamonchik's avatar Alexander Mamonchik
Browse files

Merge pull request #307 from slash7/add_customer_currency

Added `currency` attribute to customer
parents 92bedc9b 5835a4d6
......@@ -32,6 +32,7 @@ module StripeMock
delinquent: false,
discount: nil,
account_balance: 0,
currency: nil,
sources: {
object: "list",
total_count: sources.size,
......@@ -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 "Can't combine currencies on a single customer. This customer has had a subscription, coupon, or invoice item with currency #{cus[:currency]}", 'currency', 400)
cus[:subscriptions][:total_count] = (cus[:subscriptions][:total_count] || 0) + 1
cus[:subscriptions][:data].unshift sub
......@@ -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( be_empty
......@@ -26,15 +26,15 @@ shared_examples 'Customer Subscriptions' do
expect(customer.subscriptions.count).to eq(1)
expect( eq(1)
expect( eq(1)
expect(customer.currency).to eq( "usd" )
expect( eq(
expect( eq(plan.to_hash)
expect( eq(
expect( eq( "bar" )
expect( eq( "yes" )
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)
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
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')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment