Created
March 5, 2018 20:00
-
-
Save jjgriff93/bb8915d28d349de6a5a9cd16be0ff761 to your computer and use it in GitHub Desktop.
Stripe API - add new product subscriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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