Skip to main content

Python SDK

Official package:

PyPI

Installation

pip install payisland

Initialize a Transaction

from payisland import PayIsland
import os
import time

payisland = PayIsland(secret_key=os.environ["PAYISLAND_SECRET_KEY"])

response = payisland.transactions.initialize({
"callback_url": "https://example.com/webhooks/payislands",
"payment_item_id": "6",
"transaction_reference": f"order_{int(time.time())}",
"channel": "card",
"amount": "1000",
"customer_info": {
"email": "ada@example.com",
"phone_number": "08011112222",
"first_name": "Ada",
"last_name": "Lovelace"
}
})

print(response["data"]["authorization_url"])

Redirect the customer to response["data"]["authorization_url"] to complete payment.

Verify a Transaction

verification = payisland.transactions.verify("order_12345")
status = verification["data"]["payment_status"]

if status in ["paid", "successful", "success"]:
# Fulfill the order.
pass
elif status in ["pending", "unpaid"]:
# Wait for completion and verify again later.
pass
else:
# Treat as failed or not completed.
pass

The SDK calls:

GET /api/v1/transactions/in/check-transaction-status/{reference}

Webhook Signature Verification

is_valid = payisland.webhooks.verify_signature(
payload=raw_payload,
signature=signature,
secret=os.environ["PAYISLAND_WEBHOOK_SECRET"],
)

if not is_valid:
raise ValueError("Invalid PayIsland webhook signature")

verification = payisland.transactions.verify(webhook["reference"])

Verify the transaction reference before fulfilling, even after a valid webhook signature.

Notes

  • Use PAYISLAND_SECRET_KEY only on the server.
  • PayIsland chooses sandbox or live mode from the API key.
  • The default API base URL is https://ags.payislands.com.
  • Amounts are strings in the major currency unit. "1000" means NGN 1,000.