Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stripe checkout wont accept metadata

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.

like image 824
seventeen Avatar asked Apr 18 '19 10:04

seventeen


People also ask

What Does Metadata mean in Stripe?

Metadata is useful for storing additional, structured information on an object. As an example, you could store your user's full name and corresponding unique identifier from your system on a Stripe Customer object.

Is Stripe Checkout deprecated?

Stripe will not be updating the Stripe Checkout modal to comply with Strong Customer Authentication (SCA) and as a result they no longer recommend using that integration.

How do I customize my Checkout Stripe?

You can customize the look and feel of Checkout in the Stripe Dashboard. Go to Branding Settings where you can: Upload a logo or icon. Customize the Checkout page's background color, button color, font, and shapes.


2 Answers

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

like image 147
Fitzi Avatar answered Sep 21 '22 11:09

Fitzi


Metadata must be nested in the Session creation object:

Stripe's docs incorrectly list metadata as a parent (https://stripe.com/docs/api/checkout/sessions/create) when in fact it's a child:

https://support.stripe.com/questions/using-metadata-with-checkout-sessions

  1. payment_intent_data.metadata
  2. subscription_data.metadata

client_reference_id is associated with the Session only, and does not get stored in Stripe as metadata.

like image 25
jprio Avatar answered Sep 17 '22 11:09

jprio