'Can an ASP.NET application use Stripe.net with multiple API keys?
I'm working on an ASP.NET Core 3.1 solution that uses Stripe.net to take credit card payments from users. (The Stripe.net Nuget package version is 35.3.0).
When a user submits their order details to the MVC controller, the C# code ensures that the StripeConfiguration.ApiKey property has the correct value, then calls PaymentIntentService.CreateAsyc to create the PaymentIntent object and process the payment - this is all working fine, and payments are being processed as expected.
However, my client has set up a second Stripe account with a separate set of API keys - this is because they now have two separate sets of products (Set 1 and Set 2) which, for business reasons, must be handled by separate Stripe accounts. The application front-end ensures that users may only populate their basket with products from one or the other set of products, and not a combination of both.
However, this now means that the correct Stripe API key will depend on which type of products the user has in their basket.
The problem is that StripeConfiguration.ApiKey property is static - so if one user starts the Stripe checkout for items from Set 1, the API key might get overwritten by a second user simultaneously starting their Stripe checkout for an item from Set 2.
Am I missing something here? Or is the Stripe API deliberately designed so that a single application may only have a single API key? If so, is there any workaround possible for my scenario?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
