jazzband / django-payments

Universal payment handling for Django.
https://django-payments.readthedocs.io
Other
1.05k stars 282 forks source link

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

Open rtdev-com opened 6 months ago

rtdev-com commented 6 months ago

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.

WhyNotHugo commented 1 month ago

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.