skip to Main Content

As you might know, the Stripe payment extension for Firebase does the following:

  1. Creates a products collection that gets filled with products managed in Stripe.
  2. Creating a document under customers/{id1}/checkout_sessions/{id2} creates a payment in stripe. The document gets updated with the payment URL that the user can use to pay.
  3. After paying, a document gets created by Stripe at customers/{id1}/payments/{id3}

How do you associate the payment that gets registered to the document in checkout_sessions?

The checkout_session document looks like

{
  cancel_url: (CancelUrl),
  client: "web",
  created: (Timestamp),
  mode: "payment",
  price: (The priceId associated to the product),
  sessionId: (The session id of the checkout_session),
  success_url: (SuccessUrl)
}

I create the checkout_session document myself, so I can add extra meta data in there but I’m not sure if Stripe can use it.

The payment document is significantly more complex. But the only id that I can associate to anything is the customer stripeId which appears as customer on the payment document.

Basically I’m trying to do the following.

  1. A user creates a digital item with some custom properties (name, options, etc).
    This can happen during the creation of the checkout_sessions document.
  2. They pay using the URL provided.
  3. The payments document is created
  4. This is where you help me figure out to validate that the payment they made is associated with the digital item created.

One idea that I have that will probably work is to do the following: Instead of allowing the creation of the digital item during the creation of the checkout_sessions document, I can create a "voucher" for that specific item. It won’t have any personalization or options, but what I can do is create document onCreate cloud function on the payment document. If the payment is successful, allow the creation of the digital item. I can look up the ‘template’ based on the item purchased.

I dont like this option because there are at least 2 potential cold start delays that could make this a bad user experience.

2

Answers


  1. Chosen as BEST ANSWER

    When creating the checkout_sessions document, you can add a metadata object that can contain key:value pairs that will appear on the root of the document that is created in payments collection.


  2. You should listen to the checkout.session.completed event and retrieve the line_items of the checkout session object. From there you’ll know what items are purchased successfully.

    The details are explained in the integration doc

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