Attaching metadata to Stripe Payment Link

Viewed 940

Is it possible to attach metadata to a Stripe Payment link (that directs to Stripe for payment)?

I've setup a basic link to a Stripe payment, and have a link to the payment on my site.

What I hope to achieve is have a rendered mustache template attach to that link some extra parameters / query data, that will act as a metadata set.

ie: <a href="www.stripe.com/tk_live_foobarlinktopayment?userid={{user._id}}"> <button>Pay Now</button></a> ...

I hope to link who's account is making the payment via this metadata.

2 Answers

The way I've solved this with Payment Links - I generate a unique Payment Link for each purchase and add metadata on Link creation (order_id in my case). This way it gets propagated to webhooks.

Create Payment Link cURL example:

curl https://api.stripe.com/v1/payment_links \
  -u sk_test_51INcGzGixr<..> \ 
  -d "line_items[0][price]"=price_1KPia<..> \
  -d "line_items[0][quantity]"=1 \
  -d "metadata[order_id]"=6735

This involves a bit more code than you might anticipate with Payment Links, but definitely lighter on implementation side that Checkout.

Also, don't forget to cleanup the Payment Links afterwards:

curl https://api.stripe.com/v1/payment_links/plink_1KPoiiGixr8beE1DMeFarexg \
  -u sk_test_51INcGzGixr<..> \
  -d active=false

I managed to post to the backend endpoint, using checkout.sessions.create.

This creates a payment attempt, where it directs you to a stripe side payment UI.

This payload example is what is passed to the Stripe API, Though I am using node-red and the Stripe payment node, you should be able to do this concept elsewhere.

msg.payload = {
    
     payment_intent_data: {    
         metadata : {
            "user_id": msg.user._id,
            "email" : msg.user.user,
         },  
     },
     payment_method_types : ['card'],
     mode: 'payment',
     success_url: 'https://streamtacular.com/payment_success',
     cancel_url: 'https://streamtacular.com/payment_cancel',
 
     line_items : [
         {
             quantity : 1,
             price_data : {
                 currency: 'usd',
                 product_data: {
                     name: 'Some Product'
                 },
                 unit_amount: 1200
             }
         }
     ]
}
Related