Stripe Session Getting Customer Name

Viewed 1146

I would also like to retrieve the name of the person who paid. How can I get the name value from the stripe session? I have tried this:

const sessions = await stripe.checkout.sessions.list({
    limit: 1,
  });
console.log(sessions.data[0].customer)
const customer = await stripe.customers.retrieve(sessions.data[0].customer);
console.log(customer)

which gets me the email, but the name is null.

1 Answers

UPDATE: Customers created through Checkout have a null name because it is not collected/set. The "name on card" field on the Checkout page is for the cardholder name for the payment method, not the name of the customer (see https://stripe.com/docs/api/payment_methods/object#payment_method_object-billing_details-name). If you want a Customer created through Checkout to not have a null name, you'll have to update the Customer after the session is completed.

Stripe has a dashboard setting (https://dashboard.stripe.com/settings/emails) you can enable that automatically sends receipts to customers for successful payments completed in live mode. Payments completed in test mode will not automatically send an email, but you can trigger one manually through the dashboard. You can read more about sending receipts here: https://stripe.com/docs/receipts#automatically-send-receipts-when-payments-are-successful.

If you want to grab the customer’s email and send a receipt yourself it’ll be a bit more complicated.

  1. Wait for the Checkout Session to finish by listening for checkout_session.completed through a webhook endpoint (https://stripe.com/docs/payments/checkout/fulfill-orders#handle-the-checkoutsessioncompleted-event).
  2. Grab the customer ID from the Checkout Session object that comes in with the checkout_session.completed event.
  3. Using the customer ID from the previous step, retrieve the Customer object (https://stripe.com/docs/api/customers/retrieve) and get the customer’s email.
Related