Since Stripe.Net
doesn't work anymore in the PCL side, we need to use DependencyServices<>
. However, when I'm trying to generate a token from credit card information, it seems like... It's missing in the doc, I just can't find anything on the web or in the doc, is that normal?
I would like to achieve something like that :
public string CardToToken()
{
var card = new Card()
{
Number = "4242424242424242",
ExpiryMonth = 12,
ExpiryYear = 16,
CVC = 123
};
try
{
token = await Stripe.CreateToken(card);
}
catch (Exception ex)
{
return null;
}
return token;
}
So then I can just simply send it to my server. Any idea to achieve something that easy? That's the last point I need to finish for my project...
This example is in my Android side.
Thank for any help...
I found a good workaround (only Android at the moment but I will update the answer for UWP soon).
Step 1
Stripe.Net
over each subplatforms, and I mean by that Android, iOS, UWP, not the PCL part (the code you share).Step 2
The infos you will get should be stored in that class, I did like that, you can achieve it by another way, of course.
In your PCL, declare a CreditCard.cs:
Step 3
DependencyServices<>
. So we nee an interfaceIStripeServices
in the shared code (PCL), and a service that inherit of it, in the subplatform.In your PCL, declare a IStripeServices
Android: Create a StripeServices class like that:
Step 4
You can now generate a Stripe token from your credit card just by using this piece of code in your shared code (PCL)
I hope this answer will help, I will try create a solution soon on a public github repo for people who wants to test it