#r3d_code
1 messages ¡ Page 1 of 1 (latest)
đ 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/1331395334349520911
đ 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.
- r3d_code, 4 hours ago, 26 messages
I use payment_request on the frontend to handle google pay and apple pay payments
Hi there
Hey
What do you mean by "instant payment functionality"? Also, if you're moving to Products, Prices, and Invoices, does this mean you're also moving to Checkout or is your goal to continue using the PaymentElement?
Well I'd like to keep using the frontend I built, based on PaymentElement and especially paymentRequest but while getting the ability to send invoices and have a good tracking of purchases
I basically rely on paymentRequest and then stripe.confirmCardPayment on the frontend after displaying the correct Elements with the client_secret generated in the backend by the code above
Now if there's a way to just attach / generate an invoice attached to a paymentIntent that would be enough
So if you know a way to do that it would be of great help
Got it, okay.
You'll need to model this the other way around: creating and finalizing an Invoice will generate a PaymentIntent. You can use this PaymentIntent's client secret when working with Elements
Here's what I tried to do, but I don't see how I can get a PaymentIntent or the clientsecret from that
const invoice = await stripe.invoices.create({
...(selectedMethodId ? { default_payment_method: selectedMethodId } : {}),
...(stripe_customer_id ? { customer: stripe_customer_id } : {}),
collection_method: 'charge_automatically',
auto_advance: true,
currency: 'eur',
description: `MyService - ${Math.round(amount / 100)}`,
});
const invoiceItem = await stripe.invoiceItems.create({
invoice: invoice.id,
customer: stripe_customer_id,
price: priceFromAmount(amount), // Gets the price object id that fits the amount to bill, i have one product with one price per amount
quantity: 1,
description: `MyService - ${Math.round(amount / 100)}`
});
const invoiceFinalized = await stripe.invoices.finalizeInvoice(invoice.id);
const invoicePaid = await stripe.invoices.pay(invoice.id);
invoiceFinalized will be an Invoice object so you can retrieve the Invoice and expand its payment_intent to get the client secret: https://docs.stripe.com/api/invoices/object#invoice_object-payment_intent
Do I need to do the stripe.invoices.pay or will the confirmCardPayment work in elements?
That said, your code above is creating an Invoice for a specific Customer, setting a default payment method for that Invoice, and attempting to pay that Invoice server side
There are two ways I bill customers, when they are new customers who have just created their account I use confirmCardPayment on the client side, when they've been using the service for a while and are not connected I use their saved payment method off session
Got it. You shouldn't need to call stripe.invoices.pay server side when working with new customers. You should instead use the client secret for the Invoice's PaymentIntent to use confirmCardPayment client side
But can I create an invoice before creating a customer?
Hello! I'm taking over and catching up...
No, you need a Customer to create an Invoice.
Ah, so I need to do a setupIntent beforehand then?
No? You can create a Customer without any information or payment info.