#itzskyline.
1 messages ยท Page 1 of 1 (latest)
Hi there ๐ sorry to hear that, can you provide more context about the errors you're encountering?
invalid_request_error
You cannot use line_items.amount, line_items.currency, line_items.name, line_items.description, or line_items.images in this API version. Please use line_items.price or line_items.price_data. Please see https://stripe.com/docs/payments/checkout/migrating-prices for more information.
I asked support to downgrade my webhook api to 2020 but as i have a new stripe dashboard they are unable to do so
but new api completely broke my code.. how can i send events to the new webhook without generating errors? Old webhook version was 2020-03-02
This is my code; // 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('sgpayment/success' . "?application=socialgrow"),
'cancel_url' => base_url('sgpayment/cancel' . "?application=socialgrow"),
'metadata' => [
'user_id' => $this->User->id,
'order_id' => $this->Order->id,
'mode' => 'sg'
]
]);
Alright, we're gonna need to take this step by step, because it seems like you just jumped through at least two distinct concerns pretty quickly.
So let's start by focusing on making sure you can make requests, then we can circle back to the concern about webhooks and Events.
Ok
The error message is correct, you cannot provide those child values to line_items now. You will instead need to leverage the price_data hash:
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data
price_data has currency and unit_amount parameters directly nested inside of it, where you can pass your amount and currency values.
quantity will continue to be passed directly under line_items.
Your name and description values will likely go into price_data.product_data
https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-line_items-price_data-product_data
Ok so how this code shoul look like?
// Create a Checkout Session
try {
$session = \Stripe\Checkout\Session::create([
'payment_method_types' => ['card'],
'line_items' => [[
'price_data' => [
'currency' => strtolower($this->Order->currency),
'unit_amount' => (float)$total * 100, // Stripe requires amounts in cents
],
'quantity' => 1,
'product_data' => [
'name' => "Order #" . $this->Order->id,
'description' => "Payment for Order #" . $this->Order->id,
],
]],
'success_url' => base_url('sgpayment/success' . "?application=socialgrow"),
'cancel_url' => base_url('sgpayment/cancel' . "?application=socialgrow"),
'metadata' => [
'user_id' => $this->User->id,
'order_id' => $this->Order->id,
'mode' => 'sg'
]
]);
This would work?
Yeah, looks right. Did you still encounter an error when running that?
I'm testing it now
Oh, actually, I think you're still missing a required parameter.
The mode one that tells the Checkout Session how it should operate.
Seems like this is a one-time payment, so that would be set to payment.
ok
i'm not able to make it work ๐ฆ
Support team on email told me this: As I have checked, unfortunately, we won't be able to downgrade your API version at this point. That said, you can always selectively try out different versions of the Stripe API by using the Stripe-Version header on your API requests. All of our official API libraries have support for this, which you can read about here:
https://stripe.com/docs/api#versioning
Also, Stripe has recently implemented a feature whereby you can specify a Stripe API version when creating a webhook endpoint so that events sent to this endpoint will be generated with the specified Stripe Version instead of your account's default Stripe Version. You can see how to do this here:
https://stripe.com/docs/api/webhook_endpoints/create#create_webhook_endpoint-api_version
Is not possible to force this request with the old api version?
otherwise i will have to review all my code, it will be a pain
You can force the requests to be in an older version, and the link you shared should have instructions for doing so, unless you're using one of our strongly typed libraries (Java, Go, .NET).
Did you encounter an error when you tried to follow the guide for using an API version other than the default one for your account?
I don't really know how to do it
I'm not an expert developer unfortunately
Could you tell me what i need to add in this code to force the api version? // 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('sgpayment/success' . "?application=socialgrow"),
'cancel_url' => base_url('sgpayment/cancel' . "?application=socialgrow"),
'metadata' => [
'user_id' => $this->User->id,
'order_id' => $this->Order->id,
'mode' => 'sg'
]
]);
If you're not familiar with updating your code, then you may want to bring in a developer who is comfortable doing so. Maintaining your code and making adjustments to it is part of building your own Stripe integration.
(This information is in the API reference you linked to, but copying it here for convenience)
If you want to set the API version on a per-request basis, you'll need to include an extra array in your request with the stripe_version parameter:
['stripe_version' => '2023-08-16']
If you want to set the API version globally, so it applies to all requests made by that instance of Stripe, then you need to provide stripe_version when initializing Stripe:
"api_key" => "sk_test_123",
"stripe_version" => "2023-08-16"
]);```
Ok, i will test it
Unfortunately is not working, i'm still not able to go to checkout
In general, when you hit a problem, we're going to need context about the problem. When you say you can't go to checkout, what does that mean? Is your request to create a Checkout Session failing, and if so, what is the error message you're seeing? Or are you able to create the session successfully but are encountering an error when trying to navigate to it?