\n# Paymob Python Package
[![python](https://img.shields.io/badge/Python-v3.8-3776AB.svg?style=flat&logo=python&logoColor=yellow)](https://www.python.org) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
## Table of Contents
- [Description](#description)
- [Requirements](#requirements)
- [Installation Instructions](#installation-instructions)
- [Usage](#usage)
- [Services](#services)
- [Handling APIs Response](#handling-apis-response)
- [Codes Reference](#codes-reference)
# 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:
* Python 3.8+
* You have installed the latest version of [python-decouple](https://pypi.org/project/python-decouple)
# 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:
```bash
pip install --upgrade paymob
```
# Usage
### Services
1- [Accept Client](docs/services/accept.md)
---
### 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](#codes-reference) <span id="code"></span>
- **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: <span id="feedback"></span>
- `message`: A human readable description of the [Code](#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](#success-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:**
```python
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:
```bash
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](#error-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:**
```python
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:
```bash
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](#message) |
You can import these codes like the following:
```python
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:**
```bash
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
Raw data
{
"_id": null,
"home_page": "https://github.com/muhammedattif/Paymob",
"name": "Paymob-Toolbox",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pypi,paymob,payment,python",
"author": "DjangoFam Team",
"author_email": "mahmoud.nasser.abdulhamed11@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/3e/63/9dedfe2d7d24511fe52f6bfc0ec3fc00d411eb050cdb2bd86776a55b4f8f/Paymob-Toolbox-0.0.1.tar.gz",
"platform": null,
"description": "\\n# Paymob Python Package\n\n[![python](https://img.shields.io/badge/Python-v3.8-3776AB.svg?style=flat&logo=python&logoColor=yellow)](https://www.python.org) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n\n## Table of Contents\n\n- [Description](#description)\n- [Requirements](#requirements)\n- [Installation Instructions](#installation-instructions)\n- [Usage](#usage)\n - [Services](#services)\n - [Handling APIs Response](#handling-apis-response)\n- [Codes Reference](#codes-reference)\n\n# Description\n\nThe Paymob Python package provides convenient access to the `Paymob` APIs from applications written in the Python language.\nCurrent version only supports the following services:\n- `Accept`\n\n`Payouts` and the other services will be added in the next releases.\n\n# Requirements\nBefore you begin, ensure you have met the following requirements:\n* Python 3.8+\n* You have installed the latest version of [python-decouple](https://pypi.org/project/python-decouple)\n\n# Installation Instructions\n\nYou don't need this source code unless you want to modify the package. If you just\nwant to use the package, just run:\n\n```bash\npip install --upgrade paymob\n```\n\n# Usage\n\n### Services\n\n1- [Accept Client](docs/services/accept.md)\n\n---\n\n### Handling APIs Response\n\nEach API Call retrieves a tuple which contains three values (Code, An Object of the API's Return, ResponseFeedBack Instance)\n\n- **Code**: A Number that represents API state. [Codes Reference](#codes-reference) <span id=\"code\"></span>\n- **API's Return Object**: An object class of the API's Return and its attributes can be accessed using dot notation.\n- **Response FeedBack**: An object of `ResponseFeedBack` class which has the following attributes: <span id=\"feedback\"></span>\n - `message`: A human readable description of the [Code](#code)\n - `data`: A `dict` represents the actual API's Response\n - `status_code`: Status code that has been returned from the API (`2xx`, `4xx`, `5xx`)\n\n**Successful API calls will return the following values:**\n\n- **Code**: [One of the Following Codes](#success-codes)\n- **API's Return Object**: `object` (Depending on the API response)\n- **Response FeedBack**: `ResponseFeedBack` Object with the following attributes:\n - `message`: A success message depending on the API (Example: Get Order API will return a message like \"Successfully Retrieved Order: 1\")\n - `data`: `None`\n - `status_code`: `2xx`\n\n**Example:**\n```python\nfrom paymob.accept import AcceptAPIClient\n\naccept_api_client = AcceptAPIClient()\ncode, transaction, feedback = accept_api_client.get_transaction(\n transaction_id=112233\n)\n\nprint(f\"Code: {code}\")\nprint(f\"Transaction: {transaction}\")\nprint(f\"Transaction ID: {transaction.id}\")\nprint(f\"Feedback Message: {feedback.message}\")\nprint(f\"Feedback Data: {feedback.data}\")\nprint(f\"Feedback Status Code: {feedback.status_code}\")\n```\n\nOutput:\n```bash\nCode: 10\nTransaction: Transaction No: 111859918\nTransaction ID: 111859918\nFeedback Message: Transaction: 111859918 Retrieved Successfully\nFeedback Data: None\nFeedback Status Code: 200\n```\n\n\n**Unsuccessful API calls will return the following values:**\n\n- **Code**: [One of the Following Codes](#error-codes)\n- **API's Return Object**: Example: Get Transaction API will return a `Transaction` instance (transaction.id, transaction.success, ..etc)\n- **Response FeedBack**: `ResponseFeedBack` Object with the following attributes:\n - `message`: A failure message depending on exception occured (Example: \"An Error Occurred During the Request\")\n - `data`: API's response `dict` (`response.json()`)\n - `status_code`: `4xx` or `5xx`\n\n\n**Example:**\n```python\nfrom paymob.accept import AcceptAPIClient\n\naccept_api_client = AcceptAPIClient()\ncode, transaction, feedback = accept_api_client.get_transaction(\n transaction_id=112233\n)\n\nprint(f\"Code: {code}\")\nprint(f\"Transaction: {transaction}\")\nprint(f\"Feedback Message: {feedback.message}\")\nprint(f\"Feedback Data: {feedback.data}\")\nprint(f\"Feedback Status Code: {feedback.status_code}\")\n```\n\nOutput:\n```bash\nCode: 22\nTransaction: None\nFeedback Message: Non 2xx Status Code Returned.\nFeedback Data: {'detail': 'Not found.'}\nFeedback Status Code: 404\n```\n\n-----\n\n# Codes Reference\n\n### Success Codes\n| Variable | Code | Description | \n| --- | --- | --- |\n| `SUCCESS` | `10` | API Called Successfully Without any Failures |\n\n### Error Codes\n| Variable | Code | Description | \n| --- | --- | --- |\n| `JSON_DECODE_EXCEPTION` | `20` | An Error Occurred While Parsing the Response into JSON |\n| `REQUEST_EXCEPTION` | `21` | An Error Occurred During the Request |\n| `HTTP_EXCEPTION` | `22` | Non 2xx Status Code Returned |\n| `UNHANDLED_EXCEPTION` | `23` | Unhandled Exception [comment]: # Trace Error will be provided in the [message](#message) |\n\n\nYou can import these codes like the following: \n```python\nfrom paymob.accept.response_codes import (\n SUCCESS, \n JSON_DECODE_EXCEPTION, \n REQUEST_EXCEPTION, \n HTTP_EXCEPTION, \n UNHANDLED_EXCEPTION\n)\n```\n\n----\n\n# Settings\n\nYou can customized some behaves of `Paymob` by adding the following settings in `.env` file.\n\n**- ACCEPT_APIS_TIMEOUT_SECONDES**\n\nSets 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)\n\n**Example:**\n```bash\nACCEPT_APIS_TIMEOUT_SECONDES=20\n```\n\n**- VALIDATE_API_RESPONSE** (Not Added Yet)\n\nAutomatically validates the returned data of the APIs to ensure that there are no changed keys or data types\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "A simple Python package that provides convenient access to the Paymob APIs from applications written in the Python language.",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/muhammedattif/Paymob"
},
"split_keywords": [
"pypi",
"paymob",
"payment",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "67f4802b82ad71ff8984a22cd2f462b00ade1a3da145d59b306adb47acd8364c",
"md5": "0e94df705a3d0a1d8073df57f6344206",
"sha256": "592ccaa3fb652dc1290d98034cbac2bd5034d07b87d60f133de1eda8ed645c89"
},
"downloads": -1,
"filename": "Paymob_Toolbox-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0e94df705a3d0a1d8073df57f6344206",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 25449,
"upload_time": "2023-06-20T21:50:09",
"upload_time_iso_8601": "2023-06-20T21:50:09.957461Z",
"url": "https://files.pythonhosted.org/packages/67/f4/802b82ad71ff8984a22cd2f462b00ade1a3da145d59b306adb47acd8364c/Paymob_Toolbox-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3e639dedfe2d7d24511fe52f6bfc0ec3fc00d411eb050cdb2bd86776a55b4f8f",
"md5": "2b07daaae8212883032fa499c6b3dc9f",
"sha256": "eed7b9eb00f61bca7b75659d4ae36dac7ed7c7baefeccd3425de06685cbc5a7f"
},
"downloads": -1,
"filename": "Paymob-Toolbox-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "2b07daaae8212883032fa499c6b3dc9f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17893,
"upload_time": "2023-06-20T21:50:11",
"upload_time_iso_8601": "2023-06-20T21:50:11.759305Z",
"url": "https://files.pythonhosted.org/packages/3e/63/9dedfe2d7d24511fe52f6bfc0ec3fc00d411eb050cdb2bd86776a55b4f8f/Paymob-Toolbox-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-20 21:50:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "muhammedattif",
"github_project": "Paymob",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "certifi",
"specs": [
[
"==",
"2023.5.7"
]
]
},
{
"name": "cfgv",
"specs": [
[
"==",
"3.3.1"
]
]
},
{
"name": "charset-normalizer",
"specs": [
[
"==",
"3.1.0"
]
]
},
{
"name": "distlib",
"specs": [
[
"==",
"0.3.6"
]
]
},
{
"name": "filelock",
"specs": [
[
"==",
"3.12.2"
]
]
},
{
"name": "identify",
"specs": [
[
"==",
"2.5.24"
]
]
},
{
"name": "idna",
"specs": [
[
"==",
"3.4"
]
]
},
{
"name": "multimethod",
"specs": [
[
"==",
"1.9.1"
]
]
},
{
"name": "nodeenv",
"specs": [
[
"==",
"1.8.0"
]
]
},
{
"name": "platformdirs",
"specs": [
[
"==",
"3.5.3"
]
]
},
{
"name": "pre-commit",
"specs": [
[
"==",
"3.3.3"
]
]
},
{
"name": "pydantic",
"specs": [
[
"==",
"1.10.9"
]
]
},
{
"name": "python-decouple",
"specs": [
[
"==",
"3.8"
]
]
},
{
"name": "PyYAML",
"specs": [
[
"==",
"6.0"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"7.3.2"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.31.0"
]
]
},
{
"name": "six",
"specs": [
[
"==",
"1.16.0"
]
]
},
{
"name": "typing-extensions",
"specs": [
[
"==",
"4.6.3"
]
]
},
{
"name": "urllib3",
"specs": [
[
"==",
"2.0.3"
]
]
},
{
"name": "virtualenv",
"specs": [
[
"==",
"20.23.0"
]
]
}
],
"lcname": "paymob-toolbox"
}