Get start with Website API by using SDK.

This some example use SDK to call website API payment.

  • Download SDK from Github following SDK page support.

  • Download privatekey by

  • in page "IT integration" will display "appid", copy for use when request data.

  • change "appid", "mch_code" and private key in SDK.

  • change "total_fee" to "100" (add 00 for decimal) "channel_list" to wallet channel name.

  • Try to call gateway_pay if evrything correct you will got link payment.


from ksher.ksher_pay_sdk import KsherPay

appid = "mch35000"
privatekey = "/Users/yourpath/repo/ksher_sdk_python/mch_privkey.pem"
pubkey = "/Users/yourpath/repo/ksher_sdk_python/ksher_pubkey.pem"

payment_handle = KsherPay(appid, privatekey, pubkey)
data = {
    "total_fee": "100",
    "fee_type": "THB",                                                      # Currency code
    "mch_code": "",                                                         # order transaction
    "refer_url": "",                                    # homepage
    "mch_redirect_url":"",      # success page to redirected
    "mch_redirect_url_fail":"",    # fail page to redirected
    "mch_notify_url":"",    # call back over API after paid success
    "product_name":"",                                                      # product name display to customer
    "channel_list":"promptpay,linepay,airpay,truemoney,atome,card,ktc_instal,kbank_instal,kcc_instal,kfc_instal,scb_easy,bbl_deeplink,baybank_deeplink,kplus,alipay,wechat,card,ktc_instal,kbank_instal,kcc_instal,kfc_instal"                          # Payment list can select.
data['mch_order_no'] = "HelloWebsite"
resp = payment_handle.gateway_pay(data)
  • After run you will got JSON response like this

    "code": 0,
    "data": {
        "pay_content": ""
    "lang": "",
    "message": "SUCCESS",
    "msg": "SUCCESS",
    "sign": "6608b289c41550669d34236fd878045a5f95ad4a67b40988c4892ff71972ce2d809f453284b81c2c64dea5fbee826e6e81bf67a1644439a7e7917e555fbf8a9e"
  • 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": "操作成功"