Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def query_bc_transfer_supported_banks(self, transfer_type):
        """
        query bc_transfer supported banks, used by BCCardTransferParams field: bank_fullname
        :param transfer_type: P_DE:对私借记卡, P_CR:对私信用卡, C:对公账户
        :return:
        """
        query_param = _TmpObject()
        query_param.type = transfer_type
        url = get_rest_root_url() + 'rest/bc_transfer/banks?para=' + obj_to_quote_str(query_param)
        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.size = resp_dict.get('size')
            bc_result.bank_list = resp_dict.get('bank_list')

        return bc_result
Ejemplo n.º 3
0
def batch_add_merchant_users(bc_app, merchant, buyer_ids):
    """
    add merchant user
    :param bc_app: beecloud.entity.BCApp
    :param merchant: merchant account
    :param buyer_ids: merchant unique user id list
    :return: beecloud.entity.BCResult
    """
    req_param = _TmpObject()
    req_param.email = merchant
    req_param.buyer_ids = buyer_ids
    attach_app_sign(req_param, BCReqType.PAY, bc_app)

    url = get_rest_root_url() + 'rest/users'

    tmp_resp = http_post(url, req_param, 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)

    return bc_result
Ejemplo n.º 4
0
def attach_buyer_history_bills(bc_app, bill_info):
    """
    query merchant users
    :param bc_app: beecloud.entity.BCApp
    :param bill_info: {buyer_id: [bill_no...]...} dict, key is buyer id,
                        value is bill number list that belong to the buyer
    :return: result contains failed_bills, which indicates the bills that fail to connect to the buyer,
                failed_bills is also dict like bill_info
    """
    req_param = _TmpObject()
    req_param.bill_info = bill_info
    attach_app_sign(req_param, BCReqType.QUERY, bc_app)

    url = get_rest_root_url() + 'rest/history_bills'

    tmp_resp = http_put(url, req_param, 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 resp_dict.get('failed_bills'):
        bc_result.failed_bills = resp_dict.get('failed_bills')

    return bc_result
Ejemplo n.º 5
0
def add_merchant_user(bc_app, buyer_id):
    """
    add merchant user
    :param bc_app: beecloud.entity.BCApp
    :param buyer_id: merchant unique user id, can be used as buyer id for bill
    :return: beecloud.entity.BCResult
    """
    req_param = _TmpObject()
    req_param.buyer_id = buyer_id
    attach_app_sign(req_param, BCReqType.PAY, bc_app)

    url = get_rest_root_url() + 'rest/user'

    tmp_resp = http_post(url, req_param, 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)

    return bc_result
Ejemplo n.º 6
0
def query_merchant_users(bc_app, merchant=None, start_time=None, end_time=None):
    """
    query merchant users
    :param bc_app: beecloud.entity.BCApp
    :param merchant: merchant account, if not passed, only users associated with app will be returned
    :param start_time: if passed, only users registered after it will be returned
    :param end_time: if passed, only users registered before it will be returned
    :return: result contains beecloud.entity.MerchantUser list
    """
    req_param = _TmpObject()
    if merchant:
        req_param.email = merchant

    if start_time:
        req_param.start_time = start_time

    if end_time:
        req_param.end_time = end_time

    attach_app_sign(req_param, BCReqType.QUERY, bc_app)

    url = get_rest_root_url() + 'rest/users?para=' + obj_to_quote_str(req_param)

    tmp_resp = http_get(url, 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:
        user_dict_arr = resp_dict.get('users')
        class_name = BCMerchantUser

        users = []
        if user_dict_arr:
            users = [parse_dict_to_obj(user_dict, class_name) for user_dict in user_dict_arr]

        bc_result.users = users

    return bc_result
Ejemplo n.º 7
0
    def query_subscription_payment_supported_banks(self):
        """
        query subscription payment supported banks
        :return: beecloud.entity.BCResult
        """
        query_param = _TmpObject()
        attach_app_sign(query_param, BCReqType.QUERY, self.bc_app)
        url = get_rest_root_url() + 'subscription_banks'
        tmp_resp = http_get(url, self.bc_app.timeout, params=obj_to_dict(query_param))
        # 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.banks = resp_dict.get('banks')
            bc_result.common_banks = resp_dict.get('common_banks')

        return bc_result
Ejemplo n.º 8
0
 def _query_subscription_url(self):
     return get_rest_root_url() + 'subscription'
Ejemplo n.º 9
0
 def _query_plan_url(self):
     return get_rest_root_url() + 'plan'
Ejemplo n.º 10
0
 def _query_refund_url(self):
     return get_rest_root_url() + 'rest/refund'
Ejemplo n.º 11
0
 def _query_bill_url(self):
     if self.bc_app.is_test_mode:
         return get_rest_root_url() + 'rest/sandbox/bill'
     else:
         return get_rest_root_url() + 'rest/bill'
Ejemplo n.º 12
0
 def _international_pay_url(self):
     return get_rest_root_url() + 'rest/international/bill'
Ejemplo n.º 13
0
 def _bill_refund_url(self):
     return get_rest_root_url() + 'rest/refund'
Ejemplo n.º 14
0
 def _batch_transfer_url(self):
     return get_rest_root_url() + 'rest/transfers'
Ejemplo n.º 15
0
 def _offline_refund_url(self):
     return get_rest_root_url() + 'rest/offline/refund'
Ejemplo n.º 16
0
 def _query_refund_url(self):
     return get_rest_root_url() + 'rest/refund'
Ejemplo n.º 17
0
 def _bill_pay_url(self):
     if self.bc_app.is_test_mode:
         return get_rest_root_url() + 'rest/sandbox/bill'
     else:
         return get_rest_root_url() + 'rest/bill'
Ejemplo n.º 18
0
 def _subscription_url(self):
     return get_rest_root_url() + 'subscription'
Ejemplo n.º 19
0
 def _plan_url(self):
     return get_rest_root_url() + 'plan'
Ejemplo n.º 20
0
 def _offline_pay_url(self):
     return get_rest_root_url() + 'rest/offline/bill'
Ejemplo n.º 21
0
 def _bill_refund_url(self):
     return get_rest_root_url() + 'rest/refund'
Ejemplo n.º 22
0
 def _offline_pay_url(self):
     return get_rest_root_url() + 'rest/offline/bill'
Ejemplo n.º 23
0
 def _bc_transfer_url(self):
     return get_rest_root_url() + 'rest/bc_transfer'
Ejemplo n.º 24
0
 def _international_pay_url(self):
     return get_rest_root_url() + 'rest/international/bill'
Ejemplo n.º 25
0
 def _query_bills_url(self):
     if self.bc_app.is_test_mode:
         return get_rest_root_url() + 'rest/sandbox/bills'
     else:
         return get_rest_root_url() + 'rest/bills'