我正在尝试通过 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 上获取它。
想法?
雷雷