Stripe checkout wont accept metadata

江枫思渺然 提交于 2019-12-23 20:18:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!