Skip to main content

Library for communication with ČSOB API

Project description

CSOB client

Python library for communicating with ČSOB (https://platbakartou.csob.cz/) payment gateway API. The API is described here: https://github.com/csob/paymentgateway.

The library focuses on the v.1.9 but it is designed for extensibility.

Installation

pip install csobclient

Basic usage

Client initialization

from csobclient.v19 import Client

client = Client("merchantId", "merch_private.key", "csob.pub")

Payment initialization

from csobclient.v19 import Cart, CartItem

response = client.init_payment(
    order_no="2233823251",
    total_amount=100,
    return_url="http://127.0.0.1:5000/",
    cart=Cart([CartItem("Apples", 1, 100)]),
    merchant_data=b"Hello, World!",
)

Get payment URL

url = client.get_payment_process_url(pay_id)

Process the gateway redirect

payment_info = client.process_gateway_return(data_dict)

Get payment status

payment_info = client.get_payment_status(pay_id)

Reverse payment

response = client.reverse_payment(pay_id)

Refund payment

response = client.refund_payment(pay_id, amount=100)

Exceptions handling

from csobclient.v19 import APIError, HTTPRequestError

try:
    response = client.operation(...)
    response.raise_for_result_code()
except APIError as exc:
    # handle API error
except HTTPRequestError as exc:
    # handle HTTP error
except ValueError as exc:  # invalid params passed. Development error!
    # handle value error

It is also possible to check whether the API response is successful by checking the response.ok field:

response = client.operation(...)
if not response.ok:
    # handle

RSA keys management

The simples way to pass RSA keys is to pass their file paths:

from csobclient.v19 import Client

client = Client("merchantId", "merch_private.key", "csob.pub")

The library will read the private key from the file when needed. The public key will be cached into the RAM.

If you want to change it, use special classes:

from csobclient.v19 import Client, FileRSAKey, CachedRSAKey

client = Client("merchantId", FileRSAKey("merch_private.key"), FileRSAKey("csob.pub"))

You may also override the base RSAKey class to define your own key access strategy:

from csobclient.v19 import RSAKey

class MyRSAKey(RSAKey):

    def __str__(self) -> str:
        return "my key"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csobclient-0.4.1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

csobclient-0.4.1-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file csobclient-0.4.1.tar.gz.

File metadata

  • Download URL: csobclient-0.4.1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.10.9 Linux/6.2.0-1015-azure

File hashes

Hashes for csobclient-0.4.1.tar.gz
Algorithm Hash digest
SHA256 b88e99347b4e9cc270602fd46a18344d8d721060219ffb60ce5657bd4f8e0bbb
MD5 a1f75b76f1f399b821eedc6ec8e54e5f
BLAKE2b-256 2edf511da661c98a86df318854113568069b60d3e29299c74f85ee40106ab0e9

See more details on using hashes here.

File details

Details for the file csobclient-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: csobclient-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.0 CPython/3.10.9 Linux/6.2.0-1015-azure

File hashes

Hashes for csobclient-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ea4921aced23a3b38c07c1566775c9b7f7bbc92d72a7b0d597c9fd22a6acef32
MD5 e907a1ededc271f883f8cda8675df33d
BLAKE2b-256 c690d71f231c7d452946c2506dbf39116c96c328000ee9cdbcdba48b4db414a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page