Spaces:
Running
Running
File size: 1,868 Bytes
9365a43 5358f12 2d73b8f 9365a43 2d73b8f 9365a43 2902d8c 9365a43 2d73b8f 18b664c 2d73b8f 9365a43 2d73b8f 58e9d96 1b1c3e0 2d73b8f 368095c 2d73b8f e3c2c56 2d73b8f 58e9d96 2d73b8f 9365a43 d2c8a72 2d73b8f d2c8a72 67828a3 2d73b8f 67828a3 2d73b8f 2240d59 2d73b8f 2240d59 67828a3 ac5c2da 2d73b8f 9365a43 2d73b8f 7b23511 9365a43 2d73b8f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
import time
import stripe
from fastapi import FastAPI, Request, Header
import sulkuPypi
import globales
import herramientas
app = FastAPI()
string_key = globales.llave
# This is a terrible idea, only used for demo purposes!
app.state.stripe_customer_id = None
@app.get("/")
def start():
return {f"Status":"Deployed"}
@app.post("/webhook")
async def webhook_received(request: Request, stripe_signature: str = Header(None)):
webhook_secret = globales.webhook
data = await request.body()
print("data ready")
#print(data)
print("Construyendo el evento:")
try:
event = stripe.Webhook.construct_event(
payload=data,
sig_header=stripe_signature,
secret=webhook_secret
)
print("Evento construido...")
print(event)
print("Evento impreso")
time.sleep(60)
except Exception as e:
print("Excepción es: ", e)
event_data = event['data']['object']
event_type = event['type']
print("Voy a imprimir el event type:")
print(event_type)
print("El tipo de event type es: ", type(event_type))
if event_type == 'payment_intent.succeeded':
print('payment intent succeed')
print(event_data)
print("Ready")
print(event_data['created'])
print(event_data['id'])
#print(event_data['payment_intent'])
print(event_data['payment_method'])
#print(event_data['receipt_url'])
print("Customer:")
cus = event_data['customer']
print(cus)
herramientas.registrar_evento(cus, 999)
else:
print(f'unhandled event: {event_type}')
return {"status": "success"}
# if __name__ == '__main__':
# uvicorn.run("main:app", reload=True) |