No project description provided
Project description
epay-gateway-django
Chargily ePay Gateway (Django Package)
This Plugin is to integrate ePayment gateway with Chargily easily.
- Currently support payment by CIB / EDAHABIA cards and soon by Visa / Mastercard
- This repo is recently created for Django plugin, If you are a developer and want to collaborate to the development of this plugin, you are welcomed!
Requirements
- Python 2.7 or higher.
- Django 1.11 or higher.
- API Key/Secret from ePay by Chargily dashboard for free.
- Our package for python.
Installation
Using pip
pip install chargily-epay-gateway-django-plugin
or pipenv
pipenv install chargily-epay-gateway-django-plugin
Quick start
1- Make sure to secure your credentials by setting up the Environment Variables or using .env
file.
2- Load CHARGILY_APP_KEY
and CHARGILY_APP_SECRET
environment variables in settings.py file.
Usage
1- Make Payment:
- You can use class or function based view to make a payment
- If you are using
POST
method, make sure to disable Django's CSRF validation.
- Class based View Example
- In
views.py
:
from django.shortcuts import render
from chargily_epay_gateway_django.views import InvoiceView
from chargily_epay_gateway_django.forms import InvoiceForm # You can customize this form if you like
class MakePayment(InvoiceView):
def get(self, request):
form = InvoiceForm()
context = {
'form': form,
}
return render(request, 'payment.html', context)
def post(self, request):
form = InvoiceForm(data=request.POST)
context = {
'form': form,
'data': None,
'errors': None,
}
if form.is_valid():
invoice = self.make_payment(**form.data)
response = self.load_invoice(invoice.content)
if invoice.status_code == 201:
context['data'] = response['checkout_url']
else:
context['errors'] = [value for value in response['errors'].items()]
return render(request, 'payment.html', context)
Output example:
-
Wrong inputs
-
Correct inputs
You can use
CSRFExemptInvoiceView
instead ofInvoiceView
if you want to ignore csrf validation.
- in
payment.html
:
<form method="POST" >
{% csrf_token %}
{{form.as_p}}
<input type="submit" value="MAKE PAYMENT">
<!-- Handle Data -->
{% if data %}
<p><a target='__blank' href='{{data}}'>{{data}}</a></p>
{% endif %}
<!-- Handle Errors -->
{% if errors %}
<ul>
{% for error in errors %}
<li>{{error}}</li>
{% endfor %}
</ul>
{% endif %}
</form>
- If you want to return JSON instead, you can use it like this:
from django.http import JsonResponse
from chargily_epay_gateway_django.views import InvoiceView
class MakePayment(InvoiceView):
def post(self, request):
invoice = self.make_payment( # You can use InvoiceForm
client='Client Name',
client_email='Client Email',
invoice_number='Invoice ID',
amount='Amount',
discount='Discount',
back_url='https://example.com/',
webhook_url='https://example.com/webhook/',
mode="CIB",
comment='for integration test',
)
return JsonResponse(self.load_invoice(invoice.content))
- Function based view
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from chargily_epay_gateway.api import make_payment
@csrf_exempt
def invoice(request):
if request.method != 'POST':
return JsonResponse({'message': 'Method {} not allowed'.format(request.method)}, status=403)
response = make_payment( # You can use InvoiceForm
client='Client Name',
client_email='Client Email',
invoice_number='Invoice ID',
amount='Amount',
discount='Discount',
back_url='https://example.com/',
webhook_url='https://example.com/webhook/',
mode="CIB",
comment='for integration test',
)
return JsonResponse(response.json(), status=response.status_code)
2- Webhook Usage:
from django.http import JsonResponse
from chargily_epay_gateway_django.views import WebhookView
from chargily_epay_gateway.utils import signature_is_valid
class ChargilyReceiver(WebhookView):
def post(self, request):
valid_signature = signature_is_valid(self.SECRET_KEY, request)
if valid_signature:
...
# Do whatever you want
return JsonResponse({}, status=200)
3- Don't forget to register your views in urls.py
from django.urls import path
from your_app.views import MakePayment, ChargilyReceiver
urlpatterns = [
path('payment/', MakePayment.as_view(), name='payment'),
path('webhook/', ChargilyReceiver.as_view(), name='webhook'),
]
Configurations
- Available Configurations
key | description | redirect url | process url |
---|---|---|---|
CHARGILY_APP_KEY | must be string given by organization | required | required |
CHARGILY_APP_SECRET | must be string given by organization | required | required |
back_url | must be string and valid url | required | not required |
webhook_url | must be string and valid url _ | required | required |
mode | must be in CIB,EDAHABIA | required | not required |
invoice_number | string or int | required | not required |
client_name | string | required | not required |
clientEmail | must be valid email This is where client receive payment receipt after confirmation | required | not required |
amount | must be numeric and greather or equal than 75 | required | not required |
discount | must be numeric and between 0 and 99 (discount in %) | required | not required |
description | must be string_ | required | not required |
Notice
- If you faced Issues Click here to open one
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for chargily_epay_gateway_django_plugin-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3182dc8e97014c9eb167db90458fd8f349b6cb8bad649b6ca11e9e5b68c9de31 |
|
MD5 | 102efb0446bbddfa81252237383643f4 |
|
BLAKE2b-256 | 97df664abbae87149045900b988db574008cd20c06c3a8e666e17a68c0015ea4 |