0

I have a screen in my ASP.NET MVC web application in which I ask the user for their credit card information. They type it in.

Adhering to PCI guidelines, I am using Stripe.js to send this credit card information to stripe and get back a stripe token.

I then post this stripe token to my ASP.NET MVC application. In the application, I would like to create a customer. I would not like to charge the customer just now. I simply want to create a customer so I can charge them later using their Stripe customerId.

The documentation provided here makes it look simple. However, the client library that I am using (Stripe NuGet package version 1.12.0) does not offer the StripeCustomerCreateOptions class and many other classes mentioned in that document.

Instead, it has these two methods that help you create a customer:

public StripeObject CreateCustomer(ICreditCard card = null, 
             string coupon = null, 
             string email = null, 
             string description = null, 
             string plan = null, 
             DateTimeOffset? trialEnd = default(DateTimeOffset?));

public StripeObject CreateCustomerToken(string customerId);

As you can see, none of the methods are of any help to me. The first one requires the server to pass credit card information, which I am not doing as it is against PCI guidelines.

The second one assumes that you already have a customer and you want a token for the customer to use someplace else.

How do I create a customer from within my ASP.NET MVC application if I already have a credit card token for him that I got from Stripe.js?

user990423
  • 1,397
  • 2
  • 12
  • 32
Water Cooler v2
  • 32,724
  • 54
  • 166
  • 336
  • 1
    According to [this](https://github.com/nberardi/stripe-dotnet/blob/master/src/CreditCardToken.cs#L8), you should be able to pass the token ID in the `card` parameter of the `CreateCustomer()` method. – Ywain Sep 29 '15 at 16:20
  • @Ywain You are right. I looked things up in reflector. Turns out that there is a class named `CreditCardToken` that implements the `ICreditCard` interface and so it can be passed in place of the `card` parameter. The `CreditCardToken` class represents such a token and can be instantiated by giving to its ctor the `string` token you received from Stripe. I was able to do this immediately after writing the question. Just didn't have the time to update this question with an answer. If you will, I will mark it as the right one. – Water Cooler v2 Sep 29 '15 at 16:53

1 Answers1

1

You can construct a CreditCardToken from a token ID (see here: https://github.com/nberardi/stripe-dotnet/blob/master/src/CreditCardToken.cs#L8).

As CreditCardToken implements ICreditCard, you can then use it as the card parameter in the CreateCustomer() method.

Ywain
  • 16,854
  • 4
  • 51
  • 67