Spaces:
Running
Running
File size: 1,778 Bytes
9365a43 5358f12 2d73b8f 9365a43 2d73b8f 9365a43 2902d8c 9365a43 2d73b8f 18b664c 2d73b8f 9365a43 2d73b8f 445e3fd 1b1c3e0 2d73b8f 368095c 2d73b8f bd8624f 2d73b8f 9365a43 2d73b8f 368095c 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 |
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)
time.sleep(18)
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)
if event_type == 'charge.succeeded':
print('charge succeed')
herramientas.registrar_evento(event_type)
print(event_data)
print("Ready")
time.sleep(80)
print(event_data['created'])
print(event_data['id'])
print(event_data['payment_intent'])
print(event_data['payment_method'])
print(event_data['receipt_url'])
# autorizacion = sulkuPypi.authorize(19, 'picswap')
# print("Autorización: ", autorizacion)
else:
print(f'unhandled event: {event_type}')
return {"status": "success"}
# if __name__ == '__main__':
# uvicorn.run("main:app", reload=True) |