#kekko7072

1 messages · Page 1 of 1 (latest)

drifting jettyBOT
oblique zodiac
#

Hi! Let me help you with this.

#

Are you with me?

oak pivot
#

Sorry give me 5 minutes

#

So hy i have a backend firebase function

#

that is called from an IOT device

#

and in this function i canfirm the payment method

#

try {
// API DOC https://stripe.com/docs/api/payment_intents/create
const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: "eur",
customer: userData.billing.customerId,
confirm: true,
off_session: true,
payment_method: userData.billing.paymentMethodDefault,
payment_method_types: ["card"],
});

                debug(paymentIntent.id);
                debug(paymentIntent.payment_method);

                const confirmPaymentIntent =
                  await stripe.paymentIntents.confirm(paymentIntent.id, {
                    payment_method: `${paymentIntent.payment_method}`,
                  });

                log(confirmPaymentIntent.status);
              } catch (e) {
                payed = false;

                error(e);

                // Set user to not payed
                await userCollection
                  .doc(uid)
                  .update({
                    "billing.paymentResume": true,
                  })
                  .catch((e) =>
                    error(
                      `Error in ending session,
                 ERROR: ${e} 
                 | PID: ${req.body.powerBank}`
                    )
                 
            } else {
              debug(
                `✅ No transaction because user used it's wallet balance
                \nUid: ${uid}
                \nAmount: ${amount}
                \nBalance: ${userData.billing.wallet.balance}
                \nBalance_to_remove: ${balanceToRemove}`
              );
#

this is the request

#

req_rJ4WrgtSHZyZYg

#

it returns the error "You can not confirm this paymentIntent because it has already succeded afther being previously confirmed"

oblique zodiac
oak pivot
#

yes it's successful but on my try catch code

#

return this errore

#

My code is this:

#

const paymentIntent = await stripe.paymentIntents.create({
amount: amount,
currency: "eur",
customer: userData.billing.customerId,
confirm: true,
off_session: true,
payment_method: userData.billing.paymentMethodDefault,
payment_method_types: ["card"],
});

                debug(paymentIntent.id);
                debug(paymentIntent.payment_method);

                const confirmPaymentIntent =
                  await stripe.paymentIntents.confirm(paymentIntent.id, {
                    payment_method: ${paymentIntent.payment_method},
                  });
#

how should i change it to make sure i will not get this error

#

on the try catch block

#

this is the log

#

pi_3NDipuA94JJJ3znb14CplqUL

oblique zodiac
#

I see, this request has failed: req_fDGwlo1stL5M9R

oak pivot
#

becuase i have a webhook that says payment_intent.succeeded

oblique zodiac
#

You are creating a PaymentIntent with confirm: "true" and it succeeds immediately, you don't need to confirm it anymore.

oak pivot
#

ok so i can remove this code ? const confirmPaymentIntent =
await stripe.paymentIntents.confirm(paymentIntent.id, {
payment_method: ${paymentIntent.payment_method},
});

#

in the function that is called to make the user pay?

oblique zodiac
#

It depends what is the flow you are looking for. If you want to charge the saved Payment Method, yes you don't need to confirm the PaymentIntent separately

oak pivot
#

ok thankyou

#

can you suggest me flow if user hasnt payment method registred

#

what should i do?

oblique zodiac
#

Depends if you want to use Stripe Checkout or custom Payment Element.

oak pivot
#

ok thankyou

oblique zodiac
#

Happy to help. Please, let me know if you have any other questions.