Get start with Website API by using SDK.

This some example use python SDK to call website API payment.

  • Download SDK from Github or see SDK page. for more detail.

find merchantNo02

Example

#python lang

from ksher_pay_sdk import KsherPay

ksher_pay = KsherPay(appid='mch32625', privatekey='./mch_privkey.pem', pubkey='./ksher_pubkey.pem')

response = ksher_pay.gateway_pay(**{
    'mch_order_no': '77721',                                                        # order transection
    'total_fee': 100,                                                               # add 00 for decimal
    'fee_type': 'THB',                                                              # Currency code
    'channel_list': "alipay,wechat,linepay,airpay,promptpay,truemoney,ktbcard", # Payment list can select.
    'mch_code': '77721',                                                            # order transection
    'mch_redirect_url': 'https://www.baidu.com/',                                   # succeed page to redirected
    'mch_redirect_url_fail': 'https://www.baidu.com/',                              # fail page to redirected
    'refer_url': 'https://www.baidu.com/',                                          # homepage,
    "mch_notify_url":"http://abc.io/api/gateway_pay/notify_url/"
    'product_name': 'sdd'                                                           #
})
  • After run you will got JSON response like this

{
    "code": 0,
    "data": {
        "pay_content": "https://gateway.ksher.com/ua?order_uuid=70582bb6515811eb93bc52540075451d"
    },
    "message": "SUCCESS",
    "msg": "SUCCESS",
    "sign": "4abc60af7bd847676418fad410daaec6c98243a82c03c1ff793f12dcaeb915b5168a7d9711913231e2cbcb47e67a09ed390ac265277eaff1969885a67852d246"
}
  • copy URL inside "pay_content" to Web browser you will see website like this.

pc checkout
  • After paid success, it will redirect to URL "mch_redirect_url" you config.

  • checking webhook response at "mch_notify_url". If customer paid merchant will got response on webhook.

//Example JSON Webhook response

{
    "code": 0,
    "msg": "操作成功",
    "data": {
        "channel": "airpay",
        "openid": "",
        "channel_order_no": "1223163330",
        "cash_fee_type": "",
        "ksher_order_no": "90020210419144106177287",
        "nonce_str": "wrveV11olt7dnVirIy8JIwqd2XyAhBcP",
        "time_end": "2021-04-19 13:41:47",
        "fee_type": "THB",
        "attach": "",
        "rate": "1.000000",
        "result": "SUCCESS",
        "total_fee": 100,
        "appid": "mch35005",
        "cash_fee": "",
        "mch_order_no": "202104191340",
        "pay_mch_order_no": "2104191340545623"
    },
    "sign": "382ce3cda4c7959ff663fcda9289e13a0d582bafe37a4605213c98ffe794baca396add79d9af6567a50797eb9fd6bcb62177fcbd971f0f9f2d7a40942c6da4e9",
    "message": "操作成功"
}