WAY 2 PayPal Standard IPN
+ No PayPal app should be created in PayPal
+ You change PayPal email only
– Package must be installed
– migrate is needed – changes to DB
Django-paypal provides a PayPalPaymentsForm the class which creates a standard PayPal “Buy Now” button configured for selling a single item with no shipping.
1. Create sandbox account -for testing
2. Install
pip install django-paypal
Add to installed app in settings.py
INSTALLED_APPS = [
”’
‘paypal.standard.ipn’,
”’
]
Set PayPal attributes in settings.py
django-paypal settings
PAYPAL_RECEIVER_EMAIL = ‘[email protected]’
PAYPAL_TEST = True
Migrate
python manage.py migrate
Add to requirements.txt
django-paypal=1.1.1
3. Add URL to maine urls.py
url(r’^paypal/’, include(‘paypal.standard.ipn.urls’)),
url(r’^payment_process/$’, api_views.payment_process, name=’payment_process’ ),
url(r’^payment_done/$’, TemplateView.as_view(template_name= “pets/payment_done.html”), name=’payment_done’),
url(r’^payment_canceled/$’, TemplateView.as_view(template_name= “pets/payment_canceled.html”), name=’payment_canceled’),*
4. Create views
Or
def payment_process(request):
host = request.get_host()
paypal_dict = {
'business': settings.PAYPAL_RECEIVER_EMAIL,
'amount': '100',
'item_name': 'Item_Name_xyz',
'invoice': 'Test Payment Invoice',
'currency_code': 'USD',
'notify_url': 'http://{}{}'.format(host, reverse('paypal-ipn')),
'return_url': 'http://{}{}'.format(host, reverse('payment_done')),
'cancel_return': 'http://{}{}'.format(host, reverse('payment_canceled')),
}
form = PayPalPaymentsForm(initial=paypal_dict)
return render(request, 'pets/payment_process.html', {'form': form})
5. In payment_process.html
{{ form.render }}