[BUG] Subscription enters a broken state if the user decide not to make the payment #1135
-
Bug ReportNot sure if this is a skill issue on my side or a real problem but I found this problem: when the user goes to the Stripe payment page for example and then decides not to do anything about it, the old subscription is gone and the new one gets a customer without a subscription. To Reproduce:
New Customer is created
Now, if they simply click Back or close the page, they don't have any subscription. Here is my question: is this expected behavior and maybe I should code defensively around it or is this a bug? Expected Behavior:
Additional Context: Possible Fix: Checklist:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
You say the fake subscription is expired? What methods are you calling to check for a subscription? You'll have to provide some more specifics of what you're doing step-by-step. |
Beta Was this translation helpful? Give feedback.
-
yes
let me try to provide some details here: When a user signs up on my app, I give them 14 days trial def subscribe_to_trial
set_payment_processor :fake_processor, allow_fake: true
trial_period_ends_at = Subscription::TRIAL_PERIOD_DAYS.from_now
payment_processor.subscribe(trial_ends_at: trial_period_ends_at, ends_at: trial_period_ends_at)
end When the trial expires, the user can see the subscription button, that does this: def create
Current.user.set_payment_processor :stripe
session = Current.user.payment_processor.checkout(
line_items: [{ price: Subscription::PRICE_ID, quantity: 1 }],
mode: Subscription::MODE,
subscription_data: {
metadata: {
pay_name: Subscription::NAME,
},
},
success_url: Rails.application.routes.url_helpers.subscriptions_url,
cancel_url: Rails.application.routes.url_helpers.subscriptions_url
)
redirect_to session.url, allow_other_host: true
end at this point, the things I mentioned above happen: current Pay::Customer is no longer I have a wrapper around the subscription itself and for now I managed to solve it by creating the |
Beta Was this translation helpful? Give feedback.
Stripe allows you to give users a free trial without a payment method, so you could simplify this considerably using just Stripe and not the fake processor.
When you call
Current.user.set_payment_processor :stripe
that will make Stripe the default.The fake processor subscription still exists regardless of the default payment processor. You just have to make sure you aren't scoping the query to the current payment processor.
Current.user.subscriptions
here usesthrough: :pay_customers
to do that. https://github.com/pay-rails/pay/blob/main/lib/pay/attributes.rb#L17