Django Rave
Project Description
This project provides Django integration for Flutterwave Rave Card payments and subscriptions.
Current functionality:
- Allow users to make payments (once off and subscription)
- Create payment buttons which launch Rave payment modals
- Maintain a transaction history linked to users
Requirements
- Python >= 3.6
- Django >= 2.0
Installation
pip install djangorave
Setup
Add "djangorave" to your INSTALLED_APPS
Run Django migrations:
manage.py migrate
Add the following to your settings.py:
RAVE_PRODUCTION_PUBLIC_KEY = "your key"
RAVE_PRODUCTION_SECRET_KEY = "your key"
RAVE_SANDBOX_PUBLIC_KEY = "your key"
RAVE_SANDBOX_SECRET_KEY = "your key"
RAVE_SANDBOX = True
The above config will ensure djangorave uses your Rave sandbox. Once you are
ready to go live, set RAVE_SANDBOX = False
Add djangorave to your urls.py:
path("djangorave/", include("djangorave.urls", namespace="djangorave"))
Add the following url as a webhook in your Rave dashboard. This will be used by
Rave to POST payment transactions to your site:
http://yoursite.com/djangorave/transaction/
Note: while in development, a tool like ngrok (or similar) may prove useful.
Usage
djangorave provides two models, namely:
- The
DRPaymentTypeModelallows you to createonce offorrecurringpayment types. When creating arecurringpayment type, ensure thepayment_planfield corresponds to the RavePlan ID. - The
DRTransactionModelcreates transactions when Rave POSTS to the above mentioned webhook url. This provides a history of all transactions (once off or recurring), linked to the relevantDRPaymentTypeModelanduser.
A payment button can be created as follows:
- Create a new
PaymentTypeusing the django admin. - In the view where you wish the button to appear, add the above created
PaymentTypeto your context, eg:
from djangorave.models import DRPaymentTypeModel
class SignUpView(TemplateView):
"""Sign Up view"""
template_name = "my_payment_template.html"
def get_context_data(self, **kwargs):
"""Add payment type to context data"""
kwargs = super().get_context_data(**kwargs)
kwargs["pro_plan"] = DRPaymentTypeModel.objects.filter(
description="Pro Plan"
).first()
return kwargs
- In your template, add your button wherever you wish for it to appear as follows:
{% include 'djangorave/pay_button.html' with payment_model=pro_plan %}
Note: You can add multiple buttons to a single template by simply adding multiple
plans to your context data and then including each of them with their own include
tag as above.
- Add the following script to your django base template (or anywhere in your template heirarchy that ensures it is loaded before your payment buttons):
<script src="{% static 'djangorave/js/payment.js' %}"></script>
Button Styling
The following css classes are available for styling your payment buttons:
rave-pay-btnwill apply to all buttons.rave-subscription-btnwill apply to recurring payment types (ie: those with apayment_plan).rave-onceoff-btnwill apply to once off payment types (ie: those without apayment_plan).
Transaction Detail Page
Following a user payment, they will be redirected to the transaction detail page
located at /djangorave/<str:reference>/
A default transaction detail template is already available, however if you want
to override it, you may do so by creating a new template in your root
templates directory, ie: /templates/djangorave/transaction.html
You will have access to {{ transaction }} within that template.
Development
If you wish to contribute to the project, there is an example app that demonstrates general usage.
Running the example:
git clone https://github.com/bdelate/django-rave.git
cd django-rave
make build
make migrate
make import
make dup
There is a section at the bottom of django-rave/example/example/settings.py. Ensure the values are set accordingly:
RAVE_PRODUCTION_PUBLIC_KEY = "your key"
RAVE_PRODUCTION_SECRET_KEY = "your key"
RAVE_SANDBOX_PUBLIC_KEY = "your key"
RAVE_SANDBOX_SECRET_KEY = "your key"
RAVE_SANDBOX = True
Flutterwave Rave requires payments to be associated with users who have an email address. Therefore, create and login with a new django user or use the existing user already generated following the above import command:
username: testuser
password: secret
Navigate to http://localhost:8000/
Release files for djangorave 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| djangorave-0.1.2.tar.gz | 13.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| djangorave-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.0 kB
Release files / djangorave-0.1.2.tar.gz
| Download URL | djangorave-0.1.2.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
58ec9198ed45fefcd300b9f0934663cd585639cb622aba612bf0b102f34b4369
|
|
BLAKE2b-256 checksum How to use checksums |
9b5c355c0789c92179a00a27f59c30a3be3e574ee72a64e05e9c3ea22118f599
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.3 CPython/3.8.2 Darwin/18.7.0
|
Release files / djangorave-0.1.2-py3-none-any.whl
| Download URL | djangorave-0.1.2-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cf33b79d4dc6f5df1c62ed1f19ff0c1790c95642e65cc5744c2b7a5fd2e53d5d
|
|
BLAKE2b-256 checksum How to use checksums |
5eeabc5db157a9ba744f2a9fd2f6c61a29a8132eb1bd2f219bf4f5fbbf62e15a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.3 CPython/3.8.2 Darwin/18.7.0
|