django-payments
django-payments copied to clipboard
Add example
Thank you
Hi Please show working example
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
#281 added a dummy test app that should also serve as an example.