Payment Flow
To explain the payment flow, let's take a look at the following diagram:
1. Create Checkout Session
- Python SDK
- JavaScript SDK
pip install notrix
from notrix import Client, CheckoutSessionLineItem
client = Client("SECRET_API_KEY", "PROJECT_ID")
checkout_session = client.create_checkout_session(
success_url="https://myshop.com/successful-payment",
cancel_url="https://myshop.com/payment-canceled",
items=[
CheckoutSessionLineItem(
name="Bike",
description="green bike",
price=28.2, # USD
quantity=1,
imageURL="https://images.com/bike",
)
]
)
print(checkout_session.link()) # Redirect the user to this payment page link in order to pay
npm install notrix
import Client from "notrix";
let client = new Client("SECRET_API_KEY", "PROJECT_ID");
let checkoutSession = await client.createCheckoutSession(
[
{
name: "Bike",
description: "green",
price: 32.56, // USD
quantity: 1,
imageURL: "https://example.com/bike.png" // make sure the image is available from the notrix.io domain
}
],
"https://example.com/success",
"https://example.com/cancel",
);
console.log(checkoutSession.url); // redirect the user here to pay
2. Save Checkout Session to DB and Redirect
After creating the checkout session, save it to your DB and mark its status as pending. Now, redirect the user to the payment page link to proceed with the payment. Once the payment is confirmed, the user will be redirected to the success URL provided during the checkout session creation, And a webhook will be sent if configured.
3. Check Payment Status
After the user is redirected to the success URL, verify the payment confirmation by checking the status of the checkout session. Only then should you initiate the post-payment process.
danger
You MUST check the checkout session status before starting the post-payment process.
- Python SDK
- JavaScript SDK
pip install notrix
from notrix import Client
client = Client("<SECRET_API_KEY>", "PROJECT_ID")
payment_confirmed = client.is_paid(checkout_session.paymentRequestToken) # True / False
npm install notrix
import Client from "notrix";
let client = new Client("SECRET_API_KEY", "PROJECT_ID");
let paymentConfirmed = await client.isPaid(checkoutSession.paymentRequestToken); // true / false