Package: paymob-solutions
\n# Paymob Python PackageTable of ContentsDescriptionRequirementsInstallation InstructionsUsageServicesHandling APIs ResponseCodes Reference1- DescriptionThe Paymob Python package provides convenient access to thePaymobAPIs from applications written in the Python language.
Current version only supports the following services:AcceptPayoutsand other services will be added in the next releases.2- RequirementsBefore you begin, ensure you have met the following requirements:Python 3.8+3- Installation InstructionsYou don't need this source code unless you want to modify the package. If you just
want to use the package, just run:pipinstall--upgradepaymob-solutions4- Usage4.1 Services1-Accept4.2 Handling APIs ResponseEach 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 ReferenceAPI's Return Object: An object class of the API's Return and its attributes can be accessed using dot notation.Response FeedBack: An object ofResponseFeedBackclass which has the following attributes:message: A human readable description of theCodedata: Adictrepresents the actual API's Responsestatus_code: Status code that has been returned from the API (2xx,4xx,5xx)exception_error: In case an exception is raised (Based on thisCodes), you can see the error using this attribute.Successful API calls will return the following values:Code:One of the Following CodesAPI'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:NoneExample:frompaymob.acceptimportAcceptAPIClientaccept_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:10Transaction:TransactionNo:111859918TransactionID:111859918FeedbackMessage:Transaction:111859918RetrievedSuccessfully
FeedbackData:None
FeedbackStatusCode:200FeedbackExceptionError:NoneUnsuccessful API calls will return the following values:Code:One of the Following CodesAPI's Return Object: Example: Get Transaction API will return aTransactioninstance (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:frompaymob.acceptimportAcceptAPIClientaccept_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:22Transaction:None
FeedbackMessage:Non2xxStatusCodeReturned.
FeedbackData:{'detail':'Not found.'}FeedbackStatusCode:404FeedbackExceptionError:404ClientError:NotFoundforurl:https://accept.paymob.com/api/acceptance/transactions/1122335- Codes Reference5.1 Success CodesVariableCodeDescriptionSUCCESS10API Called Successfully Without any Failures5.2 Error CodesVariableCodeDescriptionJSON_DECODE_EXCEPTION20An Error Occurred While Parsing the Response into JSONREQUEST_EXCEPTION21An Error Occurred During the RequestHTTP_EXCEPTION22Non 2xx Status Code ReturnedUNHANDLED_EXCEPTION23Unhandled ExceptionYou can import these codes like the following:frompaymob.response_codesimport(SUCCESS,JSON_DECODE_EXCEPTION,REQUEST_EXCEPTION,HTTP_EXCEPTION,UNHANDLED_EXCEPTION)6- SettingsYou can customized some behaves ofPaymobby adding the following settings in.envfile.- ACCEPT_APIS_TIMEOUT_SECONDESSets 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/fromPaymobserver)Default value is10Example: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