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.
The installation process for django-paypal-plus is straightforward and consists of two main steps:
-
Install the package in your virtual environment using pip:
pip install django-paypal-plus
-
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
1. Django >= 2.2
2. Python >= 3.8
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>
)
paypal_wrapper.capture_order(resource_id)
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 2024 - Tim Burg for Particulate Solutions GmbH, under MIT license.