How can I use different stripe secret key for each user?

Hi guys!
I am using stripity_stripe for accept a payment in my backend server.

But I don’t want to set a api_key in config.exs. I want to use each user’s stripe secret key for their account.
Is there anyway to make a request to stripe api using each user’s secret key?

So your users will provide you with this key? You want to store it somewhere and use it in stripity stripe for each call?

Sorry I didn’t make it clear.
User can save their key in database.
So in my server, I can retrieve like user.stripe_api_key.

Yes key will be saved in database.

I think the way the library works sets the API key at compile time… I don’t know of a good way to do what you’re asking without forking and modifying the code. Someone on here more knowledgeable than me may chime in.

Perhaps you could consider making manual API calls?

As a side note, using a library like cloak to encrypt your keys is a good idea. I’ve used it before and it was quite easy to set up and use.

3 Likes

Thanks for suggestion
I missed the point that I have to encrypt the keys before save it.
Thanks!

I definitely would just to have another layer of protection. Good luck!

I found a solution.

I can pass Stripe.Options for any request. Something like this.

Stripe.Customer(%{email: "john@example.com"}, api_key: user.stripe_secret_key)
1 Like