django-saferpay
Saferpay integration for django
This packages uses the saferpay json api and the saferpay payment page interface. This is NOT an offical package from SIX Payment Services.
See the official saferpay json api for more information. Take also a look at test.saferpay.com.
django setup
This django package in used in cunjunction with django-oscar. It can work with other django shop systems, nothing is tied to django-oscar.
It's used with dango 1.11 but should/could work with django 2.0, 2.1.
first update settings.py:
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
INSTALLED_APPS = [
...
'saferpay',
]
...
SAFERPAY_APIURL = 'https://test.saferpay.com/api'
SAFERPAY_USERNAME = 'API_XXX'
SAFERPAY_PASSWORD = 'XXX'
SAFERPAY_CUSTOMERID = 'xxxxxx' # a number
SAFERPAY_TERMINALID = 'xxxxxx' # a number
SAFERPAY_SUCCESS_CAPTURE_URL = reverse_lazy('yourshop:payment-capture') # your callback after getting the money
SAFERPAY_SUCCESS_URL = reverse_lazy('yourshop:thank-you') # your callback after a successfull order
SAFERPAY_FAIL_URL = reverse_lazy('yourshop:payment-failed') # your callback after a failed payment
SAFERPAY_ORDER_TEXT_NR = _('Payment for the company XXX, Order nr. %s.')
SAFERPAY_FORCE_LIABILITYSHIFT_ACTIVE = False # default: False
SAFERPAY_DO_NOTIFY = True # default: False
...
You need to provide three URLs from your shop app for providing callbacks for the saferpay gateway.
SAFERPAY_SUCCESS_CAPTURE_URL- saferpay callback for a successfull capture of the amount after PAYMENTPAGE_INIT and PAYMENTPAGE_ASSERTSAFERPAY_SUCCESS_URL- everything went fine, saferpay callback to shop success urlSAFERPAY_FAIL_URL- something went wrong, saferpay callback to shop failure url
in your project urls.py:
...
url(r'', include('saferpay.urls')),
...
create the db models
./manage.py migrate
django oscar setup
If you use django oscar got to django-oscar-saferpay to procced with the setup process and see an sample usage implementation.
sample usage
You can use this code as example. You need to integrate it into your own views in the shop system.
- Intizialize the service
from saferpay.gateway import SaferpayService
from saferpay import execptions as sp_execptions
def billing_address_for_saferpay(billing_address):
"""Transform you shop billing address to
a format that saferpay uses.
Your billing_address object can be totaly differnt,
adjust it to your needs.
"""
data = {}
data['FirstName'] = billing_address.first_name
data['LastName'] = billing_address.last_name
data['Street'] = billing_address.line1
if billing_address.line2:
data['Street2'] = billing_address.line2
data['Zip'] = billing_address.postcode
data['City'] = billing_address.city
return data
def payment_init(request, order):
"""
Intizialize a new SaferpayService instance, with your
order data. Adjust the the order calls for your shop.
The init payload is created and after success you get
redirected to the saferpay PayementPage.
"""
saferpay_service = SaferpayService(
order_id=order.number, amount=order.total.incl_tax,
currency=order.total.currency, language_code=language_code
)
payload = saferpay_service.payload_init(billing_address=billing_address_data)
try:
token = saferpay_service.paymentpage_init(payload)
request.session['saferpay_token'] = token
raise RedirectRequired(saferpay_service.paymentpage_redirect().url)
except sp_execptions.GatewayError as e:
# do your rollback in case of payment failure
return redirect(reverse_lazy('yourshop:payment-failed'))
- Assert and Capture the money and place the order
from saferpay.gateway import SaferpayService
from saferpay import execptions as sp_execptions
def payment_capture(request):
token = request.session['saferpay_token']
saferpay_service = SaferpayService.init_from_transaction(token=token)
try:
status = saferpay_service.paymentpage_assert()
except (
sp_execptions.GatewayError, sp_execptions.TransactionDeclined,
sp_execptions.UnableToTakePayment, sp_execptions.PaymentError
) as e:
# do your rollback in case of payment failure
return redirect(reverse_lazy('yourshop:payment-failed'))
if status == 'CAPTURED':
# register the payment in you shop
logger.info("Order #%s: payment successful, placing order", saferpay_service.order_id)
try:
# place the order
except UnableToPlaceOrder as e:
# go back to preview
Metadata
Release files for django-saferpay 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-saferpay-0.1.1.tar.gz | 9.6 kB | Without provenance | Details for django-saferpay-0.1.1.tar.gz |
Release files / django-saferpay-0.1.1.tar.gz
| Download URL | django-saferpay-0.1.1.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c5bc3e427e946d7339cbe161fd64a35ef81ccbad6297299bfc103dda26ebf9da
|
|
BLAKE2b-256 checksum How to use checksums |
dc34351523cabed300a6647d337bc1e154bf365c212cc73f5caf8a23479866b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.0 CPython/3.6.4
|
Security for django-saferpay 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.