User display name for stripe customer name

Created on 29 October 2019, over 4 years ago
Updated 16 May 2024, about 1 month ago

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,
        ]);
✨ Feature request
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 6 months ago
    38 pass
  • πŸ‡¨πŸ‡¦Canada LeDucDuBleuet Chicoutimi QC

    We 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!

  • Status changed to RTBC 6 months ago
  • πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK

    I can't imagine any side effects.

  • πŸ‡¨πŸ‡¦Canada LeDucDuBleuet Chicoutimi QC

    @jonathanshaw
    Thank you for your feedback.

    @maintainers
    Would it be possible to see this new feature anytime soon in a new release?

    Thanks.

  • πŸ‡¨πŸ‡¦Canada maursilveira Windsor, ON

    @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 user name format. 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 description "Customer for ".

    Am I missing something here? Do I need any other configuration for getting the user display name to have this working?

    Thank you.

  • πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK

    This 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.

  • Status changed to Needs review 4 months ago
  • πŸ‡¨πŸ‡¦Canada maursilveira Windsor, ON

    @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 name item to the class Stripe.

    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.

  • Status changed to RTBC 4 months ago
  • πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK
  • Pipeline finished with Failed
    4 months ago
    Total: 921s
    #106274
  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

    vmarchuk β†’ made their first commit to this issue’s fork.

  • Status changed to Fixed 4 months ago
  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

    Committed!

  • πŸ‡¨πŸ‡¦Canada LeDucDuBleuet Chicoutimi QC

    This 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.

  • πŸ‡ΊπŸ‡¦Ukraine marchuk.vitaliy Rivne, UA

    @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.

  • πŸ‡¨πŸ‡¦Canada LeDucDuBleuet Chicoutimi QC

    OK, 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!

  • Automatically closed - issue fixed for 2 weeks with no activity.

  • πŸ‡¬πŸ‡§United Kingdom joehuggans Harrogate, UK

    Can I ask why you wouldn't use the name from the billing profile if available for this rather than the username?

  • πŸ‡¬πŸ‡§United Kingdom jonathanshaw Stroud, UK

    Hi @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.

Production build 0.69.0 2024