#peter-payment-methods

1 messages ยท Page 1 of 1 (latest)

hidden ocean
#

Hi there! Taking a look now

#

Are you using Stripe Elements?

hallow owl
#

for reference, here is the code I'm using to make the request:

    const hasPaymentMethod = Boolean(cashSender.stripePaymentMethodId);
    const returnUrlProps = hasPaymentMethod
      ? {}
      : { return_url: `${process.env.WEB_CLIENT_URL}/offers` };
    const paymentMethodProps = hasPaymentMethod
      ? { payment_method: cashSender.stripePaymentMethodId }
      : {};
    const paymentIntent = await stripe.paymentIntents.create({
      customer: cashSender.stripeCustomerId,
      amount: totalAmount,
      currency: 'usd',
      application_fee_amount: feeAmount,
      confirm: true,
      transfer_data: {
        destination: cashRecipient.stripeAccountId,
      },
      automatic_payment_methods: {
        enabled: true,
      },
      metadata: {
        offer_id: offer.id
      },
      ...returnUrlProps,
      ...paymentMethodProps
    });
#

yeah

hidden ocean
hallow owl
#

so I have elements already up and working

#

I use "setup_intent" to add their payment method for future use in previous flows

#

but if they haven't gone through those flows, we create the payment_intent and then want to use the client-secret from they payment_intent to start the PaymentElement

#

I'm using confirmCardPayment after they complete the payment method flow

#

but the problem I'm seeing is that I can't get the client secret cuz the PaymentIntent is failing with the errors I mentioned above

hidden ocean
#

So you should try creating the Payment Intent without passing a return_url and then call confirmCardPayment()

#

Is there a reason that this doesn't work?

hallow owl
#

ah I just wanted to confirm it right away once the payment method is added

#

cuz they've technically already confirmed the payment

vital elk
#

Hi ๐Ÿ‘‹ I'm stepping in for @hidden ocean. Are you good here or can you explain clearly what you are trying and what's not working?

hallow owl
#

hey, I think my solution is to wait for the payment method to be added after the payment intent succeeds, then update the payment intent with confirm: true

#

is that right?

vital elk
#

What is is you are trying to achieve in that case?

#

Can you share request IDs for one request where the customer has an attached payment method already and one where they don't?

#

My initial approach would be to split the Payment Intent creation into 2 separate functions that each create an intent for the specific case. E.g. if (hasPaymentMethod){ createIntentWithPaymentMethod()} else {createIntentAndMethod()}

#

Sorry it's all on one line like that ๐Ÿ˜…

hallow owl
#

user buys an item
-- if payment method exists
-> create PaymentIntent and charge card
-- if does not exist
-> create PaymentIntent and use client-secret to add payment method, then charge card

vital elk
#

In the second case

#

This will do both parts together (create the Payment Method, attach it to the Customer, charge the Payment Method to complete the Payment Intent)

#

But in that flow you'll need to collect the payment details which is I think where you're at right now.

hallow owl
#

yeah I'm doing that now I believe

#

the trouble is having the payment confirm once the payment method is attached

vital elk
hallow owl
#

pi_3KqQLPJYMOMTx4nT0ZpztkKz

vital elk
#

Okay that's a Payment Element ID but I can try and work with that.

hallow owl
#

oh I see

vital elk
#

Okay so this request isn't configured for off-session usage so you'd collect payment method details but it'd be a one-off

#

These logs are really useful to find failed API requests. I make plenty of bad API calls and reviewing these help me out

hallow owl
#

thats awesome, thanks

vital elk
#

Okay so you make the Payment Intent, get it back and pass the client secret to your front-end. Where is the point of failure?

hallow owl
#

I was doing that before, but it wasn't completing the payment afterward

#

but it might work now, let me check

#

also it seems difficult to test these things in dev

#

is there a default bank account to use for Stripe Connect that always works in dev?

#

we're using Plaid + Stripe to connect bank accounts

hallow owl
#

ah damn, yeah they prob work but not with Plaid

#

cuz it's a login/password

vital elk
#

Oh, well shucks. Yeah we have test bank accounts for all kinds of different scenario testing

hallow owl
#

nice

#

ok so I'm seeing this issue when submitting the payment method

#
code: "resource_missing"
doc_url: "https://stripe.com/docs/error-codes/resource-missing"
message: "No such setupintent: 'pi_3KqQXuJYMOMTx4nT081fJ3kQ'"
param: "intent"
type: "invalid_request_error"

this is my code for submitting as given in the tutorial

    event.preventDefault();
    setIsLoading(true);
    if (!stripe || !elements) {
      return;
    }
    const result = await stripe.confirmSetup({
      elements,
      confirmParams: {
        return_url: `${process.env.NEXT_PUBLIC_BASE_URL}/${asPath}`,
      }
    });
    if (result.error) {
      logError(result.error);
    }
  };```
vital elk
hallow owl
#

oh damn one sec

vital elk
#

Are you using the Payment Element or the Card Element to collect payment method details?

hallow owl
#

Payment Element

vital elk
#

Okay, then that's the right function

hallow owl
#

got it, thanks

vital elk
#

Let me know if you have any questions or trouble getting it running