def refund(self, refund_params): """ refund API, refund fee should not be greater than bill total fee; need_approval is for pre refund, you have to call [audit_pre_refunds] later on to execute real refund if the bill is paid with ali, you have to input your password on the returned url page refer to restful API https://beecloud.cn/doc/ #3 :param refund_params: beecloud.entity.BCRefundReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('refund') attach_app_sign(refund_params, BCReqType.REFUND, self.bc_app) tmp_resp = http_post(self._bill_refund_url(), refund_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.id = resp_dict.get('id') # url will be returned if bill is refunded and channel is in (ALI_APP, ALI_WEB, ALI_QRCODE) bc_result.url = resp_dict.get('url') return bc_result
def query_offline_bill_status(self, bill_no, channel=None): """ query offline bill status refer to https://beecloud.cn/doc/?index=rest-api-offline #3 :param bill_no: bill number :param channel: bill payment channel like WX_SCAN :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_offline_bill_status') query_params = _TmpObject() setattr(query_params, 'bill_no', bill_no) if channel: setattr(query_params, 'channel', channel) attach_app_sign(query_params, BCReqType.QUERY, self.bc_app) url = get_rest_root_url() + 'rest/offline/bill/status' tmp_resp = http_post(url, query_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: setattr(bc_result, 'pay_result', resp_dict.get('pay_result')) return bc_result
def query_offline_bill_status(self, bill_no, channel=None): """ query offline bill status refer to https://beecloud.cn/doc/?index=rest-api-offline #3 :param bill_no: bill number :param channel: bill payment channel like WX_SCAN :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_offline_bill_status') query_params = _TmpObject() setattr(query_params, 'bill_no', bill_no) if channel: setattr(query_params, 'channel', channel) attach_app_sign(query_params, BCReqType.QUERY, self.bc_app) url = get_rest_root_url() + 'rest/offline/bill/status' tmp_resp = http_post(url, query_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: setattr(bc_result, 'pay_result', resp_dict.get('pay_result')) return bc_result
def offline_refund(self, refund_params): """ offline payment refund API, refund fee should not be greater than bill total fee; need_approval is not allowed for offline refund refer to restful API https://beecloud.cn/doc/?index=rest-api-offline #6 :param refund_params: beecloud.entity.BCRefundReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('offline_refund') attach_app_sign(refund_params, BCReqType.REFUND, self.bc_app) tmp_resp = http_post(self._offline_refund_url(), refund_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.id = resp_dict.get('id') setattr(bc_result, "refund_result", resp_dict.get('refund_result')) return bc_result
def refund(self, refund_params): """ refund API, refund fee should not be greater than bill total fee; need_approval is for pre refund, you have to call [audit_pre_refunds] later on to execute real refund if the bill is paid with ali, you have to input your password on the returned url page refer to restful API https://beecloud.cn/doc/?index=rest-api #3 :param refund_params: beecloud.entity.BCRefundReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('refund') attach_app_sign(refund_params, BCReqType.REFUND, self.bc_app) tmp_resp = http_post(self._bill_refund_url(), refund_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.id = resp_dict.get('id') # url will be returned if bill is refunded and channel is in (ALI_APP, ALI_WEB, ALI_QRCODE) bc_result.url = resp_dict.get('url') return bc_result
def audit_pre_refunds(self, pre_refund_params): """ batch manage pre refunds; pre refund id list is required; each refund result is kept in result_map refer to restful API https://beecloud.cn/doc/?index=rest-api #4 :param pre_refund_params: beecloud.entity.BCPreRefundReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('audit_pre_refunds') attach_app_sign(pre_refund_params, BCReqType.REFUND, self.bc_app) tmp_resp = http_put(self._bill_refund_url(), pre_refund_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: # if agree is true and refund successfully bc_result.result_map = resp_dict.get('result_map') bc_result.url = resp_dict.get('url') return bc_result
def offline_refund(self, refund_params): """ offline payment refund API, refund fee should not be greater than bill total fee; need_approval is not allowed for offline refund refer to restful API https://beecloud.cn/doc/?index=rest-api-offline #6 :param refund_params: beecloud.entity.BCRefundReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('offline_refund') attach_app_sign(refund_params, BCReqType.REFUND, self.bc_app) tmp_resp = http_post(self._offline_refund_url(), refund_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.id = resp_dict.get('id') setattr(bc_result, "refund_result", resp_dict.get('refund_result')) return bc_result
def audit_pre_refunds(self, pre_refund_params): """ batch manage pre refunds; pre refund id list is required; each refund result is kept in result_map refer to restful API https://beecloud.cn/doc/ #4 :param pre_refund_params: beecloud.entity.BCPreRefundReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('audit_pre_refunds') attach_app_sign(pre_refund_params, BCReqType.PAY, self.bc_app) tmp_resp = http_put(self._bill_refund_url(), pre_refund_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: # if agree is true and refund successfully bc_result.result_map = resp_dict.get('result_map') bc_result.url = resp_dict.get('url') return bc_result
def offline_revert(self, bill_no, channel=None, method='REVERT'): """ offline payment revert API, WX_NATIVE is not supported refer to restful API https://beecloud.cn/doc/?index=rest-api-offline #4 :param bill_no: bill number :param channel: bill payment channel like ALI_SCAN :param method: currently only support 'REVERT' :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('offline_revert') tmp_obj = _TmpObject() if channel: setattr(tmp_obj, 'channel', channel) setattr(tmp_obj, 'method', method) attach_app_sign(tmp_obj, BCReqType.PAY, self.bc_app) tmp_resp = http_post(self._offline_pay_url() + '/' + bill_no, tmp_obj, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: setattr(bc_result, "revert_status", resp_dict.get('revert_status')) return bc_result
def query_refund_status(self, channel, refund_no): """ query refund status, it is for WX, YEE, KUAIQIAN, BD refer to https://beecloud.cn/doc/ #9 :param channel: str of WX, YEE, KUAIQIAN, BD :param refund_no: refund number :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_refunds_count') query_params = _TmpObject() query_params.channel = channel query_params.refund_no = refund_no attach_app_sign(query_params, BCReqType.QUERY, self.bc_app) url = get_random_host() + self._query_refund_url() + '/status?para=' + obj_to_quote_str(query_params) tmp_resp = http_get(url, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.refund_status = resp_dict.get('refund_status') return bc_result
def query_refund_status(self, channel, refund_no): """ query refund status, it is for WX, YEE, KUAIQIAN, BD refer to https://beecloud.cn/doc/ #9 :param channel: str of WX, YEE, KUAIQIAN, BD :param refund_no: refund number :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_refunds_count') query_params = _TmpObject() query_params.channel = channel query_params.refund_no = refund_no attach_app_sign(query_params, BCReqType.QUERY, self.bc_app) url = get_random_host() + self._query_refund_url() + '/status?para=' + obj_to_quote_str(query_params) tmp_resp = http_get(url, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.refund_status = resp_dict.get('refund_status') return bc_result
def offline_revert(self, bill_no, channel=None, method='REVERT'): """ offline payment revert API, WX_NATIVE is not supported refer to restful API https://beecloud.cn/doc/?index=rest-api-offline #4 :param bill_no: bill number :param channel: bill payment channel like ALI_SCAN :param method: currently only support 'REVERT' :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('offline_revert') tmp_obj = _TmpObject() if channel: setattr(tmp_obj, 'channel', channel) setattr(tmp_obj, 'method', method) attach_app_sign(tmp_obj, BCReqType.PAY, self.bc_app) tmp_resp = http_post(self._offline_pay_url() + '/' + bill_no, tmp_obj, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: setattr(bc_result, "revert_status", resp_dict.get('revert_status')) return bc_result
def bc_transfer(self, transfer_params): """ for BeeCloud transfer via bank card refer to https://beecloud.cn/doc/?index=rest-api-transfer :param transfer_params: beecloud.entity.BCCardTransferParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('bc_transfer') return self._bill_transfer(self._bc_transfer_url(), transfer_params)
def bc_transfer(self, transfer_params): """ for BeeCloud transfer via bank card refer to https://beecloud.cn/doc/?index=2 :param transfer_params: beecloud.entity.BCCardTransferParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('bc_transfer') return self._bill_transfer(self._bc_transfer_url(), transfer_params)
def query_refunds_count(self, query_params): """ query refunds count API refer to https://beecloud.cn/doc/ #8 :param query_params: beecloud.entity.BCQueryReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_refunds_count') return self._query_orders_count(query_params, _OrderType.REFUND)
def query_refunds_count(self, query_params): """ query refunds count API refer to https://beecloud.cn/doc/ #8 :param query_params: beecloud.entity.BCQueryReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_refunds_count') return self._query_orders_count(query_params, _OrderType.REFUND)
def query_refunds(self, query_params): """ query refunds API refer to https://beecloud.cn/doc/ #7 result contains a list(refunds), its items are beecloud.entity.BCRefund :param query_params: beecloud.entity.BCQueryReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_refunds') return self._query_orders(query_params, _OrderType.REFUND)
def query_refunds(self, query_params): """ query refunds API refer to https://beecloud.cn/doc/ #7 result contains a list(refunds), its items are beecloud.entity.BCRefund :param query_params: beecloud.entity.BCQueryReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_refunds') return self._query_orders(query_params, _OrderType.REFUND)
def query_refund_by_id(self, refund_id): """ query refund based on id(NOT refund number) refer to https://beecloud.cn/doc/ #10 result.refund is type of beecloud.entity.BCRefund :param refund_id: string type :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_refunds_count') return self._query_order_by_id(refund_id, _OrderType.REFUND)
def query_refund_by_id(self, refund_id): """ query refund based on id(NOT refund number) refer to https://beecloud.cn/doc/ #10 result.refund is type of beecloud.entity.BCRefund :param refund_id: string type :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('query_refunds_count') return self._query_order_by_id(refund_id, _OrderType.REFUND)
def transfer(self, transfer_params): """ for WX_REDPACK, WX_TRANSFER, ALI_TRANSFER refer to https://beecloud.cn/doc/?index=rest-api-transfer redpack_info should be type of beecloud.entity.BCTransferRedPack :param transfer_params: beecloud.entity.BCTransferReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('transfer') return self._bill_transfer(self._bill_transfer_url(), transfer_params)
def batch_transfer(self, transfer_params): """ batch transfer, currently only ALI is supported refer to https://beecloud.cn/doc/?index=2 transfer_data should be type of beecloud.entity.BCBatchTransferItem :param transfer_params: beecloud.entity.BCBatchTransferParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('batch_transfer') return self._bill_transfer(self._batch_transfer_url(), transfer_params)
def batch_transfer(self, transfer_params): """ batch transfer, currently only ALI is supported refer to https://beecloud.cn/doc/?index=rest-api-transfer transfer_data should be type of beecloud.entity.BCBatchTransferItem :param transfer_params: beecloud.entity.BCBatchTransferParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('batch_transfer') return self._bill_transfer(self._batch_transfer_url(), transfer_params)
def transfer(self, transfer_params): """ for WX_REDPACK, WX_TRANSFER, ALI_TRANSFER refer to https://beecloud.cn/doc/?index=2 redpack_info should be type of beecloud.entity.BCTransferRedPack :param transfer_params: beecloud.entity.BCTransferReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('transfer') return self._bill_transfer(self._bill_transfer_url(), transfer_params)
def international_pay(self, pay_params): """ international pay -- PayPal refer to https://github.com/beecloud/beecloud-rest-api/tree/master/international #2 credit_card_info should be type of beecloud.entity.BCPayPalCreditCard :param pay_params: beecloud.entity.BCInternationalPayParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('international_pay') attach_app_sign(pay_params, BCReqType.PAY, self.bc_app) req_dict = {} for k, v in pay_params.__dict__.items(): if v: if k == 'credit_card_info': req_dict[k] = obj_to_dict(v) else: req_dict[k] = v tmp_resp = http_post(self._international_pay_url(), req_dict, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.id = resp_dict.get('id') # url is returned when channel is PAYPAL_PAYPAL bc_result.url = resp_dict.get('url') # credit_card_id is returned when channel is PAYPAL_CREDITCARD bc_result.credit_card_id = resp_dict.get('credit_card_id') return bc_result
def international_pay(self, pay_params): """ international pay -- PayPal refer to https://github.com/beecloud/beecloud-rest-api/tree/master/international #2 credit_card_info should be type of beecloud.entity.BCPayPalCreditCard :param pay_params: beecloud.entity.BCInternationalPayParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('international_pay') attach_app_sign(pay_params, BCReqType.PAY, self.bc_app) req_dict = {} for k, v in pay_params.__dict__.items(): if v: if k == 'credit_card_info': req_dict[k] = obj_to_dict(v) else: req_dict[k] = v tmp_resp = http_post(self._international_pay_url(), req_dict, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.id = resp_dict.get('id') # url is returned when channel is PAYPAL_PAYPAL bc_result.url = resp_dict.get('url') # credit_card_id is returned when channel is PAYPAL_CREDITCARD bc_result.credit_card_id = resp_dict.get('credit_card_id') return bc_result
def offline_pay(self, pay_params): """ offline payment API, different channels have different requirements for request params and the return params varies. refer to restful API https://beecloud.cn/doc/?index=rest-api-offline #2 :param pay_params: beecloud.entity.BCPayReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('offline_pay') self._add_sdk_version(pay_params) attach_app_sign(pay_params, BCReqType.PAY, self.bc_app) tmp_resp = http_post(self._offline_pay_url(), pay_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.id = resp_dict.get('id') if resp_dict.get('pay_result') is not None: setattr(bc_result, 'pay_result', resp_dict.get('pay_result')) if resp_dict.get('code_url'): setattr(bc_result, 'code_url', resp_dict.get('code_url')) if resp_dict.get('channel_type'): setattr(bc_result, 'channel_type', resp_dict.get('channel_type')) return bc_result
def offline_pay(self, pay_params): """ offline payment API, different channels have different requirements for request params and the return params varies. refer to restful API https://beecloud.cn/doc/?index=rest-api-offline #2 :param pay_params: beecloud.entity.BCPayReqParams :return: beecloud.entity.BCResult """ if self.bc_app.is_test_mode: return report_not_supported_err('offline_pay') self._add_sdk_version(pay_params) attach_app_sign(pay_params, BCReqType.PAY, self.bc_app) tmp_resp = http_post(self._offline_pay_url(), pay_params, self.bc_app.timeout) # if err encountered, [0] equals 0 if not tmp_resp[0]: return tmp_resp[1] # [1] contains result dict resp_dict = tmp_resp[1] bc_result = BCResult() set_common_attr(resp_dict, bc_result) if not bc_result.result_code: bc_result.id = resp_dict.get('id') if resp_dict.get('pay_result') is not None: setattr(bc_result, 'pay_result', resp_dict.get('pay_result')) if resp_dict.get('code_url'): setattr(bc_result, 'code_url', resp_dict.get('code_url')) if resp_dict.get('channel_type'): setattr(bc_result, 'channel_type', resp_dict.get('channel_type')) return bc_result