Spaces:
Running
Running
File size: 2,525 Bytes
9365a43 5358f12 2d73b8f 9365a43 2d73b8f 9365a43 2902d8c 9365a43 2d73b8f 18b664c 2d73b8f 9365a43 2d73b8f 58e9d96 1b1c3e0 2d73b8f 368095c 2d73b8f 027196c 2d73b8f 58e9d96 2d73b8f 047ff2c 027196c 047ff2c 9365a43 2d73b8f d2c8a72 027196c ce612b0 027196c 2d73b8f 027196c 2d73b8f 027196c 67828a3 027196c ce612b0 027196c 2d73b8f 9365a43 2d73b8f 7b23511 ce612b0 |
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
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(30)
except Exception as e:
print("Excepción es: ", e)
try:
event_data = event['data']['object']
except Exception as e:
print("Excepción183 es: ", e)
event_type = event['type']
print("Voy a imprimir el event type:")
print(event_type)
if event_type == 'payment_intent.succeeded':
print('PAYMENT182')
print(event_data)
print("Ready")
print("Created:")
print(event_data['created'])
print("Id")
print(event_data['id'])
print("Payment_method:")
print(event_data['payment_method'])
print("Customer:")
cus = event_data['customer']
print(cus)
if event_type == 'checkout.session.completed':
print('CHECKOUT182')
print(event_data)
print("Ready")
print("Payment Status:")
print(event_data['payment_status'])
print("Metadata:")
print(event_data['metadata'])
cus_id = event_data['metadata']['stripe_customer_id']
print("Metadata Cusid:")
print(cus_id)
imagenes = event_data['metadata']['imagenes']
print("Imagenes")
print(imagenes)
print("El tipo de dato de imagenes es: ", type(imagenes))
cus = event_data['customer']
print("Customer directo:")
print(cus)
herramientas.registrar_evento(cus_id, int(imagenes))
else:
print(f'unhandled event: {event_type}')
return {"status": "success"} |