|
|
import os |
|
|
import time |
|
|
import stripe |
|
|
import uvicorn |
|
|
from fastapi import FastAPI, Request, Header |
|
|
import sulkuPypi |
|
|
|
|
|
app = FastAPI() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stripe.api_key = os.getenv("STRIPE_KEY") |
|
|
webhook_secret = os.getenv("STRIPE_WEBHOOK_SECRET") |
|
|
|
|
|
string_key = stripe.api_key |
|
|
|
|
|
app.state.stripe_customer_id = None |
|
|
|
|
|
@app.get("/") |
|
|
def start(): |
|
|
|
|
|
print(stripe.api_key) |
|
|
print(webhook_secret) |
|
|
|
|
|
autorizacion = sulkuPypi.authorize(19, 'picswap') |
|
|
|
|
|
print("Autorización: ", autorizacion) |
|
|
|
|
|
return {f"Status":"Deployed"} |
|
|
|
|
|
@app.post("/webhook") |
|
|
async def webhook_received(request: Request, stripe_signature: str = Header(None)): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data = await request.body() |
|
|
print("Estoy imprimiendo la data del request: ") |
|
|
print(data) |
|
|
print("TERMINÉ") |
|
|
|
|
|
event = stripe.Webhook.construct_event( |
|
|
payload=data, |
|
|
sig_header=stripe_signature, |
|
|
secret=webhook_secret |
|
|
) |
|
|
event_data = event['data'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
event_type = event['type'] |
|
|
print("Voy a imprimir el event type:") |
|
|
print(event_type) |
|
|
time.sleep(2) |
|
|
|
|
|
if event_type == 'charge.succeed': |
|
|
print('charge succeed') |
|
|
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) |