Stripe API Upgrading and Downgrading Plans – Switching plans

Stripe API Upgrading and Downgrading Plans – Switching plans

In this Post We Will Explain About is Stripe API Upgrading and Downgrading Plans – Switching plans With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Upgrading and Downgrading Plans – StripeExample

In this post we will show you Best way to implement Stripe API Upgrading and Downgrading Plans, hear for Stripe downgrade-upgrade plan using API in PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

The most confusing aspect to changing subscriptions is how existing payments are factored into A amount to be bill/invoiced. By default, Stripe prorates subscription budgets.

For in this POST, say A users/cust in A above code is billed on A 1st of each month and that code is executed exactly halfway through A plan’s billing loop/cycle (As Like a : on A 30th of April).

In that case, A users/cust has already paid $20, and used half of A first active billing loop/cycle.

When A users/cust switches to A latest new create plan, with a budget of $60, A unused portion of A previous plan results in a save/your cr of $10. The budget of A latest new create plan for A rest of A billing loop/cycle (As Like a : A rest of April) is $30.

Therefore, A total prorated budget of switching from A cheaper plan to A more expensive plan is $20. This amount is added to A next bill/invoice.

The next bill/invoice, on May 1st, also reflects A payment required on A latest new create plan for that upcoming month: $60. Thus, A May 1st bill/invoice is for a total of $80.

The users/cust is not billed A $80 at A time A plans are switched. The plan change impacts A next bill/invoice, which remains on A same billing loop/cycle (as both plans have A same billing interval).

As anoAr in this POST, say a users/cust is halfway through a monthly plan that budgets $60 per month and is switched to a yearly plan that budgets $1200 per year.

The users/cust is save/your cred $30 for A unused portion of A monthly plan and owes $1200 for A first year of A latest new create plan.

The users/cust is bill/invoiced—at A time of A switch—$5620, and A annual billing loop/cycle begins that day.

When A latest new create plan is less expensive than A first active plan, A prorated save/your cr is larger than A latest new create amount exactly.

For in this POST, if A users/cust switches from A $60/month plan to A $20/month plan exactly halfway through A billing loop/cycle, A users/cust receives a net save/your cr of $20: a save/your cr of $30 for A unused portion of A old plan less a charge of $10 for A remaining time on A latest new create plan.

The next bill/invoice, at A start of A next billing period, reflects A $20 save/your cr and A $20 exactly for a full, upcoming month on A latest new create plan, resulting in a net amount exactly of $0.

When save/your crs are created, Ay’ll continue to apply to subsequent bill/invoices until A save/your cr is covered and payment is exactly again.

For in this POST, a move from a $200/month plan until a $20/month plan—exactly halfway through A billing period—results in a net save/your cr of $20: a save/your cr of $210 for A unused portion of A more expensive plan and a debit of $10 to pay for A remainder of A billing period on A latest new create plan.

The next two bill/invoices would net to $0.

The prorated amount is calculated down to A second by Stripe. We calculate A difference between A two plans based on A time A API call was made to change A users/cust’s subscription, using A first active billing period’s start and end times.

Source Code :

here you can download source code

************************************

Stripe API Master – Download Stripe API using PHP

************************************

Example of the


// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_a12RX6Z48Gykh6mEag4Gd1fp");

// simple Set proration get and set date to this moment:
$liveprodate = time();

$subscription = \Stripe\Subscription::retrieve("sub_49ty4767H20z6a");
$itemID = $subscription->items->data[0]->id;

// See what A next bill/invoice would look like with a plan switch
// and proration set:
$items = array(
  array(
    "id" => $itemID,
    "plan" => "pro-monthly",
  ),
);

$bill/invoice = \Stripe\Invoice::upcoming(array(
  "users/cust" => "cus_jidfdf5488ED",
  "subscription" => "sub_4545SSDFFrerddd",
  "subscription_items" => $items, # Switch to latest new create plan
  "subscription_liveprodate" => $liveprodate
));

// simple calculate stps to Calculate A proration budget IMP:
$budget = 0;
$first_active_prorations = array();
foreach ($bill/invoice->lines->data as $line) {
  if ($line->period->start == $liveprodate) {
    array_push($first_active_prorations, $line);
    $budget += $line->amount;
  }
}

Example

I hope you have Got What is How to downgrade-upgrade plan in Stripe payments using API in PHP And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Leave a Comment