Installation and Usage¶
Usage¶
To use SSLCommerz Client in a project:
from sslcommerz_client import SSLCommerzClient
Initiate Client¶
To initiate a client:
from sslcommerz_client import SSLCommerzClient
client = SSLCommerzClient(
store_id="YOUR_STORE_ID",
store_passwd="YOUR_STORE_PASSWORD",
sandbox=True // default false
)
Initiate a Session¶
To Initiate a Session:
post_data = {
"total_amount": 100,
"currency": "BDT",
"tran_id": "221122",
"product_category": "fashion",
"success_url": "https://example.com",
"fail_url": "https://example.com",
"cancel_url": "https://example.com",
"cus_name": "Jon Osterman",
"cus_email": "jon@osterman.com",
"shipping_method": "NO",
"num_of_item": 1,
"product_name": "Fancy Pants",
"product_category": "Cloth",
"product_profile": "physical-goods",
"cus_add1": "Some Address",
"cus_city": "Dhaka",
"cus_country": "Bangladesh",
"cus_phone": "01558221870",
}
response = client.initiateSession(post_data)
response
will be an APIResponse
object with raw_data
- the actual response, status_code
for convenience, and an response
- a PaymentInitResponse
. One can use PaymentInitResponse
as is or create a dict or json from it. For more, consult pydantic
documentation.
Validate IPN¶
To validate an IPN response:
validation = client.validateIPN(data) // data: response data as a dict.
validation
will be an IPNValidationStatus
with validation status as status
and the response as IPNResponse
.
Getting Order Validation Data¶
data = {"val_id": "some_val_id"}
validation_response = client.getOrderValidationData(data)
validation_response
will be an APIResponse
object with raw_data
- the actual response, status_code
for convenience, and an response
- a OrderValidationResponse
.
Initiate Refund¶
data = {
"bank_tran_id": "some_tran_id",
"refund_amount": "100.00",
"refund_remarks": "faulty product"
}
refund_response = client.initiateRefund(data)
refund_response
will be an APIResponse
object with raw_data
- the actual response, status_code
for convenience, and an response
- a RefundInitiateResponse
.
Get Refund Data¶
refund_response = client.getRefundData("refund_ref_id")
refund_response
will be an APIResponse
object with raw_data
- the actual response, status_code
for convenience, and an response
- a RefundResponse
.
Get Transaction by Session¶
transaction_response = client.getTransactionBySession("sessionkey")
transaction_response
will be an APIResponse
object with raw_data
- the actual response, status_code
for convenience, and an response
- a TransactionBySessionResponse
.
Get Transactions by ID¶
transaction_response = client.getTransactionsByID("tran_id")
transaction_response
will be an APIResponse
object with raw_data
- the actual response, status_code
for convenience, and an response
- a TransactionsByIDResponse
.