Skip to main content

SocialPay payment gateway SDK for Python

Project description

mongolian-payment-socialpay

SocialPay payment gateway SDK for Python.

Provides both synchronous and asynchronous clients with automatic HMAC-SHA256 checksum generation.

Installation

pip install mongolian-payment-socialpay

Quick start

Synchronous usage

from mongolian_payment_socialpay import SocialPayClient, SocialPayConfig

config = SocialPayConfig(
    terminal="YOUR_TERMINAL",
    secret="YOUR_SECRET",
    endpoint="https://api.socialpay.mn",
)

with SocialPayClient(config) as client:
    # Create an invoice with phone notification
    result = client.invoice_phone(amount=5000, invoice="INV001", phone="99001234")
    print(result.description, result.status)

    # Create an invoice with QR code
    qr = client.invoice_qr(amount=3000, invoice="INV002")

    # Check a transaction
    txn = client.check_transaction(amount=5000, invoice="INV001")
    print(txn.approval_code, txn.response_code)

    # Cancel an invoice
    client.cancel_invoice(amount=5000, invoice="INV001")

    # Cancel a transaction
    client.cancel_transaction(amount=5000, invoice="INV001")

    # Settle transactions
    settlement = client.transaction_settlement(settlement_id="SETTLE001")
    print(settlement.amount, settlement.count)

Asynchronous usage

import asyncio
from mongolian_payment_socialpay import AsyncSocialPayClient, SocialPayConfig

config = SocialPayConfig(
    terminal="YOUR_TERMINAL",
    secret="YOUR_SECRET",
    endpoint="https://api.socialpay.mn",
)

async def main():
    async with AsyncSocialPayClient(config) as client:
        result = await client.invoice_phone(amount=5000, invoice="INV001", phone="99001234")
        print(result.description, result.status)

asyncio.run(main())

Configuration from environment variables

Set the following environment variables:

export SOCIALPAY_TERMINAL="YOUR_TERMINAL"
export SOCIALPAY_SECRET="YOUR_SECRET"
export SOCIALPAY_ENDPOINT="https://api.socialpay.mn"

Then load them:

from mongolian_payment_socialpay import SocialPayClient, load_config_from_env

config = load_config_from_env()
client = SocialPayClient(config)

Error handling

All API errors raise SocialPayError, which includes:

  • status_code -- the HTTP or SocialPay-level error code
  • response -- the raw response body, if available
from mongolian_payment_socialpay import SocialPayError

try:
    client.invoice_qr(amount=1000, invoice="INV999")
except SocialPayError as e:
    print(e.status_code, e.response)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mongolian_payment_socialpay-1.0.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mongolian_payment_socialpay-1.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file mongolian_payment_socialpay-1.0.0.tar.gz.

File metadata

File hashes

Hashes for mongolian_payment_socialpay-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e7321ea487cc48f9129a1821ed7ed604b3e27ce6e977e1cb07b0412014c317d9
MD5 22570d66a4e1a5ba5ce35a0248cb3fb0
BLAKE2b-256 9efbd0634d6368bb8731adbbbd55f3b00166fdfd1e0bb6abe706b114a984a8de

See more details on using hashes here.

File details

Details for the file mongolian_payment_socialpay-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mongolian_payment_socialpay-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f498bd83f83e83dc1bf9b822a0b5ee58a108dc7c3f1c92196a4238e150d183b2
MD5 17825e27d6d5fc3e19726cee7dadfecf
BLAKE2b-256 530db4e6005e228bc283d3ab5b928db1212b116ed9e5e5aa6c84d41cb578e991

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page