def _query_orders_count(self, query_params, query_type): if query_params.need_detail or query_params.skip or query_params.limit: raise ValueError('need_detail or skip or limit should NOT be used to query order count') if query_type == _OrderType.BILL: if query_params.refund_no: raise ValueError('refund_no should NOT be used to query bills') if query_params.need_approval: raise ValueError('need_approval should NOT be used to query bills') partial_url = get_random_host() + self._query_bills_url() + '/count' elif query_type == _OrderType.REFUND: if query_params.spay_result: raise ValueError('spay_result should NOT be used to query refunds') partial_url = get_random_host() + self._query_refunds_url() + '/count' else: return attach_app_sign(query_params, BCReqType.QUERY, self.bc_app) url = partial_url + '?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.count = resp_dict.get('count') return bc_result
def _query_order_by_id(self, order_id, query_type): if query_type == _OrderType.BILL: partial_url = get_random_host() + self._query_bill_url() elif query_type == _OrderType.REFUND: partial_url = get_random_host() + self._query_refund_url() else: return query_params = _TmpObject() attach_app_sign(query_params, BCReqType.QUERY, self.bc_app) url = partial_url + '/' + order_id + '?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: if query_type == _OrderType.BILL: order_dict = resp_dict.get('pay') bc_result.pay = self._parse_dict_to_obj(order_dict, _OrderType.BILL) else: order_dict = resp_dict.get('refund') bc_result.refund = self._parse_dict_to_obj(order_dict, _OrderType.REFUND) 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_orders(self, query_params, query_type): if query_type == _OrderType.BILL: if query_params.refund_no: raise ValueError('refund_no should NOT be used to query bills') if query_params.need_approval: raise ValueError('need_approval should NOT be used to query bills') partial_url = get_random_host() + self._query_bills_url() elif query_type == _OrderType.REFUND: if query_params.spay_result: raise ValueError('spay_result should NOT be used to query refunds') partial_url = get_random_host() + self._query_refunds_url() else: return attach_app_sign(query_params, BCReqType.QUERY, self.bc_app) url = partial_url + '?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: if query_type == _OrderType.BILL: order_dict_arr = resp_dict.get('bills') else: order_dict_arr = resp_dict.get('refunds') orders = [] if order_dict_arr: orders = [self._parse_dict_to_obj(order_dict, query_type) for order_dict in order_dict_arr] bc_result.count = len(orders) if query_type == _OrderType.BILL: bc_result.bills = orders else: bc_result.refunds = orders return bc_result
def _batch_transfer_url(self): return get_random_host() + 'rest/transfers'
def _bc_transfer_url(self): return get_random_host() + 'rest/bc_transfer'
def _bill_refund_url(self): return get_random_host() + 'rest/refund'
def _international_pay_url(self): return get_random_host() + 'rest/international/bill'
def _bill_pay_url(self): if self.bc_app.is_test_mode: return get_random_host() + 'rest/sandbox/bill' else: return get_random_host() + 'rest/bill'