Skip to content

Instantly share code, notes, and snippets.

@jjgriff93
Created March 5, 2018 20:00
Show Gist options
  • Select an option

  • Save jjgriff93/bb8915d28d349de6a5a9cd16be0ff761 to your computer and use it in GitHub Desktop.

Select an option

Save jjgriff93/bb8915d28d349de6a5a9cd16be0ff761 to your computer and use it in GitHub Desktop.
Stripe API - add new product subscriptions
//Register user for Product Plan in Stripe
StripeConfiguration.SetApiKey(StripeAPIKey);
var items = new List<StripeSubscriptionItemOption> {
//Subscribe to Stripe plan with corresponding ID - ENSURE YOUR STRIPE PRICING PLAN ID IS IDENTICAL TO THE APIM PRODUCT ID
new StripeSubscriptionItemOption {PlanId = Request.QueryString["productId"]}
};
var options = new StripeSubscriptionCreateOptions
{
Items = items,
};
var service = new StripeSubscriptionService();
//Get user's Stripe ID by retrieving object from user store
var user = await UserManager.FindByIdAsync(Request.QueryString["userId"]);
//Create a plan subscription for that user
StripeSubscription subscription = service.Create(user.StripeId, options);
if (subscription.Status == "active")
{
//Register user for product in APIM
using (var client = new HttpClient())
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment