Reputation: 14835
I'm trying to implement the diagram (find it at the bottom of this post) in my application. The whole flow has been implemented, except for the two blocks colored in red. They are required in order to prevent users from accidentally purchasing the same products more than once.
I would like to be able to create a checkout session where I can specify I don't want to allow existing customers from making purchases, for example:
// I'm using the Node.JS and JavaScript SDK
stripe.checkout.sessions.create({
line_items: [{
price: priceId,
quantity: 1,
}],
mode: "payment",
ui_mode: "embedded",
redirect_on_completion: "never",
// I would like something like this:
forbid_returning_customers: true,
});
I would then set this to true
only when the checkout session is being created by a non-logged-in visitor, and it would prevent the checkout as soon the user inserts an email that matches an existing Stripe customer email.
While, for logged-in visitors, I would set it to false
and I would pre-populate the customer id so that the email is pre-filled for them.
It would be better if it allowed me to specify a custom error message or a way to programmatically handle the event.
Unfortunately I can't find anything that satisfies my needs on the Stripe API documentation. What am I missing?
Here's the diagram with the whole flow, I'm providing it in case other solutions could apply to my request.
Upvotes: 0
Views: 62
Reputation: 722
This is impossible as there are no events that you can listen to during a Checkout Session to then take action on the Session, nor is there anything in the API that provides this behavior.
Instead, you want to create a Customer object with the email
of your user (sounds like you may already be doing this). You then pass this Customer object to your Checkout Session creation request and this will result in the email in the Checkout Session being prefilled.
You basically need to perform your authentication prior to creating your Checkout Session so you check if there is already a Customer object created with that email and if not create a new one and if so you re-use the Customer object and potentially prevent a purchase of the same product if they attempt to do that.
Upvotes: 0