def order_refund(): required_fields = [ "channel", "total_fee", "mch_refund_no", "refund_fee" ] data = request.json if not utils.validate_required_fields(required_fields=required_fields, data=data): return {"error": "Missing Required Fields: {required_fields}".format(required_fields=required_fields)} selection_fields = [ "mch_order_no", "ksher_order_no", "channel_order_no" ] if not utils.validate_selection_fields(selection_fields=selection_fields, data=data): return {"error": "Missing One of these Fields: {selection_fields}".format(selection_fields=selection_fields)} appid = data.get("appid", utils.get_app_id(PRIVATE_KEY_PATH)) fields = { "appid": appid, "channel": data["channel"], "total_fee": data["total_fee"], "fee_type": data.get("fee_type", "THB"), "mch_refund_no": data["mch_refund_no"], "refund_fee": data["refund_fee"] } optional_fields = [ "product", "attach", "device_id", "operator_id" ] for field in selection_fields: if field in data.keys(): fields.update({field: data[field]}) for field in optional_fields: if field in data.keys(): fields.update({field: data[field]}) payment = ksherpay.KsherPay( appid=fields["appid"], privatekey=PRIVATE_KEY_PATH ) _logger.info("Order Refund: {fields}".format(fields=fields)) resp = payment.order_refund(**fields) return resp
def order_reverse(): required_fields = [ "channel" ] data = request.json if not utils.validate_required_fields(required_fields=required_fields, data=data): return {"error": "Missing Required Fields: {required_fields}".format(required_fields=required_fields)} selection_fields = [ "mch_order_no", "ksher_order_no", "channel_order_no" ] if not utils.validate_selection_fields(selection_fields=selection_fields, data=data): return {"error": "Missing One of these Fields: {selection_fields}".format(selection_fields=selection_fields)} appid = APP_ID fields = { "appid": appid, "channel": data["channel"] } optional_fields = [ "product", "attach", "device_id", "operator_id" ] for field in selection_fields: if field in data.keys(): fields.update({field: data[field]}) for field in optional_fields: if field in data.keys(): fields.update({field: data[field]}) payment = ksherpay.KsherPay( appid=fields["appid"], privatekey=PRIVATE_KEY ) _logger.info("Order Reverse: {fields}".format(fields=fields)) resp = payment.order_reverse(**fields) return resp
def order_query(): required_fields = [ "channel" ] data = request.json if not utils.validate_required_fields(required_fields=required_fields, data=data): return {"error": "Missing Required Fields: {required_fields}".format(required_fields=required_fields)} selection_fields = [ "mch_order_no", "ksher_order_no", "channel_order_no" ] if not utils.validate_selection_fields(selection_fields=selection_fields, data=data): return {"error": "Missing Required Fields: {required_fields}".format(required_fields=required_fields)} appid = data.get("appid", utils.get_app_id(PRIVATE_KEY_PATH)) fields = { "appid": appid, "channel": data["channel"] } for field in selection_fields: if field in data.keys(): fields.update({field: data[field]}) payment = ksherpay.KsherPay( appid=fields["appid"], privatekey=PRIVATE_KEY_PATH ) _logger.info("Order Query: {fields}".format(fields=fields)) resp = payment.order_query(**fields) return resp