search

Home  >  Q&A  >  body text

Metadata about Stripe payment intent data

I'm trying to pass metadata through a Stripe checkout session. Currently I'm trying to pass it via payment_intent_data.metadata as suggested in the Stripe documentation, but I'm getting a 500 Error exception : "Stripe\Exception\InvalidRequestException", message : "Invalid object". But I seem to be following the recommended configuration on the Stripe documentation, so I'm stuck.

StripeController.php

    public function handle_checkout(Request $request)
    {
        $stripe = new \Stripe\StripeClient(env("STRIPE_PRIVATE_KEY"));

        $req_content = json_decode($request->getContent(), true);

        $line_items = []; 

        $email = "";

        foreach($req_content as $key => $val) {
            $new_line_item = [
                'price_data' => [
                'currency' => 'usd',
                'product_data' => [
                    'name' => $val["product_item"]["name"],
                ],
                'unit_amount' => $val["product_item"]["price"] * 100,
                ],
                'quantity' => $val["cart_item"]["quantity"]
            ];
            
            $email = $val["user_email"];

            array_push($line_items, $new_line_item);
        }

        $checkout_session = $stripe->checkout->sessions->create([
            'shipping_address_collection' => ['allowed_countries' => ['US']],
            'payment_method_types' => ['card'],
            "customer_email" => $email,
            'line_items' => $line_items,
            'payment_intent_data' => [ 
                 ## Here, I am just putting "AAA" for testing
                'metadata' => "AAA"
            ],
            'mode' => 'payment',
            'success_url' => 'my success url ...',
            'cancel_url' => 'my cancel url...',
          ]);
     
        return $checkout_session->url; 
    }

If I don't add

'payment_intent_data' => [ 
                 ## Here, I am just putting "AAA" for testing
                'metadata' => "AAA"
            ], 

Then that’s it. But I want to pass the metadata through the checkout process and get it on payment_intent.succeeded.

idea?

P粉928591383P粉928591383244 days ago434

reply all(1)I'll reply

  • P粉115840076

    P粉1158400762024-03-31 12:01:32

    'payment_intent_data' => [ 
                   'metadata' => [ 
                            "AAA" => "BBB"
                   ]
            ],

    reply
    0
  • Cancelreply