Where can I get the SourceToken for the customer creation in Stripe?
Here is the example of the code which uses the SourceToken
:
if (Request.Form["stripeToken"] != null) {
var customers = new CustomerService();
var charges = new ChargeService();
var customer = customers.Create(new CustomerCreateOptions {
Email = Request.Form["stripeEmail"],
SourceToken = Request.Form["stripeToken"]
});
var charge = charges.Create(new ChargeCreateOptions {
Amount = 500,
Description = "Sample Charge",
Currency = "usd",
CustomerId = customer.Id
});
Console.WriteLine(charge);
}
What is SourceToken
out of this json
?
{
"id": "tok_1EL43MKfPgrABB02rh7IGG7l",
"object": "token",
"card": {
"id": "card_1EL43MKfPgrABB02yFgReMXc",
"object": "card",
"address_city": null,
"address_country": null,
"address_line1": null,
"address_line1_check": null,
"address_line2": null,
"address_state": null,
"address_zip": null,
"address_zip_check": null,
"brand": "Visa",
"country": "US",
"cvc_check": "pass",
"dynamic_last4": null,
"exp_month": 12,
"exp_year": 2020,
"funding": "credit",
"last4": "4242",
"metadata": {},
"name": "foo@gmail.com",
"tokenization_method": null
},
"client_ip": "194.44.142.6",
"created": 1554278556,
"email": "foo@gmail.com",
"livemode": false,
"type": "card",
"used": false
}
Here is how I got the json:
var stripe = Stripe('pk_test_ob6s7KZxZU1mouJbbsuFBjEe');
var handler = StripeCheckout.configure({
key: 'pk_test_ob6s7KZxZU1mouJbbsuFBjEe',
token: function(token, args) {
var stop = 0;
}
});
document.getElementById('myBtn').addEventListener('click', function(e) {
// Open Checkout with further options
handler.open({
name: 'Demo Site',
description: '2 widgets ($20.00)',
amount: 2000
});
e.preventDefault();
});
on line var stop = 0;
.
The example is taken from here.
The SourceToken in that JSON is "tok_1EL43MKfPgrABB02rh7IGG7l"
.
After the customer is created with the source attached (e.g. that token), you can retrieve the customer which will include that customer's sources (they'll be listed in the sources
object under the customer
record).
The token itself gets consumed during the creation of the source and customer, and the result is a source that's reusable.