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
Table of Contents
1- 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 other services will be added in the next releases.
2- Requirements
Before you begin, ensure you have met the following requirements:
- Python 3.8+
3- 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-solutions
4- Usage
4.1 Services
1- Accept
4.2 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
ResponseFeedBackclass which has the following attributes:
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:
ResponseFeedBackObject 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:Nonestatus_code:2xxexception_error:None
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}")
print(f"Feedback Exception Error: {feedback.exception_error}")
Output:
Code: 10
Transaction: Transaction No: 111859918
Transaction ID: 111859918
Feedback Message: Transaction: 111859918 Retrieved Successfully
Feedback Data: None
Feedback Status Code: 200
Feedback Exception Error: None
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
Transactioninstance (transaction.id, transaction.success, ..etc) - Response FeedBack:
ResponseFeedBackObject with the following attributes:message: A failure message depending on exception occured (Example: "An Error Occurred During the Request")data: API's responsedict(response.json())status_code:4xxor5xxexception_error:Expecting value: line 1 column 1 (char 0)
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}")
print(f"Feedback Exception Error: {feedback.exception_error}")
Output:
Code: 22
Transaction: None
Feedback Message: Non 2xx Status Code Returned.
Feedback Data: {'detail': 'Not found.'}
Feedback Status Code: 404
Feedback Exception Error: 404 Client Error: Not Found for url: https://accept.paymob.com/api/acceptance/transactions/112233
5- Codes Reference
5.1 Success Codes
| Variable | Code | Description |
|---|---|---|
SUCCESS |
10 |
API Called Successfully Without any Failures |
5.2 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 |
You can import these codes like the following:
from paymob.response_codes import (
SUCCESS,
JSON_DECODE_EXCEPTION,
REQUEST_EXCEPTION,
HTTP_EXCEPTION,
UNHANDLED_EXCEPTION
)
6- 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)
Default value is 10
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file paymob-solutions-1.0.0.tar.gz.
File metadata
- Download URL: paymob-solutions-1.0.0.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1805ae50f6fe0e1a244c3df168c53fb5146fb86c2f2d282c6a518dcfdb2f3dbf
|
|
| MD5 |
3bf5f649022fab8d6a8ee3cb4277ea4c
|
|
| BLAKE2b-256 |
21362a861ac7839fe8a8d4fdd8ac5f796b8b185a0cde154fd011890e75517359
|
File details
Details for the file paymob_solutions-1.0.0-py3-none-any.whl.
File metadata
- Download URL: paymob_solutions-1.0.0-py3-none-any.whl
- Upload date:
- Size: 29.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7f560518b09dee82318c72ab395daf53ca50f314b42c5c8d2dc710b8978be06
|
|
| MD5 |
2ceb4d6047c778f910926e6c049cd209
|
|
| BLAKE2b-256 |
6a5b776a8f72cb4025ab8f01d232ad000d608dcc536949d3002cbe787f9fe78f
|