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 currently implements API v.1.9 only.

Installation

pip install csobpg

Basic usage

API client initialization

from csobpg.v19 import APIClient

client = APIClient("merchantId", "merch_private.key", "csob.pub", base_url=..., http_client=...)

HTTP client

The library uses the HTTPClient interface for making HTTP requests.

It provides the following HTTP clients:

  • csobpg.http.urllib_client.UrllibHTTPClient - the default one using the urllib under the hood
  • csobpg.http.requests_client.RequestsHTTPClient - an extra HTTP client using the requests under the hood. The library must be installed with the requests-client extra to be able to use this client

It is also possible to implement the HTTPClient interface to use your custom HTTP client.

The HTTP client is set as the following:

from csobpg.v19 import APIClient
from csobpg.http import HTTPClient

class CustomHTTPClient(HTTPClient):
    ...

client = APIClient(..., http_client=CustomHTTPClient(...))

Payment initialization

from csobpg.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

response = client.process_gateway_return(data_dict)

Get payment status

response = 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 csobpg.v19.errors import APIError, APIClientError
from csobpg.http import HTTPRequestError

try:
    response = client.<operation>(...)
except APIError as exc:
    # handle API error
    # it is raised on any API error. You may also catch the specific API error
except APIClientError as exc:
    # handle API client error
    # it is raised when API returns unexpected response (e.g. invalid JSON, invalid signature)
except HTTPRequestError as exc:
    # handle HTTP error
    # it is raised on any HTTP error
except ValueError as exc:
    # handle value error
    # it is raised on any library's misuse (e.g. passing invalid parameters)
    # it always means developer's mistake

RSA keys management

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

from csobpg.v19 import APIClient

client = APIClient(..., "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 csobpg.v19 import APIClient, FileRSAKey, CachedRSAKey

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

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

from csobpg.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

csobpg-0.0.1.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

csobpg-0.0.1-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file csobpg-0.0.1.tar.gz.

File metadata

  • Download URL: csobpg-0.0.1.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.9 Linux/6.5.0-1023-azure

File hashes

Hashes for csobpg-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f6f247d09616e8d20ef786eccc5a7393abfd92b479098a74b26fdad25df29090
MD5 477e6c38b3ef7169db89afe57ed7409e
BLAKE2b-256 d0e684dcf78542dc07836bad59b88984be69b16588465eaa9bba2533ccec13d3

See more details on using hashes here.

File details

Details for the file csobpg-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: csobpg-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 32.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.9 Linux/6.5.0-1023-azure

File hashes

Hashes for csobpg-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ca4ce573f3cd4747c9c4975986589ef96bf5de9ee553e23d7a022fae35a51385
MD5 8cb437f719b602b128d511b210f01150
BLAKE2b-256 a1afc93ba1980145a5dca4f9ececf890a95c3041179cb5ea4e91cb92a0be0eb8

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