Skip to main content

Sage Pay lib

Note: This library still refers to netcash. I'll update all references to NetCash in the future

A simple library for interacting with Sage Pay SOAP services

Installation

pip install python-netcash

Usage

The preferred way to interact with the repo is using docker.

Quick commands:

Run the tests

Warning: These are integration tests and will hit the netcash endpoints

docker-compose up
  • See: tests.py for example code

You must provide the following environment variables in env.dev (you can copy env.example and put your values in):

NETCASH_MERCHANT_ACCOUNT=... NETCASH_SOFTWARE_VENDOR_KEY=...

You customer will provide:

NETCASH_SERVICE_ID=... NETCASH_SERVICE_KEY=...

Integration requirements

In order to integrate with Netcash, you will be required to implement the following functionality:

Tip: You can get an interactive shell with:

docker-compose run --rm netcash ipython

Setup the client

# get environment variables into constants:
from netcash.client import Netcash
import os

NETCASH_MERCHANT_ACCOUNT = os.environ.get("NETCASH_MERCHANT_ACCOUNT")
NETCASH_SOFTWARE_VENDOR_KEY = os.environ.get("NETCASH_SOFTWARE_VENDOR_KEY")

service_id = ...
service_key = ...

netcash = Netcash(NETCASH_MERCHANT_ACCOUNT, NETCASH_SOFTWARE_VENDOR_KEY)

Validate service key

# returns a boolean True if valid account. Otherwise False
netcash.validate_service_key(service_id, service_key)

Request and retrieve merchant statement

# request a statement:

# this is just for readability:
from datetime import date, timedelta

from_date = date.today() - timedelta(days=7) # get the last week's worth of transactions

polling_id = netcash.request_merchant_statement(
    from_date=from_date, service_key=service_key,
)
res = netcash.retrieve_merchant_statement(
    polling_id, service_key=service_key, as_csv_reader=True
)
for row in res.rows:
    print(row)

>> ['2020-04-14', 'OBL', '0', 'Opening Balance', '0.0000', '+', '0', '', '', '']
>> ['2020-04-14', 'CBL', '0', 'Closing Balance', '0.0000', '+', '0']

Paynow

Creating a form to initiate a PayNow request:

<form method="POST"
    action="https://paynow.netcash.co.za/site/paynow.aspx" target="_top">
  <input type="hidden" name="M1" value="..">  <!--- YOUR PAY NOW SERVICE KEY GOES IN HERE --->
  <input type="hidden" name="M2" value="..">  <!--- SOFTWARE VENDOR KEY GOES IN HERE --->
  <input type="hidden" name="P2" value="">  <!--- TRANSACTION_ID --->
  <input type="hidden" name="P3" value="">  <!--- TRANSACTION DESCRIPTION --->
  <input type="hidden" name="P4" value="">  <!--- TRANSACTION AMOUNT --->

  <!--- ARBITARY FIELDS FOR STORING ANY INFORMATION YOU MIGHT NEED (E.G.: REFERENCES ETC) --->
  <input type="hidden" name="M4" value="">
  <input type="hidden" name="M5" value="">
  <input type="hidden" name="M6" value="">

  <input type="hidden" name="M9" value=""> <!--- CARDHOLDER EMAIL --->
  <input type="hidden" name="M11" value=""> <!--- CARDHOLDER MOBILE NUMBER --->

  <input type="hidden" name="Budget" value="Y">  <!--- REQUIRED, MUST BE Y --->
</form>

Contributing

This library is pretty simple. To add support for a new web method do:

  1. Add a payload to sagepay/payloads.py
  2. Add a method to wrap request in sagepay/client.py

Metadata

Release files for python-netcash 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-netcash 0.0.1
File Size Uploaded Provenance
python-netcash-0.0.1.tar.gz 4.3 kB Without provenance Details

Release files / python-netcash-0.0.1.tar.gz

Download URL python-netcash-0.0.1.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d4ccc371430dcc4d0179802463569409c1b6ae5f6a5ac556649f8aecedd07750
BLAKE2b-256 checksum
How to use checksums
14549efc1e0f0f6963b9e78344ed3a162e74887da82c0deaea49aa1e09966cbd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7

Security for python-netcash 0.0.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.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page