Пример #1
0
    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
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    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
Пример #5
0
    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
Пример #6
0
    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
Пример #7
0
    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
Пример #8
0
    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
Пример #9
0
 def _batch_transfer_url(self):
     return get_random_host() + 'rest/transfers'
Пример #10
0
 def _bc_transfer_url(self):
     return get_random_host() + 'rest/bc_transfer'
Пример #11
0
 def _bill_refund_url(self):
     return get_random_host() + 'rest/refund'
Пример #12
0
 def _international_pay_url(self):
     return get_random_host() + 'rest/international/bill'
Пример #13
0
 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'
Пример #14
0
 def _batch_transfer_url(self):
     return get_random_host() + 'rest/transfers'
Пример #15
0
 def _bc_transfer_url(self):
     return get_random_host() + 'rest/bc_transfer'
Пример #16
0
 def _bill_refund_url(self):
     return get_random_host() + 'rest/refund'
Пример #17
0
 def _international_pay_url(self):
     return get_random_host() + 'rest/international/bill'
Пример #18
0
 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'