#sergx_docs

1 messages ¡ Page 1 of 1 (latest)

arctic ginkgoBOT
#

👋 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.

keen topazBOT
misty parcel
#

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?*

icy girder
#

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

misty parcel
#

Thank you, I am trying it!

#

I am getting an error: Invalid array

icy girder
#

Can you share the code

misty parcel
#
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!

icy girder
#

That's the code? What language is that?

misty parcel
#

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

icy girder
#

So needs to follow the same format as line_items, for example

#

Where it's wrapped in an array

misty parcel
#

Works fine! Thank you very much