#basil_customer-paymentmethods

1 messages ยท Page 1 of 1 (latest)

nocturne canopyBOT
#

๐Ÿ‘‹ 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/1270419422829609024

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

feral kestrel
#

basil_customer-paymentmethods

#

That SetupIntent was never associated/attached to a Customer. It's just a one-off SetupIntent so that's expected

#

If you already have a Customer cus_123 then you need to pass customer: 'cus_123' when you create the SetupIntent

vague kettle
#

Thanks for your response @feral kestrel. I do have a test customer that I had set up using the customer creation API. The customer number is
cus_QZqyvqUHn9JM7C. I have this value stored in our database, and an passing it in the customer parameter, which is passed from the front-end as the customerId parameter.

router.post('/create-intent', async (req, res) => {
  try {
    const { customerId } = req.body; // Assuming customer ID is passed in the request body
    const intent = await stripeApp.setupIntents.create({
      customer: customerId,
      // automatic_payment_methods: { enabled: true },
    });
    res.json({ client_secret: intent.client_secret });
  } catch (error) {
    console.log('error:', error);

    res.status(500).json({ error: error.message });
  }
});

The intent request payload is {"customerId":"cus_QZqyvqUHn9JM7C"}.

feral kestrel
#

Add logs to your code and you will see that it is not working. When you are creating the SetupIntent you are not passing a customer parameter

vague kettle
feral kestrel
#

That's a picture of the Dashboard and is irrelevant I'm sorry. Please take the time to read what I am describing as you are going a bit too fast

#

You have a bug in your code somewhere, that customerId variable is empty

vague kettle
#

Ok. Sorry, that screen shot is to show that a customer exists with that customer ID, which matches what I'm sending in the intent request.

feral kestrel
#

Sure but that variable is empty. If you add logs you will see it immediately

feral kestrel
#

@vague kettle did you figure it out?

vague kettle
#

Ok, I'm looking at the POST body in the logs, and you are right: I don't see any customer entry.

{
  "client_context": {
    "currency": "usd",
    "mode": "setup",
    "setup_future_usage": "off_session"
  },
  "client_secret": "********************************************************************",
  "expected_payment_method_type": "card",
  "key": "pk_test_*********************************************************************************************OtXRBS",
  "payment_method_data": {
    "allow_redisplay": "unspecified",
    "billing_details": {
      "address": {
        "country": "CA",
        "postal_code": "N0N 0N0"
      }
    },
    "card": {
      "cvc": "***",
      "exp_month": "12",
      "exp_year": "25",
      "number": "**** **** **** 4242"
    },
    "client_attribution_metadata": {
      "client_session_id": "27abeee9-7997-4988-90e6-50c631f0ce25",
      "merchant_integration_source": "elements",
      "merchant_integration_subtype": "payment-element",
      "merchant_integration_version": "2021",
      "payment_intent_creation_flow": "deferred",
      "payment_method_selection_flow": "automatic"
    },
    "guid": "1290beb5-22a8-4291-91b1-b59dd0882449c9d41b",
    "muid": "d4cb0a55-4b57-4aa6-bfd7-d640c479d69ce825ae",
    "payment_user_agent": "stripe.js/9c2a825626; stripe-js-v3/9c2a825626; payment-element; deferred-intent; autopm",
    "referrer": "http://localhost:5173",
    "sid": "a81f0d1e-7454-4fb6-8e93-274ba4d1cd29785e41",
    "time_on_page": "149204",
    "type": "card"
  },
  "radar_options": {
    "hcaptcha_token": "20000000-aaaa-bbbb-cccc-000000000002"
  },
  "return_url": "http://localhost:5173/signup/5",
  "use_stripe_sdk": "true"
}
#

Where should the customer ID be?

feral kestrel
#

yeah you're looking at the completely wrong thing unfortunately

#

This is the API request done client-side to confirm the SetupIntent. The issue is with your creation request

vague kettle
#

The creation request for the payment method?

#

Ok, I found that the request.body isn't getting to my endpoint.

feral kestrel
#

the creation request for the SetupIntent. And yep not surprised, that is what I was trying to explain earlier when you shared your code

vague kettle
#

Thanks. I'll dig into why the req.body is empty.

nocturne canopyBOT
vague kettle
#

Ok, I got it!

#

I had forgotten to add the headers to the request.

#
    // Create the SetupIntent and obtain clientSecret
    const res = await fetch(`${VITE_API_URL}/stripe/create-intent`, {
      method: "POST",
      headers: { // missed this
        'Accept': 'application/json',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify(body)
    });
feral kestrel
#

๐Ÿ‘ glad you figured it out

vague kettle
#

The customer payment method is showing up now!

#

Thanks for your help (and patience) ๐Ÿ˜ƒ