Skip to main content

Safepay's python SDK for checkout integration

Project description

Safepay Python SDK

Official python library for Safepay API.

Installation

With Pip

python3 -m pip install safepay_python

Usage

Import and create a Safepay client by passing your config;

from "python_sdk" import safepay;

env = safepay.Safepay(
    {
        "environment": "sandbox",
        "apiKey": "sec_asd12-2342s-1231s",
        "v1Secret": "bar",
        "webhookSecret": "foo",
    }
)

You can now create payments and checkout links.

Payments

Create payment

Parameter Type Required
amount number Yes
currency PKR, USD Yes
payment_response = env.set_payment_details({"amount": 10000, "currency": "PKR"})

token = payment_response["data"]["token"]



# Pass `token` to create checkout link

Checkout

Create checkout link

Parameter Type Description Required
token string Token from env.set_payment_details Yes
orderId string Your internal invoice / order id No
cancelUrl string Url to redirect to if user cancels the flow Yes
redirectUrl string Url to redirect to if user completes the flow Yes
source string Optional, defaults to custom No
webhooks boolean Optional, defaults to false No
checkout_url = env.get_checkout_url(
    {
        "beacon": token,
        "cancelUrl": "http://example.com/cancel",
        "orderId": "T800",
        "redirectUrl": "http://example.com/success",
        "source": "custom",
        "webhooks": True,
    }
)


# set webhooks = True if want to subscribe to webhooks
# redirect user to `url`

Verification

Signature

Parameter Type Description Required
request object The req object from your server Yes
signature_verification = env.is_signature_valid({"sig": "abcd", "tracker": token})


# mark the invoice as paid if valid
# show an error if invalid

Webhook

Parameter Type Description Required
request object The req object from your server Yes
webhook_verification = env.is_webhook_valid(
    {"x-sfpy-signature": "abcd"}, {"data": data}
)



# mark the invoice as paid if valid
# show an error if invalid

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

safepay_python-0.0.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

safepay_python-0.0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file safepay_python-0.0.2.tar.gz.

File metadata

  • Download URL: safepay_python-0.0.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for safepay_python-0.0.2.tar.gz
Algorithm Hash digest
SHA256 310192868f50bb03a839c44755b21a3a7ec4dce07c20410e5f0fb8d1be038d56
MD5 503b7d92a316b31957c849af8caa8ea0
BLAKE2b-256 29651d88a34ed51a5ff391cf8d84d0371700243b431406c44370844937a22c48

See more details on using hashes here.

File details

Details for the file safepay_python-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: safepay_python-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for safepay_python-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6c7d3c3c865f59d38e0e0dd7d2ecc2efa5f6be95931867ad6e6e2806c3930e4
MD5 96d38ea878f31b330b48c4938e628c32
BLAKE2b-256 2c77d2846bb39a18dfe00b714852212f444d61c68a08bf7c5a48822c30ac2ccd

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