#Sam Stripe - env variables
1 messages · Page 1 of 1 (latest)
What do you mean by this? You can access env variables in your code. The way in which you do this depends on your language. Not on Stripe.
Can you explain this paragraph on this issue?
https://github.com/stripe/stripe-cli/issues/871
When using stripe listen to forward webhook events locally, developers have to copy the webhook secret from the console into their application for verification. This is fine, but I think it would be interesting to add an additional option to this workflow.
will this webhook secret still work with an env variable set to that secret
yeah you would just have to set that environment variable after running stripe listen
I have the env variable set up but it is not working inside the stripe listen command. However it does work outside of this.
What do you mean by inside the stripe listen command? Can you share a screenshot. Not sure I understand
By inside, I mean - when the code is running inside the webhook triggered off by stripe listen forward-to....
def construct_webhook_event(request):
webhook_secret = os.environ.get('STRIPE_PRIVATE_WEBHOOK_KEY')
assert webhook_secret == 'whsec_9fdc4cfaa8fcc91bc3e777dffb279aaa016baba0db152aa16d05ab4d4fb55bd1'
signature = request.headers.get("stripe-signature")
return stripe.Webhook.construct_event(
payload=request.body, sig_header=signature, secret=webhook_secret
)
Here the assert failed when the above listen command is run. However it passes inside just running the function (outside of stripe)
Did you set the environment variable? You would have to manually do that part
Resolved - thanks it was an error in the env var.
Could you help me with something else? When sending through an payment_intent.succeeded on the cli, I seem to get two different succeeded events (and one created event)
<-- [201] POST http://certn-smb.ctf.sh:8080/webhook/stripe [evt_3LD8L5GCm62au2jT1Cd84u9I]
2022-06-21 15:46:02
<-- [500] POST http://certn-smb.ctf.sh:8080/webhook/stripe [evt_3LD8L5GCm62au2jT1aSfKN0J]
Why am I seeing two events here?
One is paymentintent succeeded and the other is charge succeeded
They're 2 different objects
A PaymentIntent uses a charge underneath the hood
Oh okay, do they use different event types?