The payment gateway creates the Stripe customer like this:
$email = $owner->getEmail();
$customer = \Stripe\Customer::create([
'email' => $email,
'description' => $this->t('Customer for :mail', [':mail' => $email]),
'payment_method' => $stripe_payment_method_id,
]);
Seems like it would be helpful to use the user's display name, e.g.
$email = $owner->getEmail();
$name = $owner->getDisplayName();
$id = $owner->id();
$customer = \Stripe\Customer::create([
'email' => $email,
'name' => $name,
'description' => "$name ({$id})",
'payment_method' => $stripe_payment_method_id,
]);
Issue fork commerce_stripe-3090817
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jonathanshawComment #3
leducdubleuet commentedWe would need to do the same for a specific project so I created a patch adding this feature.
I tested in Stripe test mode and this adds the owner's display name in the customer created on Stripe as intended.
As you know, Stripe simply uses the email as the customer's name when the name is not specified on creation.
I wonder if using the display name might cause some unwanted side effects?
Can someone confirm this is OK to do so?
Thank you!
Comment #4
jonathanshawI can't imagine any side effects.
Comment #5
leducdubleuet commented@jonathanshaw
Thank you for your feedback.
@maintainers
Would it be possible to see this new feature anytime soon in a new release?
Thanks.
Comment #6
maursilveira commented@LeDucDuBleuet
Thank you for the patch, but I'm a bit confused here, and not seeing the expected result.
I applied the patch, and have Realname configured in my site with
[user:field_first_name] [user:field_last_name]as pattern. When I call::getDisplayName()elsewhere I get the correct formatted user name. However, when I complete a purchase using Commerce Stripe for a new customer, it gets created in Stripe with the name empty. All I see is the email address and the descriptionCustomer for <EMAIL HERE>.Am I missing something here? Do I need any other configuration for getting the user display name to have this working?
Thank you.
Comment #7
jonathanshawThis is not caused by this patch or fixable here. Likely it's because the real name is not properly available for a new user.
You might be able to workaround that using the display name alter hook.
You could also check for and/or create an issue for this module to add an event to allow customising the Stripe customer metadata.
Comment #8
maursilveira commented@jonathanshaw Thank you for your response, but I've just figured out the cause of the issue: I am using Stripe Payment Element, and the patch #3 only adds the
nameitem to the classStripe.I created a new patch that adds the name for both payment gateways. Moving the issue back to "Needs review" status.
Please let me know if you have any questions, concerns or comments.
Thank you.
Comment #9
jonathanshawComment #14
vmarchukCommitted!
Comment #15
leducdubleuet commentedThis is great, thank you very much!
I guess this will be included in the next pre-release version 8.x-1.2-rc2, right?
For a new site, this is perfect but what about existing sites with customers on Stripe already created prior to this new behaviour? I guess we could have some code to update them on our Stripe account from Drupal? Would that possible? Advisable?
Thanks again.
Comment #16
vmarchuk@LeDucDuBleuet
Definitely possible. This could be hook_update() with a batch where we can go through all Stripe users and update them accordingly.
Please create a separate issue for this.
Comment #17
leducdubleuet commentedOK, thank you for your quick reply.
I was just asking for now and I will open a new issue for that if need be.
Thanks again!
Comment #19
joe huggansCan I ask why you wouldn't use the name from the billing profile if available for this rather than the username?
Comment #20
jonathanshawHi @joe, I'm not sure. The billing profile is specific to the order; but the Drupal user is counterpart to stripe customer, the stripe customer id is stored on Drupal user entity I think. If the billing profile has the better info in a certain use case, maybe the display name needs to be updated to use it.