fixed pydantic input validation error
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Failing after 2m58s
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been skipped
Run linting on the backend code / Build (pull_request) Failing after 2m20s
Run testing on the backend code / Build (pull_request) Failing after 2m25s
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Failing after 2m58s
Build and deploy the backend to staging / Deploy to staging (pull_request) Has been skipped
Run linting on the backend code / Build (pull_request) Failing after 2m20s
Run testing on the backend code / Build (pull_request) Failing after 2m25s
This commit is contained in:
@@ -21,3 +21,6 @@ class Environment :
|
||||
# Load paypal secrets
|
||||
paypal_id_sandbox = os.environ['PAYPAL_ID_SANDBOX']
|
||||
paypal_key_sandbox = os.environ['PAYPAL_KEY_SANDBOX']
|
||||
paypal_id_prod = os.environ['PAYPAL_ID_PROD']
|
||||
paypal_key_prod = os.environ['PAYPAL_KEY_PROD']
|
||||
|
||||
|
||||
@@ -43,7 +43,6 @@ class OrderRequest(BaseModel):
|
||||
items: list[Item] = Field(default_factory=list)
|
||||
total_price: float = None
|
||||
total_credits: int = None
|
||||
supabase_client: SupabaseClient
|
||||
|
||||
|
||||
# @field_validator('basket')
|
||||
@@ -69,7 +68,7 @@ class OrderRequest(BaseModel):
|
||||
return v
|
||||
|
||||
|
||||
def load_items_and_price(self):
|
||||
def load_items_and_price(self, supabase: SupabaseClient):
|
||||
# This should be automatic upon initialization of the class
|
||||
"""
|
||||
Loads item details from database and calculates the total price as well as the total credits to be granted.
|
||||
@@ -78,7 +77,7 @@ class OrderRequest(BaseModel):
|
||||
self.total_price = 0
|
||||
self.total_credits = 0
|
||||
for basket_item in self.basket:
|
||||
item = self.supabase_client.get_item(basket_item.item_id, self.currency)
|
||||
item = supabase.get_item(basket_item.item_id, self.currency)
|
||||
self.items.append(item)
|
||||
self.total_price += item.unit_price * basket_item.quantity # increment price
|
||||
self.total_credits += item.unit_credits * basket_item.quantity # increment credit balance
|
||||
@@ -195,6 +194,7 @@ class PaypalClient:
|
||||
def order(
|
||||
self,
|
||||
order_request: OrderRequest,
|
||||
supabase_client: SupabaseClient,
|
||||
return_url_success: str,
|
||||
return_url_failure: str
|
||||
):
|
||||
@@ -209,7 +209,7 @@ class PaypalClient:
|
||||
"""
|
||||
|
||||
# Fetch details of order from mart database and compute total credits and price
|
||||
order_request.load_items_and_price()
|
||||
order_request.load_items_and_price(supabase=supabase_client)
|
||||
|
||||
# Prepare payload for post request to paypal API
|
||||
order_data = {
|
||||
|
||||
@@ -5,6 +5,7 @@ from fastapi.responses import RedirectResponse
|
||||
|
||||
from .payment_handler import PaypalClient, OrderRequest
|
||||
from ..supabase.supabase import SupabaseClient
|
||||
from ..structs.shop import BasketItem
|
||||
from ..cache import CreditCache, make_credit_cache_key
|
||||
|
||||
|
||||
@@ -22,11 +23,11 @@ logger = logging.getLogger(__name__)
|
||||
# TODO: add the return url in the API payload to redirect the user to the app.
|
||||
@router.post("/orders/new")
|
||||
def create_order(
|
||||
user_id: str = Query(...),
|
||||
basket: list = Query(...),
|
||||
currency: str = Query(...),
|
||||
return_url_success: str = Query('https://anydev.info/orders/success'),
|
||||
return_url_failure: str = Query('https://anydev.info/orders/failed')
|
||||
user_id: str = Query(...),
|
||||
currency: str = Query(...),
|
||||
return_url_success: str = Query('https://anydev.info/orders/success'),
|
||||
return_url_failure: str = Query('https://anydev.info/orders/failed'),
|
||||
basket: list[BasketItem] = Body(...),
|
||||
):
|
||||
"""
|
||||
Creates a new PayPal order.
|
||||
|
||||
Reference in New Issue
Block a user