To use Stripe tokens in Upodi, you must follow the implementation guidance from Stripe to create a customer with a default payment method (credit card) attached. You can use various methods from Stripe to integrate your token method with Upodi. Please see Stripe documentation here or our GitHub sample here.
Upodi then uses the customer id by Stripe. Example using the customer ID cus_C9VhJ6qk0qkKqI. In most cases, you should create tokens client-side using Checkout, Elements, or Stripe mobile libraries, instead of using the Stripe API.
Using Stripe to get a customer token
Stripe requires that you save the card token to a customer in order to use it for a recurring charge in the future.
Once you retrieve the card token (example: tok_60OX9jRXUI6WzLI0V2SFxUjr), do not charge the token. Instead save it to a customer object:
# Create a Customer:
curl https://api.stripe.com/v1/customers \
-u sk_test_BQokikJOvBiI2HlWgH4olfQ2: \
-d email="[email protected]" \
-d source=tok_60OX9jRXUI6WzLI0V2SFxUjr
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];
// Create a Customer:
$customer = \Stripe\Customer::create(array(
"email" => "[email protected]",
"source" => $token,
));
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
StripeConfiguration.SetApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");
// Token is created using Checkout or Elements!
// Get the payment token submitted by the form:
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
});
Once you have created the customer, you can retrieve the customer id and send this to Upodi using our API. Further documentation is available on Stripes website.
You can see a sample page how to bulid a form for Upodi using Stripe elements here.
Provide the token to Upodi Payment
To create a payment method for Stripe token, make a POST request to /paymentmethods/:customerid/ with a body using the createpaymentmethod request object:
{
"type" : 64 /* PureTokenBased = 64 */,
"makedefault" : "true", /* will make the payment method default on the customer */
"puretoken" : {
"token" : "cus_C9VhJ6qk0qkKqI", /* Stripe customer ID */
"paymentgateway" : "stripe"
}
}