Reputation: 10230
I'm using stripe-node library. I need to interact with several stripe accounts, each one with their own secret key. What's the best way to do that?
Is there a way to specify the secret key for each request, like:
stripe.charges.create({
auth: secret_key_1,
...
});
stripe.charges.create({
auth: secret_key_2,
...
});
One workaround I thought of is simply instantiating a separate stripe instance for each account.
Upvotes: 1
Views: 2573
Reputation: 107
You can send apiKey in option object
create(
params?: ChargeCreateParams,
options?: RequestOptions
)
You can call
stripe.charges.create({
{}, // ChargeCreateParams
{
apiKey: 'YOUR_API_KEY'
}
});
Upvotes: 0
Reputation: 4048
As it states in the documentation you can set the api_key
on a per-request basis like this:
stripe.charges.retrieve("ch_1AqjPcJWCk4FIh3mWQ3Hvmvi", {
api_key: "sk_test_nra5nLtBVqMvXCoYROwWQFRG"
});
The only other alternative is to have multiple instances as already mentioned in other answers.
Upvotes: 3
Reputation: 32127
You can call stripe.setApiKey
before each request.
stripe.setApiKey(secret_key_1);
stripe.charges.create({
...
});
stripe.setApiKey(secret_key_2);
stripe.charges.create({
...
});
Upvotes: 0