Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django & PayPal integration

Tags:

I am designing a website in Python (using Django), and I need to sell things through it.

Can somebody help me with the source code to integrate the paypal-pro (do-direct payment) or else paypal-standard (express checkout)?

like image 935
GS. Avatar asked Apr 26 '10 14:04

GS.


People also ask

What is the Django used for?

What is Django? Django is a high-level Python web framework that enables rapid development of secure and maintainable websites. Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel.

Is Django same as Python?

Python and Django are intertwined but not the same. Python is a programming language that's used for many different applications: artificial intelligence, machine learning, desktop apps, etc. On the other hand, Django is a Python framework for full-stack web application development and server development.

Is Django backend or frontend?

Django and Ruby on Rails — two of the leading backend web development frameworks and both open source — have been on the scene since the mid-2000s. They're no longer the trendy young bucks in web development, but they are still the seventh and 11th most-loved web frameworks respectively.

What Django means?

The name Django is boy's name of Romani origin meaning "I awake". Django — the D is silent as most everyone now knows — the nickname of the great Belgian-born jazz guitarist Django (originally Jean Baptiste) Reinhardt, makes a dynamic musical choice for any jazz aficionado.


2 Answers

You might want to try django-paypal, there's even a tutorial right there on the front page.

like image 112
Dominic Rodger Avatar answered Sep 25 '22 03:09

Dominic Rodger


paypal.standard.ipn

PayPal API Generates a Button which will call its API through paypal.standard.ipn.

For API Integration you have to follow below given steps:

Install django-paypal:

pip install django-paypal 

Update settings.py file:

INSTALLED_APPS = [     'paypal.standard.ipn', ]  PAYPAL_RECEIVER_EMAIL = 'XXXXX' PAYPAL_TEST = True 

Write Email address of Receiver. PAYPAL_TEST = True means you want a Test API payment. You can write "False" for Original payment API.

Run command:

python manage.py migrate  

In 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'),* 

In views.py:

from django.conf import settings from django.urls import reverse from django.shortcuts import render, get_object_or_404 from paypal.standard.forms import PayPalPaymentsForm   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}) 

Follow video tutorial for django-code given in reference.

In payment_process.html:

{{ form.render }} 

For calling API you have request for /payment_process/. It will generate a button on HTML which calls PayPal API for transaction. Further process will be done on PayPal end, Login or Card Payment.

like image 38
Harshdeep Khatke Avatar answered Sep 22 '22 03:09

Harshdeep Khatke