# Peach Partner Library
## Overview
**Peach Partner Library** is a platform-agnostic Python package to help Payment Service Providers in integrating with PeachPayments.
**Documentation**:
**Source Code**: <https://gitlab.com/peachpayments/peach-partner-python/>
* * *
### Key terms
| Term | Definition |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------ |
| Partner API | A service provided by Peach Payments to enable Payment Service Providers to become available on the Peach Platform |
| Payment Service Provider | A payment service provider who integrates with the Partner API |
| Outbound API call | API calls sent from Partner API to the Payment Service Provider |
| Inbound API call | API calls sent from Payment Service Provider to Partner API |
## Installation
Package requires Python 3.9+
```sh
# pip
$ pip3 install peachpayments-partner
```
```sh
# poetry
$ poetry add peachpayments-partner
```
## Result codes
```python
from peachpayments_partner.result_codes import result_codes
result_codes.TRANSACTION_SUCCEEDED.code == "000.000.000"
result_codes.get("000.000.000").name == "TRANSACTION_SUCCEEDED"
result_codes.get("000.000.000").description == "Transaction succeeded"
```
## Authentication
### Requests to Payment Service Provider
PeachPayments uses an authorization token (JWT) in each request made to the Payment Service Provider.
This library provides the `authentication.is_authenticated` method, which takes the token as an argument and the `authentication.get_key` to collect the signing_key.
The `is_authenticated` method has only one required argument, the token. If it's called without the optional `signing_key` it will collect the key using the `get_key` method. If it's called without the optional `audience` it will try to use the environment variable `AUTH0_AUDIENCE`.
The method decodes the token. If that succeeds, it returns `True`. Otherwise, it raises an `AuthError` exception.
## Formatting error responses
PeachPayments requires the error responses to be formatted in a specific way. This library provides the `format_error_response` method, which takes a dict containing error response as an argument and returns a formatted error response.
```python
def format_error_response(code, errors, data):
```
The `errors` dict might look like this:
```python
{
"status": ["Not a valid string."],
"code": ["Missing data for required field."],
}
```
The `data` dict might look like this:
```python
{
"status": 10
}
```
With the `code` as `ResultCodes.INVALID_OR_MISSING_PARAMETER`, the formatted error response will look similar to this:
```python
{
"result": {
"code": "200.300.404",
"description": "invalid or missing parameter",
"parameterErrors": [
{
"value": 10,
"name": "status",
"message": "Not a valid string."
},
{
"name": "code",
"message": "Missing data for required field."
}
]
},
"timestamp": "2021-08-03T16:16:30.992618Z"
}
```
## Fixtures
This library provides examples of valid requests and responses.
An example of the recommended usage for testing:
```python
import pytest
from copy import deepcopy
from peachpayments_partner.fixtures import DEBIT_RESPONSE
@pytest.fixture
def debit_response():
return deepcopy(DEBIT_RESPONSE)
```
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/peachpayments/peach-partner-python/",
"name": "peachpayments-partner",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "PeachPayments",
"author_email": "support@peachpayments.com",
"download_url": "https://files.pythonhosted.org/packages/d9/62/69dff8e406adb5aceb724a5614331b300a7cb4219fdb4c4e3346163ba933/peachpayments_partner-0.1.11.tar.gz",
"platform": null,
"description": "# Peach Partner Library\n\n## Overview\n\n**Peach Partner Library** is a platform-agnostic Python package to help Payment Service Providers in integrating with PeachPayments.\n\n**Documentation**:\n\n**Source Code**: <https://gitlab.com/peachpayments/peach-partner-python/>\n\n* * *\n\n### Key terms\n\n| Term | Definition |\n| ------------------------ | ------------------------------------------------------------------------------------------------------------------ |\n| Partner API | A service provided by Peach Payments to enable Payment Service Providers to become available on the Peach Platform |\n| Payment Service Provider | A payment service provider who integrates with the Partner API |\n| Outbound API call | API calls sent from Partner API to the Payment Service Provider |\n| Inbound API call | API calls sent from Payment Service Provider to Partner API |\n\n## Installation\n\nPackage requires Python 3.9+\n\n```sh\n# pip\n$ pip3 install peachpayments-partner\n```\n\n```sh\n# poetry\n$ poetry add peachpayments-partner\n```\n\n## Result codes\n\n```python\nfrom peachpayments_partner.result_codes import result_codes\n\nresult_codes.TRANSACTION_SUCCEEDED.code == \"000.000.000\"\nresult_codes.get(\"000.000.000\").name == \"TRANSACTION_SUCCEEDED\"\nresult_codes.get(\"000.000.000\").description == \"Transaction succeeded\"\n```\n\n## Authentication\n\n### Requests to Payment Service Provider\n\nPeachPayments uses an authorization token (JWT) in each request made to the Payment Service Provider.\nThis library provides the `authentication.is_authenticated` method, which takes the token as an argument and the `authentication.get_key` to collect the signing_key.\n\nThe `is_authenticated` method has only one required argument, the token. If it's called without the optional `signing_key` it will collect the key using the `get_key` method. If it's called without the optional `audience` it will try to use the environment variable `AUTH0_AUDIENCE`.\n\nThe method decodes the token. If that succeeds, it returns `True`. Otherwise, it raises an `AuthError` exception.\n\n## Formatting error responses\n\nPeachPayments requires the error responses to be formatted in a specific way. This library provides the `format_error_response` method, which takes a dict containing error response as an argument and returns a formatted error response.\n\n```python\ndef format_error_response(code, errors, data):\n```\nThe `errors` dict might look like this:\n\n```python\n{\n \"status\": [\"Not a valid string.\"],\n \"code\": [\"Missing data for required field.\"],\n}\n```\n\nThe `data` dict might look like this:\n\n```python\n{\n \"status\": 10\n}\n```\n\nWith the `code` as `ResultCodes.INVALID_OR_MISSING_PARAMETER`, the formatted error response will look similar to this:\n\n```python\n{\n \"result\": {\n \"code\": \"200.300.404\",\n \"description\": \"invalid or missing parameter\",\n \"parameterErrors\": [\n {\n \"value\": 10,\n \"name\": \"status\",\n \"message\": \"Not a valid string.\"\n },\n {\n \"name\": \"code\",\n \"message\": \"Missing data for required field.\"\n }\n ]\n },\n \"timestamp\": \"2021-08-03T16:16:30.992618Z\"\n}\n```\n\n## Fixtures\n\nThis library provides examples of valid requests and responses.\n\nAn example of the recommended usage for testing:\n\n```python\nimport pytest\nfrom copy import deepcopy\nfrom peachpayments_partner.fixtures import DEBIT_RESPONSE\n\n@pytest.fixture\ndef debit_response():\n return deepcopy(DEBIT_RESPONSE)\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "PeachPayments Partner Library is a platform agnostic Python package to help integrating PeachPayments with their partners.",
"version": "0.1.11",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "66e05ed7f94eeb8cdf7ab239b85e7cae",
"sha256": "8ab2a2ed637210e5b2a4dd5718a6d728406ebfbe08159b5c7c43207bd2a9a883"
},
"downloads": -1,
"filename": "peachpayments_partner-0.1.11-py3-none-any.whl",
"has_sig": false,
"md5_digest": "66e05ed7f94eeb8cdf7ab239b85e7cae",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9,<4.0",
"size": 34349,
"upload_time": "2022-12-22T12:06:42",
"upload_time_iso_8601": "2022-12-22T12:06:42.515990Z",
"url": "https://files.pythonhosted.org/packages/ce/b2/c38b28556c0caf7e7b0dad0243d46471cdcf5f17887f68acd5b9e4033751/peachpayments_partner-0.1.11-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "63f2b71732cd32f9c44b3a48b232d788",
"sha256": "f7b921161d587034a3cfc477e4222fa16965cceb4f7b3f52f0c2423eebe8b967"
},
"downloads": -1,
"filename": "peachpayments_partner-0.1.11.tar.gz",
"has_sig": false,
"md5_digest": "63f2b71732cd32f9c44b3a48b232d788",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9,<4.0",
"size": 33809,
"upload_time": "2022-12-22T12:06:44",
"upload_time_iso_8601": "2022-12-22T12:06:44.750566Z",
"url": "https://files.pythonhosted.org/packages/d9/62/69dff8e406adb5aceb724a5614331b300a7cb4219fdb4c4e3346163ba933/peachpayments_partner-0.1.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-12-22 12:06:44",
"github": false,
"gitlab": true,
"bitbucket": false,
"gitlab_user": "peachpayments",
"gitlab_project": "peach-partner-python",
"lcname": "peachpayments-partner"
}