Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting token to create customer using Stripe

I'm implementing Stripe in my ASP.NET Core app using Checkout.

I know how to get a token for charging a credit card using Checkout but where do I get the token to create a customer?

In the documentation, I see that I need to get a token to create a customer but not sure where that token comes from. https://stripe.com/docs/api/dotnet#create_customer

As far as I know, a token can be used only once so it cannot be the same token I get before charging a credit card.

like image 840
Sam Avatar asked Dec 16 '17 04:12

Sam


People also ask

What is Stripe customer token?

Tokenization is the process Stripe uses to collect sensitive card or bank account details, or personally identifiable information (PII), directly from your customers in a secure manner. A token representing this information is returned to your server to use.

Does Stripe offer network tokenization?

Stripe works with payment networks like Visa and Mastercard to tokenize a user's repository of PANs into network tokens, and maintains them so they stay current, even if the underlying card data changes.


1 Answers

As I am referencing here from stripe document

When you collect a customer's payment information, a Stripe token is created. This token can only be used once, but that doesn't mean you have to request your customer's card details for every payment.

Stripe provides a Customer object that makes it easy to save this—and other—information for later use. You can use Customer objects for creating subscriptions or future one-off charges.

What you have to exactly do is Create a customer you have got while taking card details from the customer and charge that customer.

Do it using following code snippet, in this way you will create a customer and charge using a single token

StripeConfiguration.SetApiKey(secret_key_of_your_account);
var token = model.Token; // Using ASP.NET MVC

var customers = new StripeCustomerService();
var charges = new StripeChargeService();

var customer = customers.Create(new StripeCustomerCreateOptions {
  Email = "[email protected]",
  SourceToken = token
});

// YOUR CODE: Save the customer ID and other info in a database for later.

// YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
var charge = charges.Create(new StripeChargeCreateOptions {
  Amount = 1500, // $15.00 this time
  Currency = "usd",
  CustomerId = customer.Id
});

read the referenced document for more details

like image 89
Rahul Sharma Avatar answered Oct 12 '22 15:10

Rahul Sharma