File size: 1,678 Bytes
c5c9df8
 
 
 
 
910787d
c5c9df8
 
 
b0fc5a9
 
 
 
99fa7ef
9abf8ba
 
c5c9df8
 
 
 
 
 
99fa7ef
 
d233859
910787d
 
 
 
99fa7ef
c5c9df8
 
 
6cf88b8
 
 
d233859
c5c9df8
9c8bf93
 
 
92762ca
a05ca57
 
 
 
 
 
50ad0d8
 
 
c5c9df8
 
 
 
50ad0d8
 
 
 
 
 
9c8bf93
c5c9df8
50ad0d8
a05ca57
 
c5c9df8
 
a05ca57
 
 
 
 
c5c9df8
 
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
import os
import time
import stripe
import uvicorn
from fastapi import FastAPI, Request, Header
import sulkuPypi

app = FastAPI()

#Local on Windows.
#stripe.api_key = os.environ["STRIPE_KEY"]
#API_KEY secret.
stripe.api_key = os.getenv("STRIPE_KEY")
webhook_secret = os.getenv("STRIPE_WEBHOOK_SECRET")

string_key = stripe.api_key
# This is a terrible idea, only used for demo purposes!
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)):
    
    #Local on Windows
    #webhook_secret = os.environ["STRIPE_WEBHOOK_SECRET"]
    
    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']
    # print("Ésto es el event data: ")
    # print(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)