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

Add example

Open matrixise opened this issue 8 years ago • 3 comments

Thank you

matrixise avatar Feb 13 '17 07:02 matrixise

Hi Please show working example

bronte2k7 avatar Dec 19 '17 12:12 bronte2k7

is there a simple working example implementation i can look at? ive followed the intro docs but i get 'LookupError: App 'payments' doesn't have a 'Payment' model.'

... in createPayment
    Payment = get_payment_model()
    
... in get_payment_model
    payment_model = apps.get_model(app_label, model_name)

but the payment model is set in the settings and assigned when i create it.

PAYMENT_HOST = 'localhost:8000'
PAYMENT_USES_SSL = False
PAYMENT_MODEL = 'payments.Payment'
PAYMENT_VARIANTS = {
    'default': ('payments.dummy.DummyProvider', {})}

payments/models.py

from decimal import Decimal

from payments import PurchasedItem
from payments.models import BasePayment

class Payment(BasePayment):

    def get_failure_url(self):
        return '/paymentfailure/'

    def get_success_url(self):
        return '/paymentsuccess/'

    def get_purchased_items(self):
        # you'll probably want to retrieve these from an associated order
        yield PurchasedItem(name='The Hound of the Baskervilles', sku='BSKV',
                            quantity=9, price=Decimal(10), currency='USD')

other/views.py

from payments import get_payment_model


def createPayment(request, username, tier_id):
   user = request.user
   tier = Tier.objects.get(id=tier_id)

   Payment = get_payment_model()
   payment = Payment.objects.create(
       variant='default',  # this is the variant from PAYMENT_VARIANTS
       description=tier.description,
       total=Decimal(tier.price),
       tax=Decimal(0),
       currency='USD',
       delivery=Decimal(10),
       billing_first_name=user.first_name,
       billing_last_name=user.last_name,
       customer_ip_address='127.0.0.1')

   context = {
       'payment': payment
   }
   # Redirect the user to your payment handling view.
   # return HttpResponseRedirect(reverse('payment.html'))
   return render(request, 'payment.html', context)

not sure what ive done wrong i havent called payments/views.py yet just trying to create the dummy payment and then redirect

jskye avatar Jun 14 '21 11:06 jskye

#281 added a dummy test app that should also serve as an example.

WhyNotHugo avatar Mar 11 '22 19:03 WhyNotHugo