Skip to content

Commit

Permalink
Merge pull request #685 from stripe-ruby-mock/add-pending-invoice-ite…
Browse files Browse the repository at this point in the history
…m-interval

Adds support for pending_invoice_item_interval
  • Loading branch information
joshcass committed Jan 7, 2020
2 parents 976f5dd + 35e3cc5 commit 9e343a5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/stripe_mock/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,9 @@ def self.mock_subscription(params={})
tax_percent: nil,
discount: nil,
metadata: {},
default_tax_rates: nil
default_tax_rates: nil,
pending_invoice_item_interval: nil,
next_pending_invoice_item_invoice: nil
}, params)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def custom_subscription_params(plans, cus, options = {})
start_time = options[:current_period_start] || now
params = { customer: cus[:id], current_period_start: start_time, created: created_time }
params.merge!({ :plan => (plans.size == 1 ? plans.first : nil) })
keys_to_merge = /application_fee_percent|quantity|metadata|tax_percent|billing|days_until_due|default_tax_rates/
keys_to_merge = /application_fee_percent|quantity|metadata|tax_percent|billing|days_until_due|default_tax_rates|pending_invoice_item_interval/
params.merge! options.select {|k,v| k =~ keys_to_merge}

if options[:cancel_at_period_end] == true
Expand Down
2 changes: 1 addition & 1 deletion lib/stripe_mock/request_handlers/subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def create_subscription(route, method_url, params, headers)
customer[:default_source] = new_card[:id]
end

allowed_params = %w(customer application_fee_percent coupon items metadata plan quantity source tax_percent trial_end trial_period_days current_period_start created prorate billing_cycle_anchor billing days_until_due idempotency_key enable_incomplete_payments cancel_at_period_end default_tax_rates payment_behavior)
allowed_params = %w(customer application_fee_percent coupon items metadata plan quantity source tax_percent trial_end trial_period_days current_period_start created prorate billing_cycle_anchor billing days_until_due idempotency_key enable_incomplete_payments cancel_at_period_end default_tax_rates payment_behavior pending_invoice_item_interval)
unknown_params = params.keys - allowed_params.map(&:to_sym)
if unknown_params.length > 0
raise Stripe::InvalidRequestError.new("Received unknown parameter: #{unknown_params.join}", unknown_params.first.to_s, http_status: 400)
Expand Down
34 changes: 34 additions & 0 deletions spec/shared_stripe_examples/subscription_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,20 @@
expect(subscription.tax_percent).to eq(20)
end

it "correctly sets pending invoice item interval" do
customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk)

subscription = Stripe::Subscription.create({
plan: plan.id,
customer: customer.id,
quantity: 2,
pending_invoice_item_interval: { interval: 'month', interval_count: 1 }
})

expect(subscription.pending_invoice_item_interval.interval).to eq 'month'
expect(subscription.pending_invoice_item_interval.interval_count).to eq 1
end

it "correctly sets created when it's not provided as a parameter", live: true do
customer = Stripe::Customer.create(source: gen_card_tk)
subscription = Stripe::Subscription.create({ plan: plan.id, customer: customer.id })
Expand Down Expand Up @@ -720,6 +734,26 @@
expect(sub.canceled_at).to be_falsey
end

it "updates a subscription's pending invoice item interval" do
customer = Stripe::Customer.create(id: 'test_customer_sub', source: gen_card_tk)

subscription = Stripe::Subscription.create({
plan: plan.id,
customer: customer.id,
quantity: 2,
pending_invoice_item_interval: { interval: 'month', interval_count: 1 }
})

expect(subscription.pending_invoice_item_interval.interval).to eq 'month'
expect(subscription.pending_invoice_item_interval.interval_count).to eq 1

subscription.pending_invoice_item_interval = { interval: 'week', interval_count: 3 }
subscription.save

expect(subscription.pending_invoice_item_interval.interval).to eq 'week'
expect(subscription.pending_invoice_item_interval.interval_count).to eq 3
end

it 'when adds coupon', live: true do
coupon = stripe_helper.create_coupon
customer = Stripe::Customer.create(source: gen_card_tk, plan: plan.id)
Expand Down

0 comments on commit 9e343a5

Please sign in to comment.