#florin_best-practices

1 messages ¡ Page 1 of 1 (latest)

astral crestBOT
#

👋 Welcome to your new thread!

⏲️ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

⏱️ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

🔗 This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1313045911353688157

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

obsidian stirrup
#

Yes, you are right, an invoice takes the billing details from the customer.

#

If you want to change the billing address, you should update it on the customer object

bright thicket
#

hmm ok, but I've seen that the billing address is also saved on a payment method, are there any issues (except security reasons as I read the billing address is used for different checks for that payment method) if I don't choose to save the billing address on my payment method? Since my app lets the user choose their billing address and cards individually ?

obsidian stirrup
#

It's entirely up to you but I'll suggest you collect the necessary billing details for better card authorization rate.

bright thicket
#

hmm I would like to store them on the payment method, but when saving the payment method I've seen that a payment method gets created on every purchase when saving the payment method( the fingerprint is the same), so I should probably display the cards alongside it's billing address, right ? I've read some tickets and you said that my code should check if a payment method with the same data already exists, I should then choose not to create a new payment method

obsidian stirrup
#

Why do you ask the customer to input the payment method details again if you already have their saved payment method?

bright thicket
#

so basically the custom checkout will be something like this: The user will be able to choose between a saved card, a saved billing address, a saved shipping address but he can also enter a new card / shipping address / billing address

#

and I wanted to make sure that if he for some reason chooses to type an already existing card with the same billing address it shouldn't get created.

obsidian stirrup
#

No, I'm afraid that Stripe checkout doesn't have an option to detect existing payment method

bright thicket
#

from reading the docs, when creating an invoice, a payment intent is created right?

const invoice = await stripe.invoices.create({
customer: user.stripeCustomerId,
currency: 'GBP',
shipping_details: user.shipping_details,
metadata: {
orderId: 'your_order_id',
},
...(body.paymentMethodId && {
default_payment_method: body.paymentMethodId,
}),
});

  const invoiceItems = await Promise.all(
    cart.cart_items.map((item) => {
      return stripe.invoiceItems.create({
        customer: user.stripeCustomerId,
        amount: item.product.price * 100,
        currency: 'GBP',
        description: `${item.product.title} (x${item.quantity})`,
        invoice: invoice.id,
      });
    })
  );

this is my code and when trying to see the payment intent console.log('mark', invoice.payment_intent); it is null

obsidian stirrup
#

A non-zero finalized invoice would have a payment_intent attached to it.

bright thicket
#

yea, the total is 0 for that invoice, but I am creating invoice items for that invoice
const invoice = await stripe.invoices.create({
customer: user.stripeCustomerId,
currency: 'GBP',
auto_advance: false,
shipping_details: user.shipping_details,
metadata: {
orderId: 'your_order_id',
},
...(body.paymentMethodId && {
default_payment_method: body.paymentMethodId,
}),
});

  const invoiceItems = await Promise.all(
    cart.cart_items.map((item) => {
      return stripe.invoiceItems.create({
        customer: user.stripeCustomerId,
        amount: item.product.price * 100,
        currency: 'GBP',
        description: `${item.product.title} (x${item.quantity})`,
        invoice: invoice.id,
      });
    })
  );

and I can see that the invoiceItems have the correct invoice id

obsidian stirrup
#

Have you finalized it?

bright thicket
#

hmm, I think my flow was flawed, I thought I can create the invoice with the payment intent, let the user pay, and then finalize the invoice after a succesful payment

obsidian stirrup
#

No you need to finalize the invoice first

bright thicket
#

but that means that the invoice will be sent to the customer, even if he doesn't pay, right ? I might confuse invoices with receipts

obsidian stirrup
#

The main purpose of an invoice is the intention for asking a payment from a customer.

bright thicket
#

I have tried to manually finalize it
await stripe.invoices.finalizeInvoice(invoice.id);
console.log({ invoice });

and it is still in draft

obsidian stirrup
#

What's the invoice ID?

bright thicket
#

in_1QRUuMKCK5mmw7xEE42A9zaR

#

hmm in the stripe dashboard Ic an see it opened, but in my code it is not immediately available

obsidian stirrup
#

It's finalized. You should do a
invoice = stripe.invoices.finalizeInvoice(invoice.id);
so that console.log({ invoice }); will print out the latest invoice

bright thicket
#

oh yea, my bad, that was an overlook ..