django-payments
django-payments copied to clipboard
How to pass an item reference to the `Payment.get_purchased_items` method?
Can someone help me understand how to pass some sort of item reference to Payment.get_purchased_items?
- The
get_purchased_itemsmethod does not take any input arguments except forself - The
BasePaymentclass does not have any item references either
def get_purchased_items(self) -> Iterable[PurchasedItem]:
# do we have item info here?
item = get_item_from_somewhere()
# Return items that will be included in this payment.
yield PurchasedItem(
name=item.name,
sku=item.sku,
quantity=1,
price=item.price,
currency='USD',
)
This part is unclear to me from reading the documentation since the docs just hard code an item.
You need to subclass BasePayment: https://django-payments.readthedocs.io/en/latest/payment-model.html
Your Payment class can have data for the items itself, or can have a ForeignKey to a Purchase model or whatever you're using.
Thank you @WhyNotHugo.