Skip to main content

The official LuniPay Python SDK.

Project description

lunipay

The official LuniPay Python SDK.

pip install lunipay

Quick start

import lunipay

lunipay.api_key = "sk_test_YOUR_KEY"

session = lunipay.CheckoutSession.create(
    amount=5000,
    currency="usd",
    success_url="https://example.com/thanks?session_id={CHECKOUT_SESSION_ID}",
)

print(session["url"])

Resources

Every LuniPay resource is a top-level class on the module:

lunipay.Customer.create(email="ada@example.com", first_name="Ada", last_name="Lovelace")
lunipay.Customer.retrieve("cus_01JRZK...")
lunipay.Customer.modify("cus_01JRZK...", phone="+18765559999")
lunipay.Customer.delete("cus_01JRZK...")

for customer in lunipay.Customer.list().auto_paging_iter():
    print(customer["email"])

Supported resources: CheckoutSession, Customer, Invoice, Payment, PaymentLink, WebhookEndpoint, Event.

Webhooks

import lunipay

@app.post("/webhook")
def webhook():
    payload = request.get_data()
    sig = request.headers.get("LuniPay-Signature")
    try:
        event = lunipay.Webhook.construct_event(
            payload=payload,
            sig_header=sig,
            secret="whsec_your_secret",
        )
    except lunipay.error.SignatureVerificationError:
        return "bad signature", 400

    if event["type"] == "checkout.session.completed":
        # fulfill the order
        pass

    return "", 200

Errors

All LuniPay API errors raise subclasses of lunipay.error.LuniPayError:

try:
    lunipay.Customer.create(email="bad", first_name="x", last_name="y")
except lunipay.error.InvalidRequestError as e:
    print(e.code, e.param, str(e))

Subclasses: AuthenticationError, PermissionError, InvalidRequestError, IdempotencyError, RateLimitError, APIError, APIConnectionError.

Idempotency

Pass idempotency_key to any mutating request:

import uuid

key = str(uuid.uuid4())
session = lunipay.CheckoutSession.create(
    amount=5000,
    currency="usd",
    success_url="https://example.com/thanks",
    idempotency_key=key,
)

Full documentation

See lunipay.io/docs/sdks/python.

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

lunipay-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

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

lunipay-0.1.0-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file lunipay-0.1.0.tar.gz.

File metadata

  • Download URL: lunipay-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lunipay-0.1.0.tar.gz
Algorithm Hash digest
SHA256 68504a067285556710e722c275339907ab060bc861cf35e4dbb54d2527806e9e
MD5 10c19b62f32bd54b2429df9ab1612a6f
BLAKE2b-256 1d9e1575ede2b8b9b59f2d3792b091f7bb03f9356bfbd5f3764118a50769ec71

See more details on using hashes here.

Provenance

The following attestation bundles were made for lunipay-0.1.0.tar.gz:

Publisher: publish-python.yml on SammarieoBrown/lunipay-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lunipay-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lunipay-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lunipay-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 53d7d6cffe80a0d5eb7bf0348fd42a9450cb8458cc40f08e2f0fb63f04036cab
MD5 63f41369fe52537033efe0af8238a357
BLAKE2b-256 af06ba77eb19ff060a434bbd3dbc0a4a8ef32ac3c129d3fae0484794e4ac7fbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for lunipay-0.1.0-py3-none-any.whl:

Publisher: publish-python.yml on SammarieoBrown/lunipay-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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