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.1.tar.gz (7.3 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.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: lunipay-0.1.1.tar.gz
  • Upload date:
  • Size: 7.3 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.1.tar.gz
Algorithm Hash digest
SHA256 68f61ccccfa32f4b3619514e49337e1763f0cab073484fa6aa77774f9694dcc6
MD5 f1406cd3001b1bf8b67f764c7efb73ce
BLAKE2b-256 fa9d74a63de50453748480e66bd8e3df981254467feb5d06b5764eef85ef5699

See more details on using hashes here.

Provenance

The following attestation bundles were made for lunipay-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: lunipay-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 950094e27fd759a80750fcd8c5497f1af7d5f8ff384a9c1f8bb1b897c5f22f15
MD5 e9c15dabd8c7847c6a53bd37fc6faecc
BLAKE2b-256 70199ab11d87ccad3f5c87a14e56fe53c20478b97a782bf638874d7252215e34

See more details on using hashes here.

Provenance

The following attestation bundles were made for lunipay-0.1.1-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