#byron-firebase-help

1 messages ยท Page 1 of 1 (latest)

drowsy kindleBOT
worldly jolt
humble merlin
#

Hi Snufkin
I'm using that extension ๐Ÿ™‚ It was also only transferred a few days ago and I've checked the commit history and nothing has changed in the last little while (so it's effectively the same thing)

worldly jolt
#

Right but we are directing all support for it to Invertase

humble merlin
#

I see. I have tried contacting them (through issues on Github) but am not getting anywhere.
How else can I reach them?

worldly jolt
humble merlin
#

haha that's a lot of firebase function knowledge ๐Ÿ˜›

Once sec I'll find some logs for you

#

Here is the event ID for the webhook firing after a customer made a successful purchase. It is trying to obviously update that user's data on Firestore but subsequently fails when it can't find the matching user.
evt_1NgAxKB2IaEU6ucijCtDIUZg

I'll try find an API request for you...

worldly jolt
#

Okay so I'm guessing you know that

  1. Since you are creating Subscriptions, a Customer object is required
  2. Payment Links do not "look up" if a customer exists with that email, they just create a new Customer if required.

IS it the case that in Firestore customers are identified by their email?

humble merlin
#

I suspect there won't be a req_ log because this originated from Stripe

worldly jolt
humble merlin
#

Yeah like that (although that's not a session complete, which is what I assume updates anything on the firestore side).

But, that aside, lemme maybe ask from the fundamentals because again, I reckon the issue here is my understanding and not the code ๐Ÿ™‚

If a user has signed up on my site, and they want to now make a purchase. They open the product table, hit the button and the purchase happens.

What does that flow look like? How does Stripe or Firestore know the others' state?

worldly jolt
#

So you have your own product table that uses Payment Links to send the user to a payment interface (Checkout Session)?

humble merlin
#

yes

worldly jolt
#

I don't know how Firestore keeps itself in sync but I would imagine they listen to any number of webhook events

#

I see 14 different events all related to that 1 confirm call I shared

#

As well as the .updated events after that

#

when it tries to find that user in Firestore, it doesn't exist (because its a new user now)
Here is where my ignorance of Firestore is unhelpful. I'm not sure what you mean by "it's a new user now"

drowsy kindleBOT
nocturne lotus
#

byron-firebase-help

humble merlin
#

(Scenario 1)
So when someone makes a purchase, and Stripe creates a new customer within Sripe, it also creates a new customer in firestore. New.
However, that new user doesn't have an authentication account on firebase so it technically isn't really a "user account". It's just a customer in the database now. Bit pointless.

BUT (scenario 2)
If I create a user on firebase first, it creates a customer in firestore AND a customer in Stripe automatically. That new customer in Stripe also carries with it a customerID in the metadata, which can be used to link it to a customer in firestore.

So both side work. Nice.

The issue is (lets assume scenario 2) when the user now goes over to Stripe and makes the purchase, using the same email, Stripe goes and makes a whole new customer and falls back to scenario 1.

nocturne lotus
#

That part is mostly expected

#

We don't do any "de-duplication" of Customer(s) by email or anything like this.

#

It's something you need to control/own via your own code/integration

humble merlin
#

Is there a way to pass some kind of key (for example a stripe customerID) back to the payment link? So Stripe knows that its working with an existing user?

nocturne lotus
#

No that's impossible. A PaymentLink is kind of a reusable link for everyone to just pay

#

in this world you should not use a PaymentLink at all. If you know who the end customer is and they have a Customer object in Stripe then you should be using Checkout directly and create a Session with their existing Customer id in customer: 'cus_123'

#

PaymentLink is more a "factory" to create N Checkout Sessions. Like you sell a book and you tweet a link and anyone can click it, get to Checkout and pay. Does that make sense?

humble merlin
#

I see. That does make sense. Ok.

So how would I direct the user after they've clicked "buy" on my site, to a Stripe checkout?
(I say Stripe checkout hoping there's some UI so I don't have to build out an entire checkout process manually)

nocturne lotus
#

yeah you're misunderstanding a bit

#

Our PaymentLink product is a layer on top of our Checkout product

humble merlin
#

ok ok ok I think I understand.
So basically:

const session = await stripe.checkout.sessions.create({
  customer: 'cus_123'
  success_url: 'https://example.com/success',
  line_items: [
    {price: 'price_H5ggYwtDq4fbrJ', quantity: 2},
  ],
  mode: 'payment',
});

Then on response, direct them to the url.
Ok that makes sense.

#

(I just copied that code from your docs for example)

nocturne lotus
#

yep!

#

I'm sorry this is so confusing until someone explains it ๐Ÿ˜…

humble merlin
#

Ah what's a few days of bashing your head against the wall between friends right

#

haha thanks a lot for the patience. I'll go work on it some more. Thanks Snufkin too.
Cheers for now