Implement stripe subscriptions with .net framework 4.7.2 and not .net core

Viewed 831

I want to implement stripe subscription for a service i am offering on my website. The code on the stripe documentation uses .netcore but my web application is in .net framework and i do not want to change to .net core because my hosting service provider does not support .net core. Is there a way of implementing subscriptions with stripe using .net framework? - How i want this to work is that when a user logs in they can click a subscription page which will allow them to select the service they want and then they input their card details - when they do this they will be charged on the very day this request happen and every month on that day. I have looked at various examples but i cannot get my head around how I would do this in code.

1 Answers

You could use the Stripe Javascript API with Stripe Checkout. You just have to enable Stripe Checkout in the dashboard:

https://stripe.com/docs/payments/checkout/client#:~:text=1%20Enable%20Checkout%20Dashboard,feel%20of%20your%20checkout%20page.

Then when you create a new product (which can be a subscription) and assign a price, you will have the option to create a Checkout code snippet. These snippets are quite generic but aren't too difficult to modify to sure your needs.

Edit:

After checking the Stripe.Net nuget page, the latest version is still compatible with .Net Framework 4.6.1, so any code samples you see using .net core are still applicable to .Net Framework 4.6.1+

For example:

StripeConfiguration.ApiKey = "sk_test_51HAxQFH39e4DIylVXXTGZgYZyEBhV0jLZ0AL4oQ1vUt8kTC5nB5sIzx6VcmsG41JbK8SA6JWDb7r3OfsFhO5omdD009OQF1OOQ";

var service = new ProductService();
service.Get("prod_HkaQiWW1JbzNyc");

will work in .net core and any .Net Framework 4.6.1+ application or website.

https://stripe.com/docs/api

Related