Skip to main content

python implementation for Khser Payment API.

Project description

Payment_sdk_python

This is python sdk for intergrating your python application with Ksher Payment Gateway. Please refers to our official api document here

Requirement

  • Python 3.7

    • other python3 version should also work, but python package version might cause some conflice and minor change might need to be done.
  • Ksher Payment API Account

  • API_URL

    • Along with a sandbox accout, you will be receiving a API_URL in this format: s[UNIQUE_NAME].vip.ksher.net
  • API_TOKEN

    • Log in into API_URL using given sandbox account and get the token. see (How to get API Token)[https://doc.vip.ksher.net/docs/howto/api_token]

The Payment SDK for accessing *.vip.ksher.net

How to Install

there are two option two install this package;

  1. Pip Install This package
  2. Clone this repository

Option 2: Pip Install This package

pip install ksherpay

Option 1: Clone this repository

Step1: clone this repository

git clone https://github.com/ksher-solutions/payment_sdk_python

Step2: cd into cloned source code and pip install all the requriements and the package itself

cd payment_sdk_python
pip install -r requirements.txt
pip install .

How to Use

you need to first init the payment object and that you can use it to;

  • Init Payment Object
  • Create New Order
  • Query Order Status
  • Refund the Order

Init Payment Object

from ksherpay import Payment
API_URL = 'https://sandboxbkk.vip.ksher.net'
API_TOKEN = testtoken1234
payment_handle = Payment(base_url=API_URL, token=API_TOKEN)

Disable Sign Verification

In early phase of implementation. You might want to disable Sign Verification to debug on other thing without the need to worry if the bug is coming for signature.

*** for Security purpose, don't forget to enable this sign verfication back first before going on Production environment.

to disbable sign you simply do this;

from ksherpay import Payment
API_URL = 'https://sandboxbkk.vip.ksher.net'
API_TOKEN = testtoken1234
payment_handle = Payment(base_url=API_URL, token=API_TOKEN, verify=False)

Create New Order

merchant_order_id need to be unique or else the request will end with error

data = {
            "amount": 100,
            "merchant_order_id": "OrderId000001",
            "channel_list": "linepay,airpay,wechat,bbl_promptpay,truemoney,ktbcard",
            "note": "string",
            "redirect_url": "http://www.baidu.com",
            "redirect_url_fail": "http://www.baidu.com",
            "signature": "string",
            "timestamp": "string"
        }
resp = payment_handle.order.create(data)
print(resp.status_code) # this should return 200

Query order status

merchant_order_id = 'OrderId000001'
resp = payment_handle.order.query(merchant_order_id)
print(resp.status_code) # this should return 200

Refund

Refund_id need to be unique or else the request will end with error

merchant_order_id = 'OrderId000001'
refund_id = "Refund_" + merchant_order_id
data = {
    'refund_amount':100,
    'refund_order_id':refund_id
}
resp = payment_handle.order.refund(merchant_order_id,params=data)
print(resp.status_code) # this should return 200

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ksherpay-0.0.2.tar.gz (5.7 kB view hashes)

Uploaded Source

Built Distribution

ksherpay-0.0.2-py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page