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

The APIClient provides the interface to communicate with the API.

from csobpg.v19 import APIClient

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

# Use the client to interact with the API:
client.init_payment(...)

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(...))

Base methods

The library supports all base API methods. For example, that's how to initialize a payment:

from csobpg.v19.models import cart

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

OneClick methods

Here are the steps to perform a OneClick payment.

Step 1 - make a regular payment

First, make a regular payment using the "payment/init":

response = client.payment_init(...)

# finalize payment...

Preserve the response.pay_id, it will be used to refer to the OneClick template.

Step 2 - initialize OneClick payment

Now, having the template ID, initialize the OneClick payment. First, check that the template ID exists (optional):

response = client.oneclick_echo(template_id)
assert response.success

Then, initiate the payment:

response = client.oneclick_init_payment(template_id=..., ...)

Step 3 - process OneClick payment

Finally, process the payment:

response = client.oneclick_process(pay_id, fingerprint=...)

Exceptions handling

from csobpg.v19.errors import APIError, APIClientError
from csobpg.http import HTTPRequestError

response = client.<operation>(...)
# you can access the response_code directly:
assert response.result_code == 0

# or call the `raise_for_result_code` method and handle exceptions:
try:
    response.raise_for_result_code()
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
from csobpg.v19.key import 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.key 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.2.0.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

csobpg-0.2.0-py3-none-any.whl (40.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for csobpg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4897c7f776b281934de8b4f0cfe036aa178e052f39914dc16aa2d9008a6b8841
MD5 5b560b2ada1f4d4896826cacb4369be7
BLAKE2b-256 785a01b2822db5023545a9c207ad7e45da849dd8086d16e52e1cf4494bb593e4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for csobpg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ba6f3296652ef89b831588a83eea962950447481a4182d7e18c8157bd3cb64e
MD5 1ea2ae32679824ded6c9b09b66d9b1af
BLAKE2b-256 4e3c9770428479305d28353101041a4d6699fd4149aa383abda77f18b8e8e423

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