Skip to main content

A simple Python package that provides convenient access to the Paymob APIs from applications written in the Python language.

Project description

\n# Paymob Python Package

python pre-commit Code style: black

Table of Contents

Description

The Paymob Python package provides convenient access to the Paymob APIs from applications written in the Python language. Current version only supports the following services:

  • Accept

Payouts and the other services will be added in the next releases.

Requirements

Before you begin, ensure you have met the following requirements:

Installation Instructions

You don't need this source code unless you want to modify the package. If you just want to use the package, just run:

pip install --upgrade paymob

Usage

Services

1- Accept Client


Handling APIs Response

Each API Call retrieves a tuple which contains three values (Code, An Object of the API's Return, ResponseFeedBack Instance)

  • Code: A Number that represents API state. Codes Reference
  • API's Return Object: An object class of the API's Return and its attributes can be accessed using dot notation.
  • Response FeedBack: An object of ResponseFeedBack class which has the following attributes:
    • message: A human readable description of the Code
    • data: A dict represents the actual API's Response
    • status_code: Status code that has been returned from the API (2xx, 4xx, 5xx)

Successful API calls will return the following values:

  • Code: One of the Following Codes
  • API's Return Object: object (Depending on the API response)
  • Response FeedBack: ResponseFeedBack Object with the following attributes:
    • message: A success message depending on the API (Example: Get Order API will return a message like "Successfully Retrieved Order: 1")
    • data: None
    • status_code: 2xx

Example:

from paymob.accept import AcceptAPIClient

accept_api_client = AcceptAPIClient()
code, transaction, feedback = accept_api_client.get_transaction(
    transaction_id=112233
)

print(f"Code: {code}")
print(f"Transaction: {transaction}")
print(f"Transaction ID: {transaction.id}")
print(f"Feedback Message: {feedback.message}")
print(f"Feedback Data: {feedback.data}")
print(f"Feedback Status Code: {feedback.status_code}")

Output:

Code: 10
Transaction: Transaction No: 111859918
Transaction ID: 111859918
Feedback Message: Transaction: 111859918 Retrieved Successfully
Feedback Data: None
Feedback Status Code: 200

Unsuccessful API calls will return the following values:

  • Code: One of the Following Codes
  • API's Return Object: Example: Get Transaction API will return a Transaction instance (transaction.id, transaction.success, ..etc)
  • Response FeedBack: ResponseFeedBack Object with the following attributes:
    • message: A failure message depending on exception occured (Example: "An Error Occurred During the Request")
    • data: API's response dict (response.json())
    • status_code: 4xx or 5xx

Example:

from paymob.accept import AcceptAPIClient

accept_api_client = AcceptAPIClient()
code, transaction, feedback = accept_api_client.get_transaction(
    transaction_id=112233
)

print(f"Code: {code}")
print(f"Transaction: {transaction}")
print(f"Feedback Message: {feedback.message}")
print(f"Feedback Data: {feedback.data}")
print(f"Feedback Status Code: {feedback.status_code}")

Output:

Code: 22
Transaction: None
Feedback Message: Non 2xx Status Code Returned.
Feedback Data: {'detail': 'Not found.'}
Feedback Status Code: 404

Codes Reference

Success Codes

Variable Code Description
SUCCESS 10 API Called Successfully Without any Failures

Error Codes

Variable Code Description
JSON_DECODE_EXCEPTION 20 An Error Occurred While Parsing the Response into JSON
REQUEST_EXCEPTION 21 An Error Occurred During the Request
HTTP_EXCEPTION 22 Non 2xx Status Code Returned
UNHANDLED_EXCEPTION 23 Unhandled Exception [comment]: # Trace Error will be provided in the message

You can import these codes like the following:

from paymob.accept.response_codes import (
    SUCCESS, 
    JSON_DECODE_EXCEPTION, 
    REQUEST_EXCEPTION, 
    HTTP_EXCEPTION, 
    UNHANDLED_EXCEPTION
)

Settings

You can customized some behaves of Paymob by adding the following settings in .env file.

- ACCEPT_APIS_TIMEOUT_SECONDES

Sets Timeout for API Calls (The connect timeout is the number of seconds Requests will wait for your client to establish a connection or read data with/from Paymob server)

Example:

ACCEPT_APIS_TIMEOUT_SECONDES=20

- VALIDATE_API_RESPONSE (Not Added Yet)

Automatically validates the returned data of the APIs to ensure that there are no changed keys or data types

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

Paymob-Toolbox-0.0.2.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

Paymob_Toolbox-0.0.2-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file Paymob-Toolbox-0.0.2.tar.gz.

File metadata

  • Download URL: Paymob-Toolbox-0.0.2.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for Paymob-Toolbox-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ec8430763160db6e59b9cb775100d49b2622370d2ae4f4e7aab7f125710b726c
MD5 9c53654c8febc6809681d61e80025191
BLAKE2b-256 7361e1230d8c4a7d87b2d332531090dce1dfdd432458b7cdd073cf352eddf1ef

See more details on using hashes here.

File details

Details for the file Paymob_Toolbox-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: Paymob_Toolbox-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.4

File hashes

Hashes for Paymob_Toolbox-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 766b5297456904e6d7218dbea50879a63f467662cb9db7b61404191acd3f0704
MD5 662a7f8e7b44bd623b40771fdf048fdf
BLAKE2b-256 66d800a0fbe2a1e7215b510bf0642fea078f52f5f2d4627cf92be44eac220dbb

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