#r3d_code

1 messages ¡ Page 1 of 1 (latest)

upper dragonBOT
#

👋 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.

paper sable
#

I use payment_request on the frontend to handle google pay and apple pay payments

blissful sphinx
#

Hi there

paper sable
blissful sphinx
#

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?

paper sable
#

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

paper sable
blissful sphinx
#

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

paper sable
#

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);
blissful sphinx
paper sable
#

Do I need to do the stripe.invoices.pay or will the confirmCardPayment work in elements?

blissful sphinx
#

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

upper dragonBOT
paper sable
#

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

blissful sphinx
#

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

paper sable
#

But can I create an invoice before creating a customer?

barren ocean
#

Hello! I'm taking over and catching up...

#

No, you need a Customer to create an Invoice.

paper sable
#

Ah, so I need to do a setupIntent beforehand then?

barren ocean
#

No? You can create a Customer without any information or payment info.

paper sable
#

oooh

#

Didn't know that

barren ocean
#

Yeah, every parameter on a Customer is optional.

#

You can fill in their details later.