问题
I have integrated Stripe checkout (the latest version) and need to send additional data so I can reconcile a later webhook.
Stripe rejects the metadata with the following error
Fatal error: Uncaught exception 'Stripe\Error\InvalidRequest' with message 'Received unknown parameter: metadata'
My partially redacted code looks like this
$object = \Stripe\Checkout\Session::create([
'success_url' => 'www/payment_processor.php?action=success',
'cancel_url' => 'www/payment_processor.php?action=cancel',
'payment_method_types' => ['card'],
'customer_email' => $email,
'metadata' => ['user_id' => $user_id],
'line_items' => [[
'amount' => $amount,
'currency' => $currency,
'name' => 'Purchase',
'description' => $description,
'quantity' => 1,
]]
]);
I expect the metadata to be accepted and returned with the webhook, as described in the Stripe documentation.
回答1:
First sentence of the linked documentation states:
Updateable Stripe objects—including Account, Charge, Customer, PaymentIntent, Refund, Subscription, and Transfer —have a metadata parameter.
You are creating neither of those, you are creating a Session
回答2:
The Stripe Session object does not accept metadata
as a parameter. See here for the details.
The reference you give in your question is for a Stripe Charge object which does accept metadata.
回答3:
The other answers are correct that metadata
doesn't exist on the Session object. client_reference_id
is an alternative but it has to be unique and it must be a string.
If you just want metadata to show up on the purchase in the Stripe Dashboard, use the payment_intent_data
attribute when creating your session. That's how you attach metadata to a purchase made during a session. Relevant documentation here.
回答4:
You cannot attach metadata to a Session
, but you can attach metadata to either the payment_intent
or setup_intent
that will be created in the session.
See the documentation, you pass it as payment_intent_data.metadata
.
Note that Stripe warns you not to put sensitive data in metadata
, so if you want to store a client name etc, you're better off putting it in a database under a unique key and then pass the key as client_reference_id
.
来源:https://stackoverflow.com/questions/55744094/stripe-checkout-wont-accept-metadata