|
@@ -15,27 +15,44 @@ from app.schema import CartSession, NowPaymentsInvoice, ShippingCostEntry, Shipp
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-def prepare_stripe_data(cart: CartSession) -> list[str, int]:
|
|
|
|
|
|
|
+def prepare_stripe_data(cart: CartSession) -> list[dict]:
|
|
|
"""Returns list of items ready for Stripe to be processed.
|
|
"""Returns list of items ready for Stripe to be processed.
|
|
|
- Each item is in the form of {price: <price_id>, quantity: <amount>}
|
|
|
|
|
|
|
+ Each item is in the form of {price_data: {...}} or {price: <price_id>, quantity: <amount>}
|
|
|
|
|
+
|
|
|
|
|
+ When using product IDs, we need to use price_data to create prices inline:
|
|
|
|
|
+ list_items = [
|
|
|
|
|
+ {
|
|
|
|
|
+ 'price_data': {
|
|
|
|
|
+ 'currency': 'usd',
|
|
|
|
|
+ 'product': 'prod_XYZ',
|
|
|
|
|
+ 'unit_amount': 2000 # amount in cents
|
|
|
|
|
+ },
|
|
|
|
|
+ 'quantity': 1
|
|
|
|
|
+ }
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ When using price IDs:
|
|
|
list_items = [
|
|
list_items = [
|
|
|
{
|
|
{
|
|
|
- # Provide the exact Price ID (for example, pr_1234) of the product you want to sell
|
|
|
|
|
- 'price': ,
|
|
|
|
|
- 'quantity': 0
|
|
|
|
|
|
|
+ 'price': 'price_XYZ',
|
|
|
|
|
+ 'quantity': 1
|
|
|
}
|
|
}
|
|
|
]
|
|
]
|
|
|
"""
|
|
"""
|
|
|
list_items = []
|
|
list_items = []
|
|
|
|
|
|
|
|
for item in cart.items.values():
|
|
for item in cart.items.values():
|
|
|
- item = {
|
|
|
|
|
- "price": item.product_id,
|
|
|
|
|
|
|
+ # Create inline price data using the product ID
|
|
|
|
|
+ item_data = {
|
|
|
|
|
+ "price_data": {
|
|
|
|
|
+ "currency": cart.meta.currency.lower(),
|
|
|
|
|
+ "product": item.product_id,
|
|
|
|
|
+ "unit_amount": int(item.price * 100 / item.quantity), # Convert to cents
|
|
|
|
|
+ },
|
|
|
"quantity": item.quantity,
|
|
"quantity": item.quantity,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- list_items.append(item)
|
|
|
|
|
|
|
+ list_items.append(item_data)
|
|
|
|
|
|
|
|
return list_items
|
|
return list_items
|
|
|
|
|
|