Skip to main content

Library for communication with ČSOB API

Project description

Codecov

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 ČSOB API v.1.9.

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 httprest library for making HTTP requests. By default it will use httprest.http.urllib_client.UrllibHTTPClient.

But you may use any other httprest's HTTP client, or even write your own client.

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 httprest.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
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.5.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csobpg-0.5.0-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for csobpg-0.5.0.tar.gz
Algorithm Hash digest
SHA256 f3a310a1eb8d09d35b1709cba6f4aca12b210988a8f7e4c417db6c65140fbc02
MD5 609620318be6bf590a4d6764e8c00377
BLAKE2b-256 2d6520c4f2396c0b202d6e4add5ea31c79d14d7c16bdb9c1e740f840f63a7ae3

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for csobpg-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3f738217ea1f06425cba9dc469fb53e05ffa7c0bef0254d3e17f543cc005d13
MD5 3bca62d8b710a0b47553b7ff8cc49aef
BLAKE2b-256 2d05b992c6c03e8b3cfc8c2ff5a85dd78a331f74d601b8393e2a6583f76ac100

See more details on using hashes here.

Supported by

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