# pesapal-py
A minimalist python library that integrates with PesaPal's API 3.0 - JSON APIs (https://developer.pesapal.com/how-to-integrate/e-commerce/api-30-json/api-reference).
This library abstracts PesaPals API 3.0 into four main methods, `authenticate`, `register_ipn`, `transact` and `get_transaction_status`
## Getting started
### Register as a merchant
1. Register as a PesaPal merchant at https://www.pesapal.com/
2. On successfull registration, you will receive a consumer key and consumer secret via email - keep these safe as they are your API credentials
### Install pesapal-py
```
pip install pesapal-py
```
### Authenticating
```
from pesapal_py.payments import PesaPal
pesapal = PesaPal("test_consumer_key", "test_consumer_secret")
auth = pesapal.authenticate()
print(auth)
```
This step returns a bearer token that is used with all the other methods below. The token expires after every 5 minutes. To prevent calling this method every time you need to transact, I recommend that you store it in an in-memory data store (e.g. redis) and expire it before 5 minutes.
### Register IPN
```
register_ipn = pesapal.register_ipn("sample_token", "https://www.sample-url.com/ipn")
print(register_ipn)
```
### Transact
```
transact = pesapal.transact(
token="sample_token",
description="sample_description",
transaction_id="sample_transaction_id",
amount=1000,
callback_url="https://www.callback-url.com/status",
ipn_id="sample_ipn_id",
email_address="sample@email-address.com",
phone_number="254722001122",
country_code="KE",
first_name="first",
last_name="last",
currency="KES",
)
print(transact)
```
### Validate Transaction
```
transaction_status = pesapal.get_transaction_status(
token="sample_token", order_tracking_id="sample_order_tracking_id"
)
print(transaction_status)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/twais/pesapal-py",
"name": "pesapal-py",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Brian Owino Otieno",
"author_email": "brian.otieno709@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ac/d0/d0d26172c3a0842ed4f25f4715b57761a70a40c58bb956b57eb05c0471ab/pesapal-py-0.1.3.tar.gz",
"platform": null,
"description": "# pesapal-py\nA minimalist python library that integrates with PesaPal's API 3.0 - JSON APIs (https://developer.pesapal.com/how-to-integrate/e-commerce/api-30-json/api-reference).\n\nThis library abstracts PesaPals API 3.0 into four main methods, `authenticate`, `register_ipn`, `transact` and `get_transaction_status`\n\n## Getting started\n\n### Register as a merchant\n1. Register as a PesaPal merchant at https://www.pesapal.com/\n2. On successfull registration, you will receive a consumer key and consumer secret via email - keep these safe as they are your API credentials\n\n### Install pesapal-py\n```\npip install pesapal-py\n```\n\n### Authenticating\n```\nfrom pesapal_py.payments import PesaPal\n\npesapal = PesaPal(\"test_consumer_key\", \"test_consumer_secret\")\nauth = pesapal.authenticate()\nprint(auth)\n```\nThis step returns a bearer token that is used with all the other methods below. The token expires after every 5 minutes. To prevent calling this method every time you need to transact, I recommend that you store it in an in-memory data store (e.g. redis) and expire it before 5 minutes.\n\n### Register IPN\n```\nregister_ipn = pesapal.register_ipn(\"sample_token\", \"https://www.sample-url.com/ipn\")\nprint(register_ipn)\n```\n\n### Transact\n```\ntransact = pesapal.transact(\n token=\"sample_token\",\n description=\"sample_description\",\n transaction_id=\"sample_transaction_id\",\n amount=1000,\n callback_url=\"https://www.callback-url.com/status\",\n ipn_id=\"sample_ipn_id\",\n email_address=\"sample@email-address.com\",\n phone_number=\"254722001122\",\n country_code=\"KE\",\n first_name=\"first\",\n last_name=\"last\",\n currency=\"KES\",\n)\nprint(transact)\n```\n\n### Validate Transaction\n```\ntransaction_status = pesapal.get_transaction_status(\n token=\"sample_token\", order_tracking_id=\"sample_order_tracking_id\"\n)\nprint(transaction_status)\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "A minimalist python library that integrates with PesaPal's API 3.0 - JSON APIs (https://developer.pesapal.com/how-to-integrate/e-commerce/api-30-json/api-reference)",
"version": "0.1.3",
"project_urls": {
"Download": "https://github.com/twais/pesapal-py/archive/refs/tags/v0.0.1.tar.gz",
"Homepage": "https://github.com/twais/pesapal-py"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "20f0a40beb8a21469a6a090418cdf55a6197b8b4413ee77d656405d82083f6a4",
"md5": "a40ddacd4ce3dd1701ce332d897251c6",
"sha256": "47bdbefcab1ecd2055ff8e2760b73e27aba4b9a54c13988d0041340f71c8f8f2"
},
"downloads": -1,
"filename": "pesapal_py-0.1.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a40ddacd4ce3dd1701ce332d897251c6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 5428,
"upload_time": "2023-08-21T20:53:19",
"upload_time_iso_8601": "2023-08-21T20:53:19.762921Z",
"url": "https://files.pythonhosted.org/packages/20/f0/a40beb8a21469a6a090418cdf55a6197b8b4413ee77d656405d82083f6a4/pesapal_py-0.1.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "acd0d0d26172c3a0842ed4f25f4715b57761a70a40c58bb956b57eb05c0471ab",
"md5": "25287267211cc13dd3392dfdb26e4d2b",
"sha256": "6bcbc90f8cfa4400c892f48905c9dcc7d62d342212fe4f847d21b2da9f628961"
},
"downloads": -1,
"filename": "pesapal-py-0.1.3.tar.gz",
"has_sig": false,
"md5_digest": "25287267211cc13dd3392dfdb26e4d2b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 4952,
"upload_time": "2023-08-21T20:53:22",
"upload_time_iso_8601": "2023-08-21T20:53:22.873003Z",
"url": "https://files.pythonhosted.org/packages/ac/d0/d0d26172c3a0842ed4f25f4715b57761a70a40c58bb956b57eb05c0471ab/pesapal-py-0.1.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-21 20:53:22",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "twais",
"github_project": "pesapal-py",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "attrs",
"specs": [
[
"==",
"22.2.0"
]
]
},
{
"name": "black",
"specs": [
[
"==",
"23.1.0"
]
]
},
{
"name": "bleach",
"specs": [
[
"==",
"6.0.0"
]
]
},
{
"name": "build",
"specs": [
[
"==",
"0.10.0"
]
]
},
{
"name": "certifi",
"specs": [
[
"==",
"2023.7.22"
]
]
},
{
"name": "charset-normalizer",
"specs": [
[
"==",
"3.1.0"
]
]
},
{
"name": "click",
"specs": [
[
"==",
"8.1.3"
]
]
},
{
"name": "coverage",
"specs": [
[
"==",
"7.2.2"
]
]
},
{
"name": "docutils",
"specs": [
[
"==",
"0.19"
]
]
},
{
"name": "exceptiongroup",
"specs": [
[
"==",
"1.1.1"
]
]
},
{
"name": "idna",
"specs": [
[
"==",
"3.4"
]
]
},
{
"name": "importlib-metadata",
"specs": [
[
"==",
"6.1.0"
]
]
},
{
"name": "importlib-resources",
"specs": [
[
"==",
"5.12.0"
]
]
},
{
"name": "iniconfig",
"specs": [
[
"==",
"2.0.0"
]
]
},
{
"name": "jaraco.classes",
"specs": [
[
"==",
"3.2.3"
]
]
},
{
"name": "keyring",
"specs": [
[
"==",
"23.13.1"
]
]
},
{
"name": "markdown-it-py",
"specs": [
[
"==",
"2.2.0"
]
]
},
{
"name": "mdurl",
"specs": [
[
"==",
"0.1.2"
]
]
},
{
"name": "mock",
"specs": [
[
"==",
"5.0.1"
]
]
},
{
"name": "more-itertools",
"specs": [
[
"==",
"9.1.0"
]
]
},
{
"name": "mypy-extensions",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "nose",
"specs": [
[
"==",
"1.3.7"
]
]
},
{
"name": "packaging",
"specs": [
[
"==",
"23.0"
]
]
},
{
"name": "pathspec",
"specs": [
[
"==",
"0.11.1"
]
]
},
{
"name": "pkginfo",
"specs": [
[
"==",
"1.9.6"
]
]
},
{
"name": "platformdirs",
"specs": [
[
"==",
"3.1.1"
]
]
},
{
"name": "pluggy",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "Pygments",
"specs": [
[
">=",
"2.15.0"
]
]
},
{
"name": "pyproject_hooks",
"specs": [
[
"==",
"1.0.0"
]
]
},
{
"name": "pytest",
"specs": [
[
"==",
"7.2.2"
]
]
},
{
"name": "readme-renderer",
"specs": [
[
"==",
"37.3"
]
]
},
{
"name": "requests",
"specs": [
[
"==",
"2.31.0"
]
]
},
{
"name": "requests-toolbelt",
"specs": [
[
"==",
"0.10.1"
]
]
},
{
"name": "rfc3986",
"specs": [
[
"==",
"2.0.0"
]
]
},
{
"name": "rich",
"specs": [
[
"==",
"13.3.2"
]
]
},
{
"name": "six",
"specs": [
[
"==",
"1.16.0"
]
]
},
{
"name": "tomli",
"specs": [
[
"==",
"2.0.1"
]
]
},
{
"name": "twine",
"specs": [
[
"==",
"4.0.2"
]
]
},
{
"name": "typing_extensions",
"specs": [
[
"==",
"4.5.0"
]
]
},
{
"name": "urllib3",
"specs": [
[
"==",
"1.26.15"
]
]
},
{
"name": "webencodings",
"specs": [
[
"==",
"0.5.1"
]
]
},
{
"name": "zipp",
"specs": [
[
"==",
"3.15.0"
]
]
}
],
"lcname": "pesapal-py"
}