From 8cab5af5fc05e640461f5ec55a424f608a3c3e00 Mon Sep 17 00:00:00 2001 From: clr-li <111320104+clr-li@users.noreply.github.com> Date: Wed, 27 Dec 2023 11:41:58 -0800 Subject: [PATCH] Payment types added --- app_users/models.py | 6 +++--- routers/paypal.py | 10 +--------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/app_users/models.py b/app_users/models.py index b0ad776d1..fa7e5b931 100644 --- a/app_users/models.py +++ b/app_users/models.py @@ -119,12 +119,12 @@ def add_balance(self, amount: int, invoice_id: str) -> "AppUserTransaction": """ # if an invoice entry exists try: - if len(invoice_id) > 17: + if "-" in invoice_id and "_" not in invoice_id: type = "Paypal" else: type = "Stripe" - # avoid updating twice for same invoice - return AppUserTransaction.objects.get(invoice_id=invoice_id) + # avoid updating twice for same invoice + return AppUserTransaction.objects.get(invoice_id=invoice_id) except AppUserTransaction.DoesNotExist: type = "SavedRun" pass diff --git a/routers/paypal.py b/routers/paypal.py index ff0b3da94..ca5c6c307 100644 --- a/routers/paypal.py +++ b/routers/paypal.py @@ -5,9 +5,8 @@ import requests from fastapi import APIRouter, Depends from fastapi.requests import Request -from fastapi.responses import RedirectResponse, JSONResponse, HTMLResponse +from fastapi.responses import JSONResponse from furl import furl -from starlette.datastructures import FormData from sentry_sdk import capture_exception import json @@ -44,10 +43,6 @@ def generateAccessToken(): # @see https://developer.paypal.com/docs/api/orders/v2/#orders_create def createOrder(payload: dict, uid: str): # use the cart information passed from the front-end to calculate the purchase unit details - print( - "shopping cart information passed from the frontend createOrder() callback:", - payload, - ) accessToken = generateAccessToken() url = f"{settings.PAYPAL_BASE}/v2/checkout/orders" @@ -114,9 +109,6 @@ async def request_body(request: Request): def orders(req: Request, uid: str, _payload: bytes = Depends(request_body)): # use the cart information passed from the front-end to calculate the order amount detals payload: dict = json.loads(_payload) - print( - "shopping cart information passed from the frontend orders() callback:", payload - ) jsonResponse, httpStatusCode = createOrder(payload, uid) return JSONResponse(jsonResponse, httpStatusCode)