#masudrhossain

1 messages · Page 1 of 1 (latest)

sly sundialBOT
#

Hello! We'll be with you shortly. 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.

west imp
#

Hi there

lunar sand
#

hey

west imp
#

Can you provide the PaymentIntent ID that you are testing with?

lunar sand
#

I'm not using it with a paymentintent, instead of using it to save a card to a Customer profile as their default payment method.

west imp
#

Ah so SetupIntent then

lunar sand
#

Basically when the user submits the card on the frontend, my backend does this

# Create a customer with the payment method
        customer = Stripe::Customer.create(
          email: current_user.email,
          payment_method: params[:paymentMethodId],
          invoice_settings: {
            default_payment_method: params[:paymentMethodId]
          }, 
          metadata: {
            name: current_user.username
          }
        )
west imp
#

That is irrelevant to actually tokenizing the PaymentMethod and attaching it to the Customer.

#

That has to be done before what you are doing above.

#

And you should be using a SetupIntent to do that.

lunar sand
#

I don't think i'm doing setupintent either.

i'm just doing

import { CardElement, useStripe, useElements } from '@stripe/react-stripe-js';

<Elements stripe={stripePromise} options={options}>
  <form onSubmit={handleSubmit}>
    <CardElement options={{ style: { base: { fontSize: '16px' } } }} />
  </form>
</Elements>

And on submit it'l do a post

west imp
#

Okay well that is why you aren't seeing 3DS most likely

#

What does your handleSubmit() function do?

#

It just calls createPaymentMethod I assume?

lunar sand
#
const handleSubmit = async (e) => {
    e.preventDefault();
    setDisabled(true)

    if (!stripe || !elements) {
      return;
    }

    setIsLoading(true);

    const cardElement = elements.getElement(CardElement);

    // Create a Payment Method using the Card Element
    const { error, paymentMethod } = await stripe.createPaymentMethod({
      type: 'card',
      card: cardElement,
    });

    if (error) {
      console.error(error);
      setIsLoading(false);
      return;
    }

    axios.post(`/api/o/${service.organization.token}/services/${match.params.service_id}/service_checkouts`, {
      paymentMethodId: paymentMethod.id,
      name,
      email,
    })
    .then(function(response){
      console.log(response);
      if(response.data.success){
        notice("Checkout successful");
      } else {
        setDisabled(false)
      }
    })
    .catch(function(error){
      console.log(error)
      notice("An error occured");
      setDisabled(false)
    })
    .then(function () {
      setDisabled(false);
    });

    setIsLoading(false);
  };
west imp
#

Yep

#

So that is why you don't see 3DS

lunar sand
west imp
#

You need to use a SetupIntent here as I noted.

#

Instead of calling createPaymentMethod() you call confirmCardSetup()

#

That will both create the PaymentMethod and handle 3DS

#

And it will attach the PaymentMethod to the Customer (if you passed the Customer ID when you create the SetupIntent on your backend)

lunar sand
#

Oh okay so setupintet is required to use confirmCardSetup?

setup_intent = Stripe::SetupIntent.create(
          payment_method_types: ['card'],
          customer: customer.id, # Replace with the actual customer ID
          setup_future_usage: 'off_session' # Set to 'off_session' for recurring payments
        )
west imp
#

Yep you need a client_secret to use confirmCardSetup()

lunar sand
#

Does setupintent work regardless if i'm doing a subscription or single product charge for my users future transacations?

west imp
#

Yep

#

It just ensures the PaymentMethod is set up for future use

lunar sand
#

So it's strictly a better way to handle saving a payment method to a customers profile and that's it?

west imp
#

Yep

lunar sand
#

appreciate it

west imp
#

Sure

lunar sand
#

Got everything to work BlobHappeee

But one final question. for usage: 'off_session', what if the Customer also wants to use that same payment method for recurring OR single charges?

    setup_intent = Stripe::SetupIntent.create(
      payment_method_types: ['card'],
      customer: customer.id, # Replace with the actual customer ID
      usage: 'off_session' # Set to 'off_session' for recurring payments
    )
sly sundialBOT
west imp
#

That is totally fine