dj-stripe / dj-stripe

dj-stripe automatically syncs your Stripe Data to your local database as pre-implemented Django Models allowing you to use the Django ORM, in your code, to work with the data making it easier and faster.
https://dj-stripe.dev
MIT License
1.56k stars 476 forks source link

How do I use the secret and public keys in settings when configured from admin? #1956

Closed rsevs3 closed 9 months ago

rsevs3 commented 10 months ago

I have tried to find the answer to this, but I am just going around in circles.

When I configure a test key in settings.py, I get some info saying:

?: (djstripe.I002) Your keys are defined in the settings files and are also in the admin. You can now add and manage them directly from the django admin. HINT: We suggest adding STRIPE_TEST_SECRET_KEY and STRIPE_LIVE_SECRET_KEY directly from the Django Admin. And removing them from the settings files.

If I then remove it from settings.py and put the keys in the admin panel that message clears as expected, but then the following returns blank:

djstripe_settings.djstripe_settings.STRIPE_PUBLIC_KEY

Can anyone tell me what I am doing wrong? How do I use these keys when they are configured in the admin panel? I know that I could query the database through the model, but this does not seem like the correct solution.

In the documentation, I see that the keys are still included in the settings.py file.

If I still need to have the keys in the settings.py file, what is the point of having them in the admin panel as well? I am still learning python, so apologies if this is something that should be obvious, I do find the documentation to be quite sparse.

wale-cyberpunk commented 10 months ago

Same issue here. I couldn't find anything in their documentation.

arnav13081994 commented 9 months ago

@rsevs3 @wale-cyberpunk You would need to query the APIKey model to get the keys. This might not seem like a good approach if you have only 1 key. Stripe allows for multiple keys and this solution scales well as the number of keys scale