Skip to content

ParticulateSolutions/django-paypal-plus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stable Version Code style: black Linting: Ruff

django-paypal-plus is a Django plugin that provides integration with PayPal's Orders API and Webhooks API. The package allows for the creation, management, and updating of orders through PayPal's Orders API. It also includes support for creating and listening to webhooks, enabling real-time communication between your application and PayPal's servers for capturing order events.

Installation

The installation process for django-paypal-plus is straightforward and consists of two main steps:

  1. Install the package in your virtual environment using pip:

    pip install django-paypal-plus
  2. Configure your Django project by adding the following lines to your settings file:

    # django-paypal-plus
    INSTALLED_APPS += ('django_paypal', )
    
    PAYPAL = True
    
    # Replace the following dummy values with your own PayPal API credentials. These are used in our default webhook view.
    PAYPAL_API_CLIENT_ID = "Your-PayPal-Client-ID"
    PAYPAL_API_SECRET = "Your-PayPal-Secret"
    
    # Optional settings
    PAYPAL_AUTH_CACHE_KEY = "paypal_auth_cache_key" # Default is "django-paypal-auth"
    PAYPAL_AUTH_CACHE_TIMEOUT = 3600 # Default is 600 seconds
    PAYPAL_WEBHOOK_ID = "Your-PayPal-Webhook-ID" # Default is None

Requirements

1. Django >= 2.2
2. Python >= 3.8

Usage

Create a new order

paypal_wrapper = PaypalWrapper(
	auth=APIAuthCredentials(
		client_id=django_paypal_settings.PAYPAL_API_CLIENT_ID, client_secret=django_paypal_settings.PAYPAL_API_SECRET
	)
)


paypal_order = paypal_wrapper.create_order(
	intent='sale',
	intent='CAPTURE',
	payer={'payment_method': 'paypal'},
	purchase_units=<purchase_units>,
	note_to_payer="Thank you for your purchase!",
	payment_source=paypal_api.PaymentSource(paypal=paypal_api.PayPal()),
	cancellation_url=<cancelled_url>,
	transactions=<transactions>,
	success_url=<my success url>
)

Capture an order

paypal_wrapper.capture_order(resource_id)

Listening to webhooks

By default, django-paypal-plus has a PaypalWebhookView listening to Order events. If you haven't already set up webhooks on PayPal, paypal_wrapper.setup_webhooks(<webhook_url>) will do that for you.

Copyright and license

Copyright 2024 - Tim Burg for Particulate Solutions GmbH, under MIT license.