Skip to content
On this page

Python SDK ​

SDK (Software Development Kit) is a convenient and intuitive toolkit for integrating your Python application with our PolusPay payment system. This allows you to easily and securely accept crypto payments and receive information about payments in the PolusPay system.

Get started ​

Install PolusPay library using pip

pip install poluspay

Import the Merchant class and initialize it by passing two input parameters: merchant_id and signing_key

python
from poluspay import Merchant

merchant = Merchant(
    merchant_id="YOUR_MERCHANT_ID",
    signing_key="YOUR_MERCHANT_SIGNING_KEY"
)

Values of merchant_id and signing_key can be found in PolusPay admin panel.

Now that you have your merchant class initialized, you can start creating payments.

Payment creation ​

PolusPay SDK provides two main ways to create payments: basic and advanced. Consider both of these methods.

Basic (lite) payment creation ​

WARNING

The basic method involves pre-setting the merchant's payment parameters in the PolusPay admin panel. You need to set up a list of default blockchains used when making a payment.

python
from poluspay import Merchant
from poluspay.asset import USDT

merchant = Merchant(
    merchant_id="YOUR_MERCHANT_ID",
    signing_key="YOUR_MERCHANT_SIGNING_KEY"
)

payment = merchant.CreatePayment(
    description="My test payment",
    amount="1.00",
    asset=USDT,
    payload="abc123abc"
)

In this example, we create a payment using the CreatePayment method of the initialized Merchant class. After the successful creation of the payment, the variable payment will contain an instance of the PoluspayPayment class that stores information about the created payment.

CreatePayment

fieldtypedesc
descriptionstringdescription of your payment
amountstringpayment amount (in asset)
assetstring or PaymentAssetprefered currency to receive payment
payloadstringadditional info about payment, order ID for example (optional)

Advanced payment creation ​

This method of creating a payment provides more flexible settings. You can pass one or more blockchain objects to the blockchain parameter to accept the payment.

Blockchain object initialization ​

From poluspay.blockchain import the blockchain classes you need by passing the required parameters: asset, amount and address.

python
from poluspay.blockchain import Polygon, Ethereum
from poluspay.asset import USDT, USDC, BUSD

polygon = Polygon(
    asset=USDC,
    amount="2.00",
    address="0x..."
)

ethereum = Ethereum(
    asset=USDT,
    amount="2.75",
    address="0x..."
)

bsc = BSC(
    asset=BUSD,
    amount="2.25",
    address="0x..."
)

Creating payment ​

The main difference between the advanced method of creating payments and the basic one is that you can specify only the blockchains you need for each individual payment. Also, for each of the transmitted blockchains, you can configure the currency in which you want to receive the payment, the amount and the address for receiving the payment.

Note that for each blockchain you initialize, you can choose a different currency, amount, and also specify different addresses for accepting payments.

python
from poluspay import Merchant
from poluspay.blockchain import Polygon, Ethereum, BSC
from poluspay.asset import USDT, USDC, BUSD


merchant = Merchant(
    merchant_id="YOUR_MERCHANT_ID",
    signing_key="YOUR_MERCHANT_SIGNING_KEY"
)

polygon = Polygon(
    asset=USDC,
    amount="2.00",
    address="0x..."
)

ethereum = Ethereum(
    asset=USDT,
    amount="2.75",
    address="0x..."
)

bsc = BSC(
    asset=BUSD,
    amount="2.25",
    address="0x..."
)

payment1 = merchant.CreatePayment(
    description="Payment for 2.00 USDC only in Polygon blockchain",
    blockchain=polygon
)
    
payment2 = merchant.CreatePayment(
    description="Payment for 2.75 USDT in Ethereum blockchain or 2.25 BUSD in   Binance Smart Chain",
    blockchain=[ethereum, bsc]
)

In this example, we initialize 3 blockchains: Polygon, Ethereum and BSC with different currencies and amounts. Then we create two payments, the first payment will only support Polygon blockchain, while second payment will support two blockchains: Ethereum and BSC, the payment amount and currency will also differ depending on the blockchain (when paying in Ethereum, the user will pay you 2.75 USDT, but if the payment will be processed in Binance Smart Chain, then you will receive 2.25 BUSD)

CreatePayment

fieldtypedesc
descriptionstringdescription of your payment
blockchainPoluspayBlockchain or list[PoluspayBlockchain]One or more initialized PoluspayBlockchain classes, with flexible payment settings for each specific blockchain

Webhooks ​

PolusPay SDK provides a method for verifying the signature of the webhook that comes to you about the successful payment of the payment you created.

To verify the request, you need an initialized Merchant object, you must pass the x-signature header value and the request body to the VerifyWebhook method, after processing the request, the method will return you true or false, if you received true as a result of verification, then the webhook has been successfully verified and you can perform all the actions you need with this payment.

python
from flask import Flask, request
from poluspay.api.merchant import Merchant

app = Flask(__name__)

merchant = Merchant(
    merchant_id="YOUR_MERCHANT_ID",
    signing_key="YOUR_MERCHANT_SIGNING_KEY"
)

@app.route('/payments-webhook', methods=['POST'])
def payments_webhook_handler():

    # Get x-signature header
    x_sign_header = request.headers.get('x-signature')

    # Verifying webhook
    if merchant.VerifyWebhook(request.json, x_sign_header):

        # process the request...

        return 'request processed successfully'
    return 'unauthorized', 401


if __name__ == '__main__':
    host = '127.0.0.1'
    port = 8080

    print(f"server started on {host}:{port}")
    app.run(host='127.0.0.1', port=8080)

WARNING

Please note that in this example, a simple web server is implemented using the flask framework, if you are using a different framework for your application, then search the Internet for how to get the incoming request headers and request body for your framework.