コード例 #1
0
def rest_delete_object(bc_app, url, obj_id, **kwargs):
    """
    :param bc_app: used to attach app sign
    :param url: used to post request
    :param obj_id: object id
    :param kwargs: optional key/value pairs arguments
    :return: beecloud.entity.BCResult
    """
    tmp_obj = _TmpObject()
    if kwargs:
        for k, v in kwargs.items():
            if v:
                setattr(tmp_obj, k, v)

    attach_app_sign(tmp_obj, BCReqType.PAY, bc_app)
    req_url = url + '/' + obj_id + '?' + compatible_urlencode(tmp_obj)
    tmp_resp = http_del(req_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:
        bc_result.id = resp_dict.get("id")

    return bc_result
コード例 #2
0
ファイル: pay.py プロジェクト: zhoudaqing/beecloud-python
    def _bill_transfer(self, url, transfer_params):
        attach_app_sign(transfer_params, BCReqType.TRANSFER, self.bc_app)
        req_dict = {}
        for k, v in transfer_params.__dict__.items():
            if v:
                if k == 'redpack_info':  # WX_REDPACK
                    req_dict[k] = obj_to_dict(v)
                elif k == 'transfer_data':  # batch_transfer
                    req_dict[k] = [
                        obj_to_dict(item)
                        for item in transfer_params.transfer_data
                    ]
                else:
                    req_dict[k] = v

        tmp_resp = http_post(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')
            # for ali
            bc_result.url = resp_dict.get('url')

        return bc_result
コード例 #3
0
ファイル: pay.py プロジェクト: RamboWu/beecloud-python
    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
コード例 #4
0
ファイル: pay.py プロジェクト: RamboWu/beecloud-python
    def _bill_transfer(self, url, transfer_params):
        attach_app_sign(transfer_params, BCReqType.TRANSFER, self.bc_app)
        req_dict = {}
        for k, v in transfer_params.__dict__.items():
            if v:
                if k == 'redpack_info':     # WX_REDPACK
                    req_dict[k] = obj_to_dict(v)
                elif k == 'transfer_data':      # batch_transfer
                    req_dict[k] = [obj_to_dict(item) for item in transfer_params.transfer_data]
                else:
                    req_dict[k] = v

        tmp_resp = http_post(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')
            # for ali
            bc_result.url = resp_dict.get('url')

        return bc_result
コード例 #5
0
ファイル: pay.py プロジェクト: zhoudaqing/beecloud-python
    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
コード例 #6
0
ファイル: pay.py プロジェクト: zhoudaqing/beecloud-python
    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
コード例 #7
0
ファイル: pay.py プロジェクト: beecloud/beecloud-python
    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
コード例 #8
0
ファイル: utils.py プロジェクト: beecloud/beecloud-python
def rest_delete_object(bc_app, url, obj_id, **kwargs):
    """
    :param bc_app: used to attach app sign
    :param url: used to post request
    :param obj_id: object id
    :param kwargs: optional key/value pairs arguments
    :return: beecloud.entity.BCResult
    """
    tmp_obj = _TmpObject()
    if kwargs:
        for k, v in kwargs.items():
            if v:
                setattr(tmp_obj, k, v)

    attach_app_sign(tmp_obj, BCReqType.PAY, bc_app)
    req_url = url + '/' + obj_id + '?' + compatible_urlencode(tmp_obj)
    tmp_resp = http_del(req_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:
        bc_result.id = resp_dict.get("id")

    return bc_result
コード例 #9
0
ファイル: pay.py プロジェクト: zhoudaqing/beecloud-python
    def pay(self, pay_params):
        """
        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 #2
        :param pay_params: beecloud.entity.BCPayReqParams
        :return: beecloud.entity.BCResult
        """
        self._add_sdk_version(pay_params)

        attach_app_sign(pay_params, BCReqType.PAY, self.bc_app)
        tmp_resp = http_post(self._bill_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')
            # most channel will return url or html
            if resp_dict.get('html'):
                bc_result.html = resp_dict.get('html')
            if resp_dict.get('url'):
                bc_result.url = resp_dict.get('url')
            # WX_NATIVE or BC_NATIVE or BC_ALI_QRCODE
            if resp_dict.get('code_url'):
                bc_result.code_url = resp_dict.get('code_url')
            # WX_JSAPI
            if pay_params.channel == BCChannelType.WX_JSAPI:
                bc_result.app_id = resp_dict.get('app_id')
                bc_result.package = resp_dict.get('package')
                bc_result.nonce_str = resp_dict.get('nonce_str')
                bc_result.timestamp = resp_dict.get('timestamp')
                bc_result.pay_sign = resp_dict.get('pay_sign')
                bc_result.sign_type = resp_dict.get('sign_type')

        return bc_result
コード例 #10
0
ファイル: pay.py プロジェクト: beecloud/beecloud-python
    def pay(self, pay_params):
        """
        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 #2
        :param pay_params: beecloud.entity.BCPayReqParams
        :return: beecloud.entity.BCResult
        """
        self._add_sdk_version(pay_params)

        attach_app_sign(pay_params, BCReqType.PAY, self.bc_app)
        tmp_resp = http_post(self._bill_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')
            # most channel will return url or html
            if resp_dict.get('html'):
                bc_result.html = resp_dict.get('html')
            if resp_dict.get('url'):
                bc_result.url = resp_dict.get('url')
            # WX_NATIVE or BC_NATIVE or BC_ALI_QRCODE
            if resp_dict.get('code_url'):
                bc_result.code_url = resp_dict.get('code_url')
            # WX_JSAPI
            if pay_params.channel == BCChannelType.WX_JSAPI:
                bc_result.app_id = resp_dict.get('app_id')
                bc_result.package = resp_dict.get('package')
                bc_result.nonce_str = resp_dict.get('nonce_str')
                bc_result.timestamp = resp_dict.get('timestamp')
                bc_result.pay_sign = resp_dict.get('pay_sign')
                bc_result.sign_type = resp_dict.get('sign_type')

        return bc_result
コード例 #11
0
ファイル: pay.py プロジェクト: zhoudaqing/beecloud-python
    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
コード例 #12
0
ファイル: pay.py プロジェクト: RamboWu/beecloud-python
    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
コード例 #13
0
ファイル: pay.py プロジェクト: zhoudaqing/beecloud-python
    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
コード例 #14
0
ファイル: pay.py プロジェクト: beecloud/beecloud-python
    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