Skip to content

Commit 4fae19d

Browse files
authored
Merge pull request stripe-ruby-mock#800 from fabianoarruda/master
Fixes billing_cycle_anchor attribute on Subscription to accept `now` as value
2 parents 73430a8 + be37bc1 commit 4fae19d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/stripe_mock/request_handlers/subscriptions.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def create_subscription(route, method_url, params, headers)
9797
customer[:default_source] = new_card[:id]
9898
end
9999

100-
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 default_payment_method collection_method off_session trial_from_plan expand transfer_data)
100+
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 default_payment_method collection_method off_session trial_from_plan proration_behavior backdate_start_date transfer_data expand)
101101
unknown_params = params.keys - allowed_params.map(&:to_sym)
102102
if unknown_params.length > 0
103103
raise Stripe::InvalidRequestError.new("Received unknown parameter: #{unknown_params.join}", unknown_params.first.to_s, http_status: 400)
@@ -196,6 +196,10 @@ def update_subscription(route, method_url, params, headers)
196196
stripe_account = headers && headers[:stripe_account] || Stripe.api_key
197197
route =~ method_url
198198

199+
if params[:billing_cycle_anchor] == 'now'
200+
params[:billing_cycle_anchor] = Time.now.utc.to_i
201+
end
202+
199203
subscription_id = $2 ? $2 : $1
200204
subscription = assert_existence :subscription, subscription_id, subscriptions[subscription_id]
201205
verify_active_status(subscription)

spec/shared_stripe_examples/subscription_examples.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,18 @@
11191119
expect(e.message).to eq("Invalid timestamp: must be an integer")
11201120
}
11211121
end
1122+
1123+
it "converts billing_cycle_anchor=now to a timestamp" do
1124+
customer = Stripe::Customer.create(id: 'test_billing_anchor', plan: plan.id, source: gen_card_tk)
1125+
1126+
sub = Stripe::Subscription.retrieve(customer.subscriptions.data.first.id)
1127+
sub.billing_cycle_anchor = 'now'
1128+
sub.save
1129+
1130+
expect(sub.billing_cycle_anchor).to be_a(Integer)
1131+
end
1132+
1133+
11221134
end
11231135

11241136
context "cancelling a subscription" do

0 commit comments

Comments
 (0)