#mauriver21

1 messages ยท Page 1 of 1 (latest)

deep mantleBOT
viscid hazel
#

Hi there, are you using the Prebuilt checkout page or the Custom payment flow?

winter karma
#

It's a custom payment flow, I'm working with the CardElement only

viscid hazel
#

OK. You can use CardElement with SetupIntent.

winter karma
#

Thxs, I think this give me a clue of how to solve it. One last question, the confirmCardPayment associates the payment method to the customer object?

viscid hazel
#

If you set the PaymentIntent's setup_future_suage and cutomer. Then the payment_method will be attached to the customer

winter karma
#

Thxs for the guidance, I will take a look. This was very helpful

winter karma
#

@viscid hazel your solution didn't work ๐Ÿ™ , the card element expects a payment intent key, but I need to work with a setup intent key

viscid hazel
#

can you share with me your code?

winter karma
#

Client side code:

const handleClick = async () => {
    if (!stripe || !elements) return;
    try {
      setProcessing(true);

      const { id, setupIntentClientSecret } = await lessonCreate({
        name: orderName,
        email: orderEmail,
      });

      setCustomerId(id);

      const { error, rest } = await stripe.confirmCardPayment(
        setupIntentClientSecret,
        {
          payment_method: {
            card: elements.getElement(CardElement),
          },
        }
      );

      console.log(rest);

      if (error) {
        setError(error);
        return;
      }

      setSucceeded(true);
    } catch (error) {
      switch (error.name) {
        case "CustomerExists":
          setError(error.message);
          setExistingCustomer({
            customerId: error.data.id,
            email: error.data.email,
          });
          break;
        default:
          console.error(error);
      }
    } finally {
      setProcessing(false);
    }
  };
#

Server side code:

app.post('/lessons', async (req, res) => {
  try {
    const { email } = req.body;
    const foundCustomers = await stripe.customers.list({
      email,
    });
    const [foundCustomer] = foundCustomers.data;

    if (Boolean(foundCustomer)) {
      throw newError('CustomerExists', 409, {
        message: 'This customer already exists',
        data: { id: foundCustomer.id, email: foundCustomer.email },
      });
    }

    const customer = await stripe.customers.create({
      ...req.body,
    });

    const setupIntent = await stripe.setupIntents.create({
      customer: customer.id,
      payment_method_types: ['card'],
    });

    res.send({
      ...customer,
      setupIntentClientSecret: setupIntent.client_secret,
    });
  } catch (error) {
    handleError(res, error);
  }
});
viscid hazel
#

stripe.confirmCardPayment( ->. it should be stripe.confirmCardSetup() as I explained earlier.

winter karma
#

You mentioned earlier confirmCardPayments
There are lots of gaps in the docs for setup intents.

viscid hazel
#

stripe.confirmCardSetup instead of stripe.confirmCardPayment

winter karma
#

Yes, what I mean, as a feedback, the docs about setup intents is very hidden and has many gaps, specifically for custom flows.
I've just used confirmCardSetup and worked as expected ๐Ÿ˜

viscid hazel
#

That's great and thanks a lot for your feedback

#

Also I'd suggest to use PaymentElement so that your customer have more payment method options

winter karma
#

Related to attaching the payment method to the customer obj, you mentionend to use "setup_future_usage" however this is for payment intents. For setup intents may I use stripe.retrieveSetupIntent(clientSecret) ?

viscid hazel
#

The purpose of SetupIntent is to setup a payment_method for a customer, so there's no setup_future_usage param in SetupIntent and you don't need to specify one

winter karma
#

but using stripe.confirmCardSetup, visualizing the dashboard, the customer still doesn't show an associated payment method

viscid hazel
#

give me your setupIntent ID

winter karma
#

seti_1MRRRMG7PaZ8mE7W1VYw76n6

#

Here payment method appears empty

#

But clicking inside, it appears

viscid hazel
winter karma
#

May be is a bug in the dashboard?

viscid hazel
#

you can view the payment method here

#

No, the payment methods are shown in the customer details page, not list page.

winter karma
#

so which is the purpose of this payment method column?

#

Checking the overview, It's working as expected, it got me confused the list view of the dashboard with this empty column ๐Ÿ˜ .

viscid hazel
#

Can you share with me the URL?

#

Oh I see, that payment method column shows the default payment method attached to the customer

#

This customer doesn't have a default payment method, and that's why it shows empty

winter karma
#

That's good to know ๐Ÿ˜…

viscid hazel
#

I agree the UI should be less confusing, thanks for your feedback!