TrustPay payments integration library.
Project description
TrustPay payment solution integration helpers.
Install
$ pip install trustpaylib
Usage
Link approach
Create environment, payment request and generate signed link.
>>> import trustpaylib
>>>
>>> env = trustpaylib.build_environment(
... aid="1234567890",
... secret_key="abcd1234",
... # api_url=trustpaylib.TRUSTCARD_API_URL,
... )
>>> pay_request = trustpaylib.build_pay_request(
... AMT="123.45",
... CUR="EUR",
... REF="1234567890",
... )
>>> trustpay_client = trustpaylib.TrustPay(env)
>>> trustpay_client.build_link(pay_request)
'https://ib.trustpay.eu/mapi/paymentservice.aspx?AID=9876543210&REF=1234567890&AMT=123.45&SIG=DF174E635DABBFF7897A82822521DD739AE8CC2F83D65F6448DD2FF991481EA3&CUR=EUR'
Form approach
First merge payment request with environment variables, validate it and sign. trustpaylib.TrustPay.finalize_request returns prepared payment request. As form action use trustpay_client.environment.api_url.
>>> pay_request = trustpay_client.finalize_request(pay_request)
>>> trustpay_client.initial_data(pay_request)
{'AID': '9876543210', 'REF': u'1234567890', 'AMT': u'123.45', 'SIG': 'DF174E635DABBFF7897A82822521DD739AE8CC2F83D65F6448DD2FF991481EA3', 'CUR': u'EUR'}
>>> trustpay_client.environment.api_url
'https://ib.trustpay.eu/mapi/paymentservice.aspx'
Redirects handling
There’s not much you can (or should) do with redirect.
But at least you can check the result code.
>>> # data received as get params to redirect
... redirect_data = {"REF": "1234567890", "RES": 3, "PID": "1212321"}
>>> redirect = trustpaylib.build_redirect(**redirect_data)
>>>
>>> trustpay_client.get_result_desc_from_redirect(redirect).short
'Authorized'
>>> trustpay_client.get_result_desc_from_redirect(redirect).long
'Payment was successfully authorized. Another notification (with result code 0 - success) will be sent when TrustPay receives and processes payment from 3rd party.'
Notifications handling
For received notification, first check signature.
>>> notification_data = {
... "AID": "1234567890",
... "TYP": "CRDT",
... "AMT": "123.45",
... "CUR": "EUR",
... "REF": "9876543210",
... "RES": "0",
... "TID": "11111",
... "OID": "1122334455",
... "TSS": "Y",
... "SIG": (
... "97C92D7A0C0AD99CE5DE55C3597D5ADA"
... "0D423991E2D01938BC0F684244814A37"
... ),
... }
>>> notification = trustpaylib.build_notification(**notification_data)
>>> assert trustpay_client.check_notification_signature(notification)
Then check result code.
>>> trustpay_client.get_result_desc_from_notification(notification).short
'Success'
>>> trustpay_client.get_result_desc_from_notification(notification).long
'Payment was successfully processed.'
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
trustpaylib-0.0.1.tar.gz
(8.7 kB
view details)
File details
Details for the file trustpaylib-0.0.1.tar.gz
.
File metadata
- Download URL: trustpaylib-0.0.1.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce690af3851a837a196b85c527877fa26d4c5a7539a39da8ace486dfa71a514c |
|
MD5 | cb82f58126179dd5f2bcba064cf5cbd8 |
|
BLAKE2b-256 | 3f3642bfea7349e0edb1fb11f71f32162e57badcf5bd16a65f2ad8b868913d55 |