From bbb7e17300bbda4ade2a6aefb16d632218e405e5 Mon Sep 17 00:00:00 2001 From: clr-li <111320104+clr-li@users.noreply.github.com> Date: Sat, 18 Nov 2023 16:30:51 -0800 Subject: [PATCH] Integrated Paypal in UI --- routers/paypal.py | 8 +- templates/account.html | 151 ++++++++++++++++++++++++++++++++-- templates/add_on_credits.html | 4 +- templates/create_payment.html | 111 ------------------------- 4 files changed, 149 insertions(+), 125 deletions(-) delete mode 100644 templates/create_payment.html diff --git a/routers/paypal.py b/routers/paypal.py index a5a0dc30a..53f83f6ba 100644 --- a/routers/paypal.py +++ b/routers/paypal.py @@ -59,7 +59,7 @@ def createOrder(payload, uid): "currency_code": "USD", "value": payload["price"], }, - "custom_id": uid + "," + str(100), + "custom_id": uid + "," + str(int(payload["price"]) * 100), }, ], } @@ -123,7 +123,6 @@ def orders(req: Request, uid: str, _payload: bytes = Depends(request_body)): @router.post("/__/paypal/orders/{orderID}/capture") def capture(req: Request, orderID: str): - print("orderiddd", orderID) jsonResponse, httpStatusCode = captureOrder(orderID) return JSONResponse(jsonResponse, httpStatusCode) @@ -136,8 +135,6 @@ def create_payment(request: Request): @router.post("/__/paypal/webhook", status_code=200) def create_webhook(request: Request, _payload: bytes = Depends(request_body)): - print("initial payload", _payload) - print("request.headers", request.headers) # Verify accessToken = generateAccessToken() headers = { @@ -146,7 +143,6 @@ def create_webhook(request: Request, _payload: bytes = Depends(request_body)): } payload: dict = json.loads(_payload) - print("payload", payload) data = { "transmission_id": request.headers["paypal-transmission-id"], "transmission_time": request.headers["paypal-transmission-time"], @@ -156,7 +152,6 @@ def create_webhook(request: Request, _payload: bytes = Depends(request_body)): "webhook_id": settings.PAYPAL_WEBHOOK_ID, "webhook_event": payload, } - print("data", data) response = requests.post( f"{settings.PAYPAL_BASE}/v1/notifications/verify-webhook-signature", @@ -165,7 +160,6 @@ def create_webhook(request: Request, _payload: bytes = Depends(request_body)): ) response.raise_for_status() response = response.json() - print("response", response) if response["verification_status"] != "SUCCESS": capture_exception(Exception("PayPal webhook verification failed")) return JSONResponse({"status": "failure"}) diff --git a/templates/account.html b/templates/account.html index 89cac26d4..71597cd16 100644 --- a/templates/account.html +++ b/templates/account.html @@ -57,17 +57,27 @@

Remaining Credits: {{ humanize.intcomma(user_credits) }}

Buy Credits

- Payments processed via Stripe. - Pay via PayPal or Venmo instead. -
-
+ Payments processed via + + +
+
{% for lookup_key, subscription in available_subscriptions.items() %} -
+ + {% endblock content %} \ No newline at end of file diff --git a/templates/add_on_credits.html b/templates/add_on_credits.html index 48a3be2fa..a67721d23 100644 --- a/templates/add_on_credits.html +++ b/templates/add_on_credits.html @@ -4,6 +4,6 @@
Buy a one-time top up @ 100 Credits per dollar.
- + -{% endfor %} +{% endfor %} \ No newline at end of file diff --git a/templates/create_payment.html b/templates/create_payment.html deleted file mode 100644 index 7f63d2d79..000000000 --- a/templates/create_payment.html +++ /dev/null @@ -1,111 +0,0 @@ -{% extends 'base.html' %} - -{% block content %} -
-
-

Pay with Paypal

-
-
Buy a one-time top up @ 100 Credits per dollar (minimum $10).
- - -
-
- -

- - - -
-{% endblock content %} \ No newline at end of file