Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Doesn't Stripe Checkout Add Customer Name to Customer Record?

I am trying to retrieve various pieces of data from a Stripe Checkout form submission, where I am just using the Stripe Checkout code provided in my Stripe Dashboard.

In my checkout_submission_completed event I have webhook where I am trying to retrieve email, name so that after successful purchase I can take other actions.

It is surprisingly difficult.

Here is how I can retrieve email (where payload is the response my webhook receives):

 $cust = $payload['data']['object']['customer'];
 $custdata = \Stripe\Customer::retrieve($cust);
 $email=$custdata->email;

Ok, not a big deal.

How about Name? Well, here is where things get really fun. After hitting the form payment submit button Stripe creates a customer, completes a successful charge. But in the Customer object there is no name. Yes, no name. During a chat today with Stripe they had no explanation and said they would look into it more.

Turns out the only place where the name entered on the form shows up in a Stripe object is the Payment Details Object within the Payment Intent object.

I am serious. So here is how I am getting the name (using cust from previous code:

   $piid = $cust = $payload['data']['object']['payment_intent'];
   $pi = \Stripe\PaymentIntent::retrieve($piid);
   $name = $pi['charges']['data'][0]['billing_details']['name'];

Is there a better way for me to do this?

thanks, Brian

like image 296
Brian Avatar asked Sep 05 '19 18:09

Brian


People also ask

How do I use the customer resource with stripe billing?

Learn how to use the Customer resource with Stripe Billing. The Customer resource is a core entity within Stripe. Use it to store all of the profile, billing, and tax information required to bill a customer for subscriptions and one-off invoices. Create a customer for every new user or business you want to bill.

Can I create and manage customers in the stripe dashboard?

You can create and manage customers in the Stripe Dashboard. This is especially useful if you don’t want to use code to create a customer, or if you want to manually bill a customer with a one-off invoice.

How do I add Tax IDs to a customer using stripe?

With Stripe, you can add one or multiple tax IDs to a customer. A customer’s tax IDs are displayed in the header of invoice and credit note PDFs.

How do I store my stripe customer IDs?

This allows you to search for the customer using your internal reference ID. Conversely, we recommend storing Stripe customer IDs against the internal customer model of your application. Use the address properties to set an address for billing (invoicing, credit notes, and so on), and a shipping address (for physical goods).


1 Answers

I think the idea is that the name collected is a cardholder name and is associated with the card [0] , not the Customer. A Customer might end up with multiple cards or other payment methods, and they might reasonably all have different cardholder names. So that information isn't transposed up to the Customer by default.

Your approach looks generally good — I would personally use the expand feature [1] of the API so you can skip a bunch of API calls by retrieving the full context of the Checkout Session and its payment and customer in one call from the webhook handler.

$session  = \Stripe\Checkout\Session::retrieve(
  $payload['data']['object']['id'],
  ["expand" => ["payment_intent", "customer"]]);

$cardholderName = $session['payment_intent']['charges']['data'][0]['billing_details']['name'];
\Stripe\Customer::update($session['customer'].id,
  ["name" => $cardholderName]);

[0] - https://stripe.com/docs/api/payment_methods/object?lang=php#payment_method_object-billing_details-name

[1] - https://stripe.com/docs/api/expanding_objects?lang=php

like image 79
karllekko Avatar answered Oct 16 '22 08:10

karllekko