Skip to main content

A simple client for the Kapital payment gateway.

Project description

Kapital Payment Gateway Client

PyPI Downloads

kapital is a Python client for the Kapital Bank payment gateway, designed to simplify the process of creating and managing payment orders. This library provides a straightforward interface to interact with the Kapital Bank API, making it easier to integrate payment functionality into your applications.

Features

  • Create payment orders with customizable parameters.
  • Supports basic authentication for secure API access.
  • Handles JSON payloads and responses seamlessly.

Installation

You can install the kapital package via pip. It's recommended to create a virtual environment for your project.

pip install kapital

Usage

Here’s a quick guide on how to use the kapital client.

Importing the Client

from kapital import Kapital

Initializing the Client

To use the client, initialize it with your credentials. If you don't provide any credentials, default values will be used.

client = Kapital(
  base_url="https://e-commerce.kapitalbank.az/api",
  username="your-username",
  password="your-password"
)

Creating a Payment Order

You can create a payment order by calling the create_order method. Here's an example:

response = client.create_order(
  redirect_url="https://your-redirect-url.com",
  amount=100.00,
  description="Payment for Order #123",
  currency="AZN",
  language="az"
)

print(response)

Response Structure

The create_order method returns a dictionary containing the following keys:

  • order_id: The unique identifier for the order.
  • password: The password for the order.
  • hppUrl: The URL for redirecting the user to complete the payment.
  • status: The status of the order.
  • cvv2AuthStatus: The CVV2 authentication status.
  • secret: A secret value associated with the order.
  • redirect_url: The full URL to redirect the user for payment.

Example Response

{
  "order_id": "123456",
  "password": "secret_password",
  "hppUrl": "https://payment-url.com",
  "status": "pending",
  "cvv2AuthStatus": "approved",
  "secret": "order_secret",
  "redirect_url": "https://payment-url.com?id=123456&password=password"
}

Saving a Card

To save a card for future transactions, use the save_card method:

response, status_code = client.save_card(
  redirect_url="https://your-redirect-url.com",
  amount=100.0,
  description="Saving card for future use",
  currency="AZN",
  language="az",
)

In redirect url kapital will send a token which you can use for future transactions. The response will contain the token of the stored card.

{
  "order": {
    "storedTokens": [
      {
        "id": "21790"
      }
    ]
  }
}

Paying with a Stored Card

You can make a payment using a stored card by calling the pay_with_card method:

response, status_code = client.pay_with_card(
  amount=100.0,
  description="Payment for services",
  token="21790",  # Replace with your stored card token
  currency="AZN",
  language="az",
)

Refund a Transaction

To refund a transaction, use the refund method. Here's an example:

response, status_code = client.refund(
  order_id="45451", # Replace with your order ID
  amount=100.0, # Amount to refund
)

Reverse a Transaction

To reverse a transaction, call the reverse method:

response, status_code = client.reverse(
  order_id="45451", # Replace with your order ID
)

Get Order Details

You can retrieve the details of an order using the get_order_details method:

response, status_code = client.get_order_details(
  order_id="45451", # Replace with your order ID
)

Error Handling

The client raises exceptions for various error cases, such as:

  • If the response status code is not 200, an Exception will be raised.
  • If the response format is invalid, a ValueError will be raised indicating the specific issue.
try:
  response = client.create_order(
    redirect_url="https://your-redirect-url.com",
    amount=100.00,
    description="Payment for Order #123"
  )
except Exception as e:
  print(f"An error occurred: {e}")

Contributing

Contributions are welcome! If you have suggestions for improvements or want to report bugs, please open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Authors

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

kapital-1.0.5.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

kapital-1.0.5-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file kapital-1.0.5.tar.gz.

File metadata

  • Download URL: kapital-1.0.5.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for kapital-1.0.5.tar.gz
Algorithm Hash digest
SHA256 9eccc633c29cf5887d539bd3c86bfb3f43398cd77f9f3282f1904d32354c73f1
MD5 528c5f44cd8b34afea4c06c1f7f8ba3f
BLAKE2b-256 86fba46dfb40a8f60891f0055c57b56b74dc7640d5b297a07605c799d7e83b88

See more details on using hashes here.

File details

Details for the file kapital-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: kapital-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for kapital-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 26d8e46658cab65ffd466560723d565f48e75b3519080e8f4d6535d9bb394e71
MD5 fe0923571626596a1cc8493c6b78fbf6
BLAKE2b-256 54e0a413d8f5c80736da97a5cc6dd9fd96e771e677a7715b9a3f6c5a0f4e25a5

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