skip to Main Content

I’m trying to use Stripe Checkout for a subscription service.

Using the PHP SDK

Session::create([
            'customer' => $user->stripeCustomerId,
            'payment_method_types' => ['card'],
            'line_items' => [[
                'price' => 'price_0MACBYAGG6RS7KP5c1fNa6v9',
                'quantity' => $amount,
            ]],
            'subscription_data' => [
                'metadata' => [
                    'message' => $message,
                ],
            ],
            'mode' => 'subscription',
            'success_url' => UrlHelper::url('?session_id={CHECKOUT_SESSION_ID}'),
            'cancel_url' => UrlHelper::url('?cancel=true'),
        ]);

but metadata is never attached as per the docs https://support.stripe.com/questions/using-metadata-with-checkout-sessions?locale=en-GB

I have a single charge option that passes:

'payment_intent_data' => [
                'metadata' => [
                    'message' => $message,
                ],
            ],

and that attaches perfectly. What am I missing?

2

Answers


  1. Chosen as BEST ANSWER

    Turns out that I was looking in the wrong place. The meta data is not attached to each payment but on the actual subscription itself.


  2. Using subscription_data[metadata] (API ref) as you’ve done is the way this is intended to work. Have you confirmed in your request logs that the metadata was included in your request as you expect? It’s possible your $message might be empty in the subscription case.

    If your Checkout session request did include the subscription_data metadata as expected, then you should also see this on the subscription object after the customer completes the Checkout session. Where are you looking at the resulting subscription which makes you conclude that it does not have metadata?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search