Oliver Dixon
Oliver Dixon

Reputation: 7405

Stripe Payment Link creates new customer

We have to use payment links as were coming from a native desktop app on MacOS and Windows, Stripe has no support here.

The native desktop apps do not have a web-view.

Using the following API with url params. https://stripe.com/docs/payments/payment-links#url-parameters

const paymentLink = await stripe.paymentLinks.create({
    line_items: [
        {
            price: price.id,
            quantity: 3,
            //
        },
    ],
});

The url on the frontend opens as such (note to "client_reference_id")

final url = link + "?client_reference_id=$customerId&prefilled_email=${stripeCustomer!.email}";

The key url params are added.

The problem is, is that "client_reference_id" is ignored and a new customer is created on the Stripe dashboard, this is no good for making payments as we generate the payment for a specific account created on the database.

Any ideas what I could do here?


We tried checkout session but there is no way to open from a link. :-/

Upvotes: 4

Views: 2630

Answers (2)

Mike Knapp
Mike Knapp

Reputation: 131

Important to note: Stripe has requirements for the format of customer_reference_id:

client_reference_id can be composed of alphanumeric characters, dashes, or underscores, and be any value up to 200 characters. Invalid values are silently dropped and your payment page will continue to work as expected.

I was tearing my hair out trying to work out why client_reference_id wasn't being passed, and it looks like this was the issue – I was separating two values with a period.

Upvotes: 2

Travis Delly
Travis Delly

Reputation: 1374

I found the answer to this question. So the generic payment link does not work with a customer id, however you can create a session and attach a customer id to it. The session object will return with a url.

Example:

    const session = await stripe.checkout.sessions.create({
        line_items: [{ price: price_id, quantity: 1 }],
        mode: 'subscription',
        success_url: 'https://app.seedscout.com',
        cancel_url: 'https://app.seedscout.com',
        customer: cus_id,
    });

You can find more information in their documentation here.

https://stripe.com/docs/api/checkout/sessions/create

Upvotes: 4

Related Questions