#itzsky_invoiceitem-behavior
1 messages Ā· Page 1 of 1 (latest)
š Welcome to your new thread!
ā²ļø We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).
ā±ļø We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can start a new thread if you have another question.
š This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1261003153457811456
š Have more to share? Add details, code, screenshots, videos, etc. below.
Hello, this is my code, i can't manage to make it work like it's working on my other stripe dashboard, even if i am forcing an older api version i can't manage to request the 1 eur pending invoice item at checkout.
You can see i am forcing \Stripe\Stripe::setApiVersion("2018-05-21"); but even if i did this the pending invoice items are not displayed to pay at checkout.
itzsky_invoiceitem-behavior
This is the reply i got from support, but i can't manage to modify this code to make it work like it shoulds.
Hello,
This is Toby, an engineer here at Stripe, and I'm reviewing your inquiry.
I believe you're seeing different behavior for the same code due to the default API version 0 being different for the accounts you're using. Below are the accounts you referenced and their current default API versions:
acct_1OfOAWGHp99ilxw2 - 2023-10-16
acct_1POTXREi2SLTIvrD - 2024-04-10
acct_1HCpeXDG51Hcmlec - 2020-03-02
In version 2022-08-01 1, the default behavior of pending_invoice_item_behavior 2 was changed to be exclude. If you aren't explicitly setting a value for the pending_invoice_item_behavior when creating your Invoices, then the default behavior will be used. That default behavior will be different for your accounts due to one of them using an API version from before the change I mentioned, while the other two are using API versions from after that change.
If you would like to force those Invoice creation requests to run the same on all of your accounts, I would recommend explicitly setting your desired value for the pending_invoice_item_behavior parameter. But, please let me know if that still does not accomplish what you're hoping and I'd be happy to take another look!
Best regards,
-Toby
Hello! Is this a copy-paste of a ticket? If so, why not just respond to that ticket to get help from the person working with you?
Also your code is over 1k lines long so I definitely won't read it. Can you share the exact relevant bit of code so I can help you?
Hello, i tried to reply to the ticket also
The problem is that i am trying to request a 1⬠invoice for trial subscription but this invoice is not beeing displayed at checkout like it is on my other dashboard
because seems like after an api update by your side i should include this pending_invoice_item_behavior parameter in my code.
As i'm forcing version Stripe\Stripe::setApiVersion("2018-05-21"); and your change was made on version 2022-08-01 , i can't understand why it's still not working.
Yeah I think there's a real misunderstanding here both on your part and the person helping you. The pending_invoice_items behaviour should be unrelated to Checkout entirely. This is only about creating an Invoice in the API
Let's take a couple of steps back.
My understanding is that you want to use Checkout to start a Subscription with a trial period. And you want to charge an extra 1⬠for that trial period.
You were using a trick where you create a Customer, then you create a pending InvoiceItem on it, then you create the Checkout Session which pulls in the pending InvoiceItem automatically but it's not working on some accounts
Is that a fair understanding?
Exactly
It's working perfectly on my old stripe dashboard but not on the new ones
Okay so this has nothing to do with the API version which is why it's not working. We (Stripe) have changed the behaviour of Checkout for new accounts recently because pulling in the pending InvoiceItems was really problematic/confusing for so many people and it was never really intended.
Unfortunately you have no way to control this yourself, it's kind of a setting we put in on "old accounts" to keep the status quo and you likely have that setting on one account and not the other ones
There's a simple solution though! Do not do what you are doing at all. All you need to do is changing your Checkout Session creation call to explicitly pass a one-time Price for the extra 1⬠so that it's charged as part of the trial
How can i do that? because the behiavour should be like this:
- User goes to checkout to test a trial version of our product
- We require him to pay 1⬠for having 2 days of trial
- after this 2 days of trial are over if the users does not cancel his subscription he will be charged for the monthly package price
It should look like this.
When you create the Checkout Session you pass line_items: [....] as a list of Price(s) and right now you likely only pass your Subscription's Price.
Change that code to pass two Prices instead (one for the Subscription and one one-off Price for the 1⬠fee).
Could you please make me an example of a correct code?
Can you share your current code for creating that Checkout Session (not the 1k lines of code)
This one? / create checkout session ....
try {
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'name' => "Order #" . $this->Order->id,
'description' => "Payment for Order #" . $this->Order->id,
'amount' => (float)$total,
'currency' => strtolower($this->Order->currency),
'quantity' => 1,
]],
'success_url' => base_url('payment/success'),
'cancel_url' => base_url('payment/cancel'),
'subscription_data' => [
//'transfer_data' => [
// 'destination' => $this->config->item('fee_collector_SG'),
// 'amount_percent' => $this->config->item('fee_percent_SG')
//],
],
// 'payment_intent_data' => [
// 'application_fee_amount' => 1, // optional
// 'transfer_data' => [
// 'destination' => $this->config->item('fee_collector_SG'),
// ],
// ],
'metadata' => [
'user_id' => $this->User->id,
'order_id' => $this->Order->id,
'mode' => 'np',
'trial' => $trial,
],
'consent_collection' => ['terms_of_service' => 'required'],
'custom_text' => [
'terms_of_service_acceptance' => [
'message' => 'I agree to the Terms of Service',
],
],
]);
Hi š
I'm stepping in as my colleague needs to go
Hello
@robust thicket Just one last question: can you share an exact Checkout Session id where the old behaviour works fine? I want to look into it further internally and I'm struggling to find a concrete example on those accounts
Sure
pi_3PYYGrKNpTcKcZna0wJmxeXI
This is a payment for 1⬠of trial on the old dashboard
checkout.session ā cs_live_a1J4ORkeEpYz0Dj0NqdkbuDO8jOFGTioZocuXUC5zZLeKoWO0J2Z9VmSrE
perfect I confirmed it was the issue I said
so once you change your code you're all set
There is no way to request to change my new accounts with the older pending invoice items behiavour?
Because i am not an experienced developer and i will need to struggle a lot to redo all my code
I hope @slate moat can help me to change it at least..
I don't think your code is what controls the integration. It's not doing a Subscription so it's the wrong bit of code
I have 3 checkout codes in this file
Maybe is this?
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [
[
'price' => $plan_id2,
'description' => "Payment for Order #" . $this->Order->id,
'quantity' => 1,
]
],
'customer' => $customer_id,
'subscription_data' => $subscription_data,
'metadata' => [
'user_id' => $this->User->id,
'order_id' => $this->Order->id,
'mode' => 'np',
'trial' => $trial,
],
'success_url' => base_url('payment/success'),
'cancel_url' => base_url('payment/cancel'),
'mode' => 'subscription',
'consent_collection' => ['terms_of_service' => 'required'],
'custom_text' => [
'terms_of_service_acceptance' => [
'message' => 'I agree to the Terms of Service',
],
],
]);
} else {
//
$subscription_data = [
"metadata" => [
"order_id" => $this->Order->id,
"user_id" => $this->User->id
],
//'transfer_data' => [
// 'destination' => $this->config->item('fee_collector_SG'),
// 'amount_percent' => $this->config->item('fee_percent_SG')
//],
];
yes that, so you want to change that to add a second Price to that line_items
- Create a new Product/Price for the 1⬠extra set up fee for each Stripe account
- Change
line_itemsto use that Price
Could you please make me an example of how that code shoud looks?
I need to create a "Trial Fee" product on the new stripe dashboards?
I created on stripe dashboard prod_QSLi4OuNEVDNu0
I need to create a "Trial Fee" product on the new stripe dashboards?
Yes, you need to use the Price ID associated with that product and add a second line item. That could look like this:
'line_items' => [
[
'price' => $plan_id2,
'description' => "Payment for Order #" . $this->Order->id,
'quantity' => 1,
],
[
'price' => $trial_price, // The price associated with your Trial Fee product
'description' => "Trial Fee"
'quantity' => 1,
],
],
Ok, and after i make this modification i need to remove the code where i was creating the 1⬠trial invoice before?
price_1PbR0gB4bznwKBcEFwbuPykp should be the price ID
Correct
So i need to rebuild the whole structure of the code basically
Okay, i will try my best to do that
It's a few small changes but yes, this would move the creation of the trial fee to make it part of the Checkout creation
Okay i will try to help myself with openAI since unfortunately i'm not really a developer
Thanks for clarifying.
it should look like: 'price' => price_1PbR0gB4bznwKBcEFwbuPykp, ?
Close. 'price' => "price_1PbR0gB4bznwKBcEFwbuPykp",
The quotes are important here
Okay, thanks a lot