AfroPin for Python
The AfroPin gift card API from Python: sell, top up and redeem PINs, quotes, stores and webhooks.
pip install afropin
Python 3.8 or newer. No dependencies.
Start
import os
from afropin import Client
afropin = Client(os.environ["AFROPIN_KEY_ID"], os.environ["AFROPIN_SECRET"])
Your API key's mode decides whether you work with test or live records; the address is the same for both. Keep the secret on your server, never in a browser or app.
Reseller: sell a PIN
pin = afropin.reseller.pins.sell({
"catalog_id": catalog_id, # from afropin.reseller.catalog.list()
"amount": 5000,
"external_reference": order_id, # your own reference; reusing it fails safely
"first_name": "Ada",
"last_name": "Obi",
"email": "ada@example.com",
})
pin["pin_code"] # the full code: returned only here, so deliver it to your customer now
Brand: check and redeem a PIN
check = afropin.brand.pins.check({"pin_code": code, "amount": 2500})
if check["can_redeem"]:
afropin.brand.pins.redeem({"pin_code": code, "amount": 2500, "external_reference": sale_id})
Methods use snake_case (top_up, new_code, wallet_links); every call is listed in METHODS.md.
Parameters and response fields are the API's own, as in the developer docs.
Errors
from afropin import AfroPinError
try:
afropin.reseller.pins.top_up({"pin_id": pin_id, "amount": 1000, "external_reference": ref})
except AfroPinError as error:
error.code # for example pin_not_found, amount_too_large, duplicate_external_reference
error.fields # per-field messages for input problems
error.status # HTTP status, or 0 when the API wasn't reached (connection_failed)
Branch on code; the message is for people and may change.
Lists
Lists return a Page: iterate it, and read paging for page, pages and total.
page = afropin.brand.payments.list({"limit": 50})
for payment in page:
...
if page.has_more:
following = afropin.brand.payments.list({"limit": 50, "page": page.paging["page"] + 1})
Idempotency and retries
Each request gets a new Idempotency-Key. To use your own: sell(params, idempotency_key=key). Nothing is retried for
you. If a sale times out, send it again with the same external_reference: it either goes through once, or fails with
duplicate_external_reference.
Webhooks
from afropin import webhooks
# Flask
event = webhooks.parse(request.get_data(), request.headers.get("webhook-secret"), WEBHOOK_SECRET)
if event["type"] == "pin.spent":
...
parse raises invalid_signature when the signature doesn't match. Use the raw body exactly as received.
Metadata
Release files for afropin 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| afropin-1.0.0.tar.gz | 10.5 kB | Without provenance | Details for afropin-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| afropin-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for afropin-1.0.0-py3-none-any.whl |
Total release size: 19.8 kB
Release files / afropin-1.0.0.tar.gz
| Download URL | afropin-1.0.0.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7efc2b12511c0ff254efd6235953e1d4f4717722ff95b84af0ca80bdd2a72e05
|
|
BLAKE2b-256 checksum How to use checksums |
e82316607798d1ca39eb1038e32c322bf97db061d9e6eddc749d8e1c6e48946a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / afropin-1.0.0-py3-none-any.whl
| Download URL | afropin-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91d2c24ddb6ad710cfe3ab04e26720ff44a8de56217e5a9ad066a9d8a0a39232
|
|
BLAKE2b-256 checksum How to use checksums |
ca1f0f099068fe0d12f100cce436448c936f8a1a16ba4b16ddbb46280d6a3d37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for afropin 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.