django-payments icon indicating copy to clipboard operation
django-payments copied to clipboard

How to pass an item reference to the `Payment.get_purchased_items` method?

Open rtdev-com opened this issue 1 year ago • 1 comments

Can someone help me understand how to pass some sort of item reference to Payment.get_purchased_items?

  1. The get_purchased_items method does not take any input arguments except for self
  2. The BasePayment class 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.

rtdev-com avatar Mar 27 '24 15:03 rtdev-com

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.

WhyNotHugo avatar Aug 23 '24 08:08 WhyNotHugo

Thank you @WhyNotHugo.

rtdev-com avatar Oct 16 '24 23:10 rtdev-com