Search code examples
javascriptc#stripe-paymentsstripes

Stripe V3 Cardholder name on source card


I have MVC project and facing one issue with stripe flow. any help would be really appreciated.

Below is my flow.

  • I'm creating card token from UI using stripe js version v3. with this code, I'm able to retrieve both card and token perfectly from stripe.

    stripe.createToken(card, { name: name }).then(function (result) {
     if (result.error) {
         // Inform the customer that there was an error.           
     } else {
       // stripeTokenHandler will post the form to back end with token, here we are getting card with proper name,
       // but we are just sending token to back end
         stripeTokenHandler(result.token);
     }
    });
    
  • Then I use that token further to create a stripe source with C# back end code, for that I have used Stripe.net, Version=37.15.0.0m below is the code.

    // creating a stripe customer, consider this is working fine
     Stripe.Customer customer = GetCustomerService().Create(options, requestOptions);
    
    // create the credit card source and attach it to the current StripeCustomerId
     var options = new Stripe.SourceCreateOptions()
     {
         Type = "card",
         Token = token,
     };
    
     var requestOptions = new Stripe.RequestOptions();
    
     if (stripeAccountId.IsNotEmpty())
         requestOptions.StripeAccount = stripeAccountId;
    
     Stripe.Source source = null;
    
     try
     {
         source = GetSourceService().Create(options, requestOptions);
     }
     catch (StripeException ex)
     {
         msgs.Add(ex.Message, MessageType.UserError, ex);
         msgs.Add($"Payment source was not created", MessageType.UserError);
     }
    
  • And this is how I'm retrieving stripe sources.

    List<Stripe.Source>() sources = GetSourceService().List(customerId).ToList();
    
  • This all works fine, but the retrieved sources does not contains the name of card holder, which was there when we created and retrieved token. I tried to look at the documentation, but no luck.

  • I think it's issue in the flow, I might be missing some pieces but not sure what it is. Again, any help would be really appreciated. Thanks!


Solution

  • If you're building a net new project you should really look at using the newer Payment Methods / Payment Intents APIs instead of what you're doing here.

    That said, you don't seem to be attaching the Token to the Customer, rather you seem to be creating a Source - which is different. If you do want to create the Source with a name, you'd want to provide that.