Travis Delly
Travis Delly

Reputation: 1374

Stripe Payment Links with Customer Id

I am currently building an application where we want to user Stripe Payment links rather then building our own version of UI to support the same functionality. However I notice that Stripe Payment Links create a new customer every single time. Is there a way to attach my customer id to the payment link so that a new customer is not created when they attempt to buy more then one product? I would prefer not to have to have a single user have multiple customer ids inside of my database.

Thanks!

Upvotes: 17

Views: 7773

Answers (3)

Manuel
Manuel

Reputation: 9

Fired when a payment session is completed, successfully or not.

This event can be used to receive interesting information for internal use, via a parameter added to your payment link. The parameter should be called "client_reference_id". For example https://buy.stripe.com/test_fZe8AdgMFewR6sM9AA?client_reference_id=10

The interesting thing you ask in the comments is: how do I know if it has finished successfully without having to listen to the payment_intent.succeeded event?

Yes, you can. If you want to be absolutely sure that the payment has been completed successfully, simply see the value .getPaymentStatus() of com.stripe.model.checkout.Session object, and check that it has the value "paid":

EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
            
            
            StripeObject stripeObject = null;
            
           
            com.stripe.model.checkout.Session checkoutSession;
            
            
            if (dataObjectDeserializer.getObject().isPresent()) {
                stripeObject = dataObjectDeserializer.getObject().get();
               
                

                        // Handle the event
                  switch (event.getType()) {
                          
                        case "checkout.session.completed":
                          checkoutSession = (com.stripe.model.checkout.Session) stripeObject;


                          if(checkoutSession!=null){
                             
                               if(checkoutSession.getPaymentStatus().equals("paid")){
                                    ...
                                }


                           

Upvotes: 0

Miki Habryn
Miki Habryn

Reputation: 47

If you attach a ?customer_id=xyz to your payment link URL, then you will receive the xyz back again as the client_reference_id in the checkout.session.completed event via webhook.

Upvotes: -1

RyanM
RyanM

Reputation: 2960

Payment Links are not specific to a Customer record. The documentation does include examples of how you might append data to them to aid in reconciling payments to a specific individual.

If you want to make use of the Stripe hosted UI while still assigning specific Customer records then I would recommend making use of Stripe Checkout.

Upvotes: 4

Related Questions