When recurring customers change their plans, they want to show the difference at the time of the change in advance.
I tried to customize for Laravel with reference to the following site
It was not possible due to lack of knowledge.
If i know someone
If i teach me, it will be very helpful.
There are two types of monthly payment plans: Light (1,000 yen) and Standard (5,000 yen).
If a customer who joined the Light Plan on November 1 changes to the Standard Plan on the 15th of the middle of the month
I want to automatically calculate the difference at the next billing.
* The daily bill calculation method follows the basic concept of periodic payments in Stripe Billing (see the URL below).
* Invoice issued on the first day of every month.
* I want to calculate automatically when downgrading from Standard to Light.
* Table configuration is the same as Cashier migration.
[Reference URL] Stripe Billing-Proportional distribution in recurring payments
https://qiita.com/y_toku/items/404b3c99632161f18579
[Reference URL] https://stripe.com/docs/billing/subscriptions/prorations#prorations
// 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_Ar66eiYNVgxtbd07ig6vIugp009e1S3qwk');
// Set proration date to this moment:
$proration_date = time ();
$subscription = \ Stripe \ Subscription :: retrieve ('sub_49ty4767H20z6a');
// See what the next invoice would look like with a plan switch
// and proration set:
$items = [
[
'id' =>$subscription->items->data [0]->id,
'plan' =>'plan_CBb6IXqvTLXp3f', # Switch to new plan
],
];
$invoice = \ Stripe \ Invoice :: upcoming ([
'customer' =>'cus_4fdAW5ftNQow1a',
'subscription' =>'sub_49ty4767H20z6a',
'subscription_items' =>$items,
'subscription_proration_date' =>$proration_date,
]);
// Calculate the proration cost:
$cost = 0;
$current_prorations = [];
foreach ($invoice->lines->data as $line) {
if ($line->period->start == $proration_date) {
array_push ($current_prorations, $line);
$cost + = $line->amount;
}
}
Error code
No API key provided. (HINT: set your API key using "Stripe :: setApiKey ()". You can generate API keys from the Stripe web interface.See https: // stripe .com/api for details, or email [email protected] if you have any questions.
The above code
$subscription = \ Stripe \ Subscription :: retrieve ('sub_49ty4767H20z6a');
Replaced with the following code
$subscription = $user->subscription ('main');
Trying to get property 'data' of non-object
// $subscription->items->data [0]->id is missing
Development environment
Laravel 6.0.3
laravel/cashier 9.3.5
PHP 7.3.5
xampp
windows 10
I would be happy if you could answer.
-
Answer # 1
Related articles
- automatic numbering insert cannot be done from php to postgressql
- calculation between php arrays
- php - responsive mail form does not receive automatic reply
- php - about automatic login to vba scraping sakura rental server control
- php - garbled characters in automatic reply text
- html - i want to add an automatic calculation function with js
- how to maintain login and add automatic login function in php
- php : Laravel -validation on multiple input file
- i want to display the selected radio button on the laravel php edit screen
- php - [laravel] how to read and use the class of another file in controller
- php - about the value stored in laravel db
- php - e-mail transmission with laravel is garbled
- after upgrading the php version of the rental server from 58 to 74, composer stopped working on ssh connections
- php - i can't connect to mysql in laravel js
- php - i built an environment with docker and laravel, but i get a 404 file not found
- php - about searching with laravel where clause
- php - left join doesn't do what i want
Thank you.
I will describe the cause of the error.
\ Stripe \ Stripe :: setApiKey ();
The value of the Stripe secret key in this code was incorrect.
The error code was "No API key provided"
I should have obediently obeyed.
Thank you for your advice.
Success code