Closed wbw20 closed 6 years ago
I did it that way and so far, it seems to work... not too confident about this. (version 1.3.1)
const sub = await payjp.subscriptions.retrieve(subscriptionId)
const plan = await payjp.plans.create({ amount: newPlanPrice, currency: 'jpy', interval: 'month', name: sub.plan.name })
await payjp.subscriptions.update(subscriptionId, { plan: plan.id, trial_end: sub.current_period_end })
It doesn't work if the subscription is paused though.
"error": {
"code": "already_paused",
"message": "Subscription \"sub_1234567890...\" has already been paused.",
"status": 400,
"type": "client_error"
}
According to the docs, it is the way to do it. https://pay.jp/docs/api/?javascript#定期課金を更新
プランを変更する場合は、 plan に新しいプランのIDを指定してください。[...] またプランを変更するとその時点で新しいプランでの課金が実行されます。即時の課金を実行したくない場合は、トライアル期間を設定してください。
My humble translation:
When you change the plan, please specify a new ID for plan
. Then, once the plan has changed, there will be a transaction according to the new plan. If you do not wish to charge immediately, please set the trial period.
This strategy is working for me as well! Thank you for translating, I will close this issue out and it can help people in the future.
Does your API have the ability to change a user's plan starting in their next cycle? This is a great feature that Stripe has.
Perhaps there is a way to implement it using
trial_end
?