我正在嘗試透過 Stripe 結帳會話傳遞元資料。目前,我正在嘗試按照 Stripe 文件中的建議透過 payment_intent_data.metadata 傳遞它,但我收到 500 個錯誤異常 : “Stripe\Exception\InvalidRequestException”,訊息 : 「無效物件」。但我似乎遵循了 Stripe 文件上的建議配置,所以我陷入了停滯。
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; }
如果我不加
'payment_intent_data' => [ ## Here, I am just putting "AAA" for testing 'metadata' => "AAA" ],
然後就可以了。但我想透過結帳流程傳遞元資料並在 payment_intent.succeeded 上獲取它。
想法?