I'm having a bit of a hard time updating a subscription with a new plan. What I'm trying to do is the following:
Check if the subscription is still in trial mode. Get trial_end timestamp
If trial_end has not happened yet. Create new plan. Subscribe customer to new plan. Do not prorate anything. Carry the trial_end for the new plan. (In other words, don't charge the customer until after the trial period ends.)
If trial_end has already passed, create new plan, Sub customer to the new plan. Prorate the new plan. Carry the next billing date. (Meaning, again, don't charge the customer right now but add the prorated amount to the next invoice)
Here's the code I have so far:
//CREATE NEW PLAN
$plan = \Stripe\Plan::create(array(
"id" => $usremail.'_'.time(),
"name" => $usremail.'-'.time(),
"currency" => "usd",
"amount" => $totalamount,
"interval" => "month",
));
$planid = $plan->id;
$proration_date = time();
//UPDATE SUBSCRIPTION
$subscription = \Stripe\Subscription::retrieve($subid);
$subscription->plan = $planid;
$subscription->proration_date = $proration_date;
$subscription->save();
When I do it this way, if the customer is in a trial subscription and signs up for a new plan, the subscription becomes active and the customer is charged right away the amount of the new plan.
I'm sure it is an easy thing, just can't figure it out. Any help is greatly appreciated.
T