#sergx_docs
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always 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/1220721856907186186
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
I have read the documentation, but I am not sure how to pass the shipping rate to the checkout session, because in the documentation I see it adds the info in shipping_options. But actually, I have created that info in shipping rates in Stripe Dashboard
How can I pass shipping rate ID to checkout Session?*
You can pass the id here instead: https://docs.stripe.com/api/checkout/sessions/create#create_checkout_session-shipping_options-shipping_rate
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
shipping_rate_data is for passing the info inline
But if you already have created a shipping rate, you just need to pass its ID above
Can you share the code
array (size=13)
'line_items' =>
array (size=1)
0 =>
array (size=2)
'price' => string 'price_XXX' (length=30)
'quantity' => string '1' (length=1)
'client_reference_id' => int 224
'billing_address_collection' => string 'required' (length=8)
'allow_promotion_codes' => boolean false
'locale' => string 'es' (length=2)
'automatic_tax' =>
array (size=1)
'enabled' => boolean true
'tax_id_collection' =>
array (size=1)
'enabled' => boolean true
'success_url' => string 'http://localhost:8000' (length=71)
'cancel_url' => string 'http://localhost:8000/' (length=51)
'invoice_creation' =>
array (size=1)
'enabled' => boolean true
'custom_fields' =>
array (size=1)
0 =>
array (size=4)
'key' => string 'business' (length=8)
'label' =>
array (size=2)
...
'type' => string 'text' (length=4)
'optional' => boolean false
'mode' => string 'payment' (length=7)
'shipping_options' =>
array (size=1)
'shipping_rate' => string 'shr_XXX' (length=28)
yes of course!
That's the code? What language is that?
That's the response, wait I send you the code, sorry.
$data = [
'line_items' => [
[
'price' => $priceId,
'quantity' => $request->quantity,
],
],
'client_reference_id' => $user->id,
'billing_address_collection' => 'required',
'allow_promotion_codes' => false,
'locale' => 'es',
'automatic_tax' => [
'enabled' => true,
],
'tax_id_collection' => [
'enabled' => true,
],
'success_url' => route('XX', ['purchase' => 'successful']),
'cancel_url' => route('XX'),
'invoice_creation' => [
'enabled' => true,
],
'custom_fields' => [
[
'key' => 'business',
'label' => [
'type' => 'custom',
'custom' => 'Indica el negocio',
],
'type' => 'text',
'optional' => false,
],
],
'mode' => 'payment',
];
if ($request->quantity == 1) {
$data['shipping_options'] = $this->handleShipping(config('app.shipping_rate'));
}
return var_dump($data);
return $request->user()->checkout([$priceId], $data);
private function handleShipping($shippingRateId)
{
return ['shipping_rate' => $shippingRateId];
}
PHP
Shipping options needs to be an array of associative arrays: https://docs.stripe.com/api/checkout/sessions/create?lang=php#create_checkout_session-shipping_options. Right now it looks like you just have it as an associative array
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
So needs to follow the same format as line_items, for example
Where it's wrapped in an array
Works fine! Thank you very much