#Ricardo Caterino Polini
1 messages ยท Page 1 of 1 (latest)
hello! can you share your code for processing webhooks?
make sure you remove any api keys before sharing
@api.route('/webhook', methods=['POST'])
def webhook():
event = None
payload = request.data
sig_header = request.headers['STRIPE_SIGNATURE']
# This is your Stripe CLI webhook secret for testing your endpoint locally.
endpoint_secret = ' '
print("evento de webhoooks")
try:
event = stripe.Webhook.construct_event(
payload, sig_header, endpoint_secret
)
except ValueError as e:
# Invalid payload
raise e
except stripe.error.SignatureVerificationError as e:
# Invalid signature
raise e
# Handle the event
if event['type'] == 'charge.captured':
charge = event['data']['object']
elif event['type'] == 'charge.succeeded':
charge = event['data']['object']
ejemplo = charge.billing_details.email
user = User.query.filter_by(email = ejemplo).first()
pay = Pay(cliente_id = cliente.id, amount = charge.amount / 100 )
#cliente.corrienteDePago = True
db.session.add(pay)
db.session.commit()
# ... handle other event types
else:
print('Unhandled event type {}'.format(event['type']))
return jsonify(success=True)
๐ Taking over this thread from alex, catching up now
Does your webhook secret start with whsec_?
Are you listening to the webhook in local or using endpoint?
You can go to https://dashboard.stripe.com/webhooks > Select your endpoint > Look for "Signing secret" > Click "Reveal" to get the webhook secret
thanks...
now it's working
another error but i can handle it jajaja have a good day and nice weekend
No problem! Happy to help ๐
other ask....
How can I send the customer data in the
login attempt for checkout? this in order for the webhook to return the customer data to correctly save the payment information
Which integration are you using? Payment Element or Checkout Session?
I think it's checkout session
You can set the customer data such as ID in the metadata when creating a checkout session: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-metadata
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
metadata will be returned in event