コード例 #1
0
    def test_batch_transfer(self, mock_post):
        # err case
        self._inner_test_http_err_case(mock_post, BCBatchTransferParams(),
                                       self.bc_pay.batch_transfer)

        # if test mode
        self.bc_app.is_test_mode = True
        self.bc_app.test_secret = 'your_test_sec'
        result = self.bc_pay.batch_transfer(BCBatchTransferParams())
        assert result.result_code == NOT_SUPPORTED_CODE
        # print(result.err_detail)

        # succ case
        self.bc_app.is_test_mode = None  # or False

        resp_dict = {
            'result_msg': 'OK',
            'url': 'https://mapi.alipay.com/more',
            'err_detail': '',
            'result_code': 0
        }
        mock_post.return_value = URL_REQ_SUCC, resp_dict

        transfer_params = BCBatchTransferParams()
        # not really required for unit test as http request is mocked
        transfer_params.channel = BCChannelType.ALI
        transfer_params.batch_no = order_num_on_datetime()
        transfer_params.account_name = u'苏州比可网络科技有限公司'
        item1 = BCBatchTransferItem()
        item1.transfer_id = order_num_on_datetime() + 'a'
        item1.receiver_account = '1234567'
        item1.receiver_name = u'某人1'
        item1.transfer_fee = 1
        item1.transfer_note = u'python支付宝批量打款item1'

        item2 = BCBatchTransferItem()
        item2.transfer_id = order_num_on_datetime() + 'b'
        item2.receiver_account = '[email protected]'
        item2.receiver_name = 'account2'
        item2.transfer_fee = 1
        item2.transfer_note = u'python支付宝批量打款item2'

        transfer_params.transfer_data = [item1, item2]

        result = self.bc_pay.batch_transfer(transfer_params)
        assert result.result_code == 0
        assert result.result_msg == 'OK'
        assert result.err_detail == ''
        assert result.url == 'https://mapi.alipay.com/more'
コード例 #2
0
def _deal_with_normal_pay(channel, open_id, bank=None):
    # wx js api 需要先获取支付人的open id
    req_params = BCPayReqParams()

    # 当channel为BC_GATEWAY时,bank必填
    if channel == 'BC_GATEWAY':
        req_params.bank = bank

    req_params.channel = channel
    req_params.title = u'python {:s} 支付测试'.format(channel)
    req_params.total_fee = 2
    req_params.bill_no = order_num_on_datetime()
    req_params.optional = {'lang': 'python', u'中文key': u'中文value'}
    # 支付完成后的跳转页面
    req_params.return_url = 'https://beecloud.cn/'
    # 支付宝网页支付(ALI_WEB)的选填参数,可以为商品详细页的url
    # req_params.show_url = 'https://beecloud.cn/'
    # 支付宝内嵌二维码支付(ALI_QRCODE)的必填参数
    if req_params.channel == BCChannelType.ALI_QRCODE:
        req_params.qr_pay_mode = '0'
    if req_params.channel == BCChannelType.WX_JSAPI and open_id:
        req_params.openid = open_id
    resp = bc_pay.pay(req_params)

    if resp.result_code:
        return resp.result_msg + ' # ' + resp.err_detail

    print("beecloud bill object id: " + resp.id)

    if hasattr(resp, 'url') and resp.url:
        print(resp.url)
        return redirect(resp.url)
    elif hasattr(resp, 'html') and resp.html:
        print(resp.html)
        return render_template('blank.html', content=Markup(resp.html))
    elif hasattr(resp, 'code_url') and resp.code_url:
        print(resp.code_url)
        return render_template('qrcode.html', raw_content=resp.code_url)
    elif req_params.channel == BCChannelType.WX_JSAPI:
        jsapi = {}
        jsapi['timeStamp'] = resp.timestamp
        jsapi['appId'] = resp.app_id
        jsapi['nonceStr'] = resp.nonce_str
        jsapi['package'] = resp.package
        jsapi['signType'] = resp.sign_type
        jsapi['paySign'] = resp.pay_sign
        # print(json.dumps(jsapi))
        return render_template('jsapi.html', jsapi=json.dumps(jsapi))
    else:
        return "invalid request"
コード例 #3
0
ファイル: demo.py プロジェクト: wwwcs59/beecloud-python
def app_refund():
    refund_params = BCRefundReqParams()
    # 退款channel为选填参数
    refund_params.channel = request.args.get('channel', '')
    refund_params.refund_no = order_num_on_datetime()
    refund_params.bill_no = request.args.get('bill_no', '')
    refund_params.refund_fee = int(request.args.get('refund_fee', ''))
    if request.args.get('need_approval', ''):
        # 表示预退款,需要后期调用 预退款批量审核 API
        refund_params.need_approval = True
    result = bc_pay.refund(refund_params)
    if not result.result_code:
        # 支付宝退款地址,需用户在支付宝平台上手动输入支付密码处理
        if not refund_params.need_approval and refund_params.channel == BCChannelType.ALI:
            return redirect(result.url)
    return str(result.result_code) + ' # ' + result.result_msg + ' # ' + result.err_detail
コード例 #4
0
def app_refund():
    refund_params = BCRefundReqParams()
    # 退款channel为选填参数
    refund_params.channel = request.args.get('channel', '')
    refund_params.refund_no = order_num_on_datetime()
    refund_params.bill_no = request.args.get('bill_no', '')
    refund_params.refund_fee = int(request.args.get('refund_fee', ''))
    if request.args.get('need_approval', ''):
        # 表示预退款,需要后期调用 预退款批量审核 API
        refund_params.need_approval = True
    result = bc_pay.refund(refund_params)
    if not result.result_code:
        # 支付宝退款地址,需用户在支付宝平台上手动输入支付密码处理
        if not refund_params.need_approval and refund_params.channel == BCChannelType.ALI:
            return redirect(result.url)
    return str(result.result_code) + ' # ' + result.result_msg + ' # ' + result.err_detail
コード例 #5
0
    def test_bc_transfer(self, mock_post):
        # err case
        self._inner_test_http_err_case(mock_post, BCCardTransferParams(),
                                       self.bc_pay.bc_transfer)

        # if test mode
        self.bc_app.is_test_mode = True
        self.bc_app.test_secret = 'your_test_sec'
        result = self.bc_pay.bc_transfer(BCCardTransferParams())
        assert result.result_code == NOT_SUPPORTED_CODE
        # print(result.err_detail)

        # succ case
        self.bc_app.is_test_mode = None  # or False

        resp_dict = {'result_msg': 'OK', 'err_detail': '', 'result_code': 0}
        mock_post.return_value = URL_REQ_SUCC, resp_dict

        transfer_params = BCCardTransferParams()
        transfer_params.total_fee = 1
        transfer_params.bill_no = order_num_on_datetime()
        # 最长支持16个汉字
        transfer_params.title = u'python比可代付测试'
        # 银行缩写编码
        transfer_params.bank_code = 'BOC'
        # 银行联行行号
        transfer_params.bank_associated_code = '12345678'
        # 银行全名
        transfer_params.bank_fullname = u'中国银行'
        # DE代表借记卡,CR代表信用卡
        transfer_params.card_type = 'DE'
        # 帐户类型,P代表私户,C代表公户
        transfer_params.account_type = 'C'
        # 收款方的银行卡号
        transfer_params.account_no = '5300000'
        # 收款方的姓名或者单位名
        transfer_params.account_name = u'苏州比可网络科技有限公司'
        # 银行绑定的手机号,当需要手机收到银行入账信息时,该值必填,前提是该手机在银行有短信通知业务,否则收不到银行信息
        transfer_params.mobile = '1850000'
        result = self.bc_pay.bc_transfer(transfer_params)
        assert result.result_code == 0
        assert result.result_msg == 'OK'
        assert result.err_detail == ''
コード例 #6
0
ファイル: demo.py プロジェクト: wwwcs59/beecloud-python
def _deal_with_international_pay(channel):
    req_params = BCInternationalPayParams()
    req_params.channel = channel
    req_params.title = u'python {:s} 支付测试'.format(channel)
    req_params.total_fee = 1
    req_params.currency = 'USD'
    req_params.bill_no = order_num_on_datetime()
    # 支付完成后的跳转页面
    req_params.return_url = 'https://beecloud.cn/'

    resp = bc_pay.international_pay(req_params)

    if resp.result_code:
        return resp.result_msg + ' # ' + resp.err_detail

    if resp.id:
        print("beecloud bill object id: " + resp.id)

    if hasattr(resp, 'url') and resp.url:
        return redirect(resp.url)
コード例 #7
0
def _deal_with_international_pay(channel):
    req_params = BCInternationalPayParams()
    req_params.channel = channel
    req_params.title = u'python {:s} 支付测试'.format(channel)
    req_params.total_fee = 1
    req_params.currency = 'USD'
    req_params.bill_no = order_num_on_datetime()
    # 支付完成后的跳转页面
    req_params.return_url = 'https://beecloud.cn/'

    resp = bc_pay.international_pay(req_params)

    if resp.result_code:
        return resp.result_msg + ' # ' + resp.err_detail

    if resp.id:
        print("beecloud bill object id: " + resp.id)

    if hasattr(resp, 'url') and resp.url:
        return redirect(resp.url)
コード例 #8
0
    def test_international_pay(self, mock_post):
        # err case
        self._inner_test_http_err_case(mock_post, BCInternationalPayParams(),
                                       self.bc_pay.international_pay)

        # if test mode
        self.bc_app.is_test_mode = True
        self.bc_app.test_secret = 'your_test_sec'
        result = self.bc_pay.international_pay(BCInternationalPayParams())
        assert result.result_code == NOT_SUPPORTED_CODE
        # print(result.err_detail)

        # succ case
        self.bc_app.is_test_mode = None  # or False

        resp_dict = {
            'err_detail': '',
            'url': 'https://www.paypal.com/more',
            'result_msg': 'OK',
            'result_code': 0
        }
        mock_post.return_value = URL_REQ_SUCC, resp_dict

        req_params = BCInternationalPayParams()
        # not really required for unit test as http request is mocked
        req_params.channel = BCChannelType.PAYPAL_PAYPAL
        req_params.title = u'python PayPal 支付测试'
        req_params.total_fee = 1  # cent
        req_params.currency = 'USD'
        req_params.bill_no = order_num_on_datetime()
        # 支付完成后的跳转页面
        req_params.return_url = 'https://beecloud.cn/'

        result = self.bc_pay.international_pay(req_params)

        assert result.result_code == 0
        assert result.result_msg == 'OK'
        assert result.err_detail == ''
        assert result.url == 'https://www.paypal.com/more'
コード例 #9
0
    def test_transfer(self, mock_post):
        # err case
        self._inner_test_http_err_case(mock_post, BCTransferReqParams(),
                                       self.bc_pay.transfer)

        # if test mode
        self.bc_app.is_test_mode = True
        self.bc_app.test_secret = 'your_test_sec'
        result = self.bc_pay.transfer(BCTransferReqParams())
        assert result.result_code == NOT_SUPPORTED_CODE
        # print(result.err_detail)

        # succ case
        self.bc_app.is_test_mode = None  # or False

        resp_dict = {'result_msg': 'OK', 'err_detail': '', 'result_code': 0}
        mock_post.return_value = URL_REQ_SUCC, resp_dict

        transfer_params = BCTransferReqParams()
        # not really required for unit test as http request is mocked
        transfer_params.channel = BCChannelType.WX_REDPACK
        # 10 digits for WX
        transfer_params.transfer_no = order_num_on_datetime()[0:10]
        transfer_params.desc = 'desc'
        # range for WX 1-200 RMB
        transfer_params.total_fee = 100  # cent
        transfer_params.channel_user_id = 'wx_open_id'
        redpack = BCTransferRedPack()
        redpack.send_name = 'BeeCloud'
        redpack.wishing = u'BeeCloud祝福开发者工作顺利'
        redpack.act_name = u'BeeCloud开发者测试中'
        transfer_params.redpack_info = redpack
        result = self.bc_pay.transfer(transfer_params)
        assert result.result_code == 0
        assert result.result_msg == 'OK'
        assert result.err_detail == ''
コード例 #10
0
ファイル: demo.py プロジェクト: wwwcs59/beecloud-python
def app_transfer():
    channel = request.form['channel']
    # 批量打款
    if channel == 'ALI':
        transfer_params = BCBatchTransferParams()
        transfer_params.batch_no = order_num_on_datetime()
        transfer_params.account_name = u'苏州比可网络科技有限公司'
        item1 = BCBatchTransferItem()
        item1.transfer_id = order_num_on_datetime() + 'a'
        item1.receiver_account = '1234567'
        item1.receiver_name = u'某人1'
        item1.transfer_fee = 1
        item1.transfer_note = u'python支付宝批量打款item1'

        item2 = BCBatchTransferItem()
        item2.transfer_id = order_num_on_datetime() + 'b'
        item2.receiver_account = '[email protected]'
        item2.receiver_name = 'account2'
        item2.transfer_fee = 1
        item2.transfer_note = u'python支付宝批量打款item2'

        transfer_params.transfer_data = [item1, item2]

        result = bc_pay.batch_transfer(transfer_params)
    elif channel == 'BC_TRANSFER':  # 比可代付
        transfer_params = BCCardTransferParams()
        # 单位为分
        transfer_params.total_fee = 1
        transfer_params.bill_no = order_num_on_datetime()
        # 最长支持16个汉字
        transfer_params.title = u'python比可代付测试'
        # 银行缩写编码
        transfer_params.bank_code = 'BOC'
        # 银行联行行号
        transfer_params.bank_associated_code = '1043050000'
        # 银行全名
        transfer_params.bank_fullname = u'中国银行'
        # DE代表借记卡,CR代表信用卡
        transfer_params.card_type = 'DE'
        # 帐户类型,P代表私户,C代表公户
        transfer_params.account_type = 'C'
        # 收款方的银行卡号
        transfer_params.account_no = '5300000'
        # 收款方的姓名或者单位名
        transfer_params.account_name = u'苏州比可网络科技有限公司'
        # 银行绑定的手机号,当需要手机收到银行入账信息时,该值必填,前提是该手机在银行有短信通知业务,否则收不到银行信息
        transfer_params.mobile = '1850000'
        # 附加数据,选填
        transfer_params.optional = {'key1': u'选填的value'}

        result = bc_pay.bc_transfer(transfer_params)

    else:   # 单笔打款
        transfer_params = BCTransferReqParams()
        transfer_params.channel = channel
        transfer_params.desc = u'python {:s} 打款测试'.format(channel)
        if transfer_params.channel == BCChannelType.WX_REDPACK:
            # 微信为10位数字
            transfer_params.transfer_no = order_num_on_datetime()[0:10]
            # 微信红包1.00-200元
            transfer_params.total_fee = 100
            transfer_params.channel_user_id = 'o3kKrjlUsMnv__cK5DYZMl0JoAkY'
            redpack = BCTransferRedPack()
            redpack.send_name = 'BeeCloud'
            redpack.wishing = u'BeeCloud祝福开发者工作顺利'
            redpack.act_name = u'BeeCloud开发者测试中'
            transfer_params.redpack_info = redpack
        elif transfer_params.channel == BCChannelType.WX_TRANSFER:
            # 微信为10位数字
            transfer_params.transfer_no = order_num_on_datetime()[0:10]
            # 微信红包1.00-200元
            transfer_params.total_fee = 100
            transfer_params.channel_user_id = 'o3kKrjlUsMnv__cK5DYZMl0JoAkY'
        else:
            transfer_params.transfer_no = order_num_on_datetime()
            transfer_params.total_fee = 1
            transfer_params.channel_user_id = '*****@*****.**'
            transfer_params.channel_user_name = 'py'
            transfer_params.account_name = u'苏州比可网络科技有限公司'

        result = bc_pay.transfer(transfer_params)

    if hasattr(result, 'url') and result.url:
        # 支付宝需要跳转到如下支付宝链接输入支付密码确认
        return redirect(result.url)

    return str(result.result_code) + ' # ' + result.result_msg + ' # ' + result.err_detail
コード例 #11
0
def app_transfer():
    channel = request.form['channel']
    # 批量打款
    if channel == 'ALI':
        transfer_params = BCBatchTransferParams()
        transfer_params.batch_no = order_num_on_datetime()
        transfer_params.account_name = u'苏州比可网络科技有限公司'
        item1 = BCBatchTransferItem()
        item1.transfer_id = order_num_on_datetime() + 'a'
        item1.receiver_account = '1234567'
        item1.receiver_name = u'某人1'
        item1.transfer_fee = 1
        item1.transfer_note = u'python支付宝批量打款item1'

        item2 = BCBatchTransferItem()
        item2.transfer_id = order_num_on_datetime() + 'b'
        item2.receiver_account = '[email protected]'
        item2.receiver_name = 'account2'
        item2.transfer_fee = 1
        item2.transfer_note = u'python支付宝批量打款item2'

        transfer_params.transfer_data = [item1, item2]

        result = bc_pay.batch_transfer(transfer_params)
    elif channel == 'BC_TRANSFER':  # 比可企业打款
        transfer_params = BCCardTransferParams()
        # 单位为分
        transfer_params.total_fee = 1
        transfer_params.bill_no = order_num_on_datetime()
        # 最长支持16个汉字
        transfer_params.title = u'python比可企业打款测试'
        # 银行全名
        transfer_params.bank_fullname = u'中国银行'
        # DE代表借记卡,CR代表信用卡
        transfer_params.card_type = 'DE'
        # 帐户类型,P代表私户,C代表公户
        transfer_params.account_type = 'C'
        # 收款方的银行卡号
        transfer_params.account_no = '5300000'
        # 收款方的姓名或者单位名
        transfer_params.account_name = u'苏州比可网络科技有限公司'
        # 银行绑定的手机号,当需要手机收到银行入账信息时,该值必填,前提是该手机在银行有短信通知业务,否则收不到银行信息
        transfer_params.mobile = '1850000'
        # 附加数据,选填
        transfer_params.optional = {'key1': u'选填的value'}

        result = bc_pay.bc_transfer(transfer_params)

    else:   # 单笔打款
        transfer_params = BCTransferReqParams()
        transfer_params.channel = channel
        transfer_params.desc = u'python {:s} 打款测试'.format(channel)
        if transfer_params.channel == BCChannelType.WX_REDPACK:
            # 微信为10位数字
            transfer_params.transfer_no = order_num_on_datetime()[0:10]
            # 微信红包1.00-200元
            transfer_params.total_fee = 100
            transfer_params.channel_user_id = 'o3kKrjlUsMnv__cK5DYZMl0JoAkY'
            redpack = BCTransferRedPack()
            redpack.send_name = 'BeeCloud'
            redpack.wishing = u'BeeCloud祝福开发者工作顺利'
            redpack.act_name = u'BeeCloud开发者测试中'
            transfer_params.redpack_info = redpack
        elif transfer_params.channel == BCChannelType.WX_TRANSFER:
            # 微信为10位数字
            transfer_params.transfer_no = order_num_on_datetime()[0:10]
            # 微信红包1.00-200元
            transfer_params.total_fee = 100
            transfer_params.channel_user_id = 'o3kKrjlUsMnv__cK5DYZMl0JoAkY'
        else:       # ALI_TRANSFER 支付宝单笔打款
            transfer_params.transfer_no = order_num_on_datetime()
            transfer_params.total_fee = 1
            transfer_params.channel_user_id = '*****@*****.**'
            transfer_params.channel_user_name = 'py'
            transfer_params.account_name = u'苏州比可网络科技有限公司'

        result = bc_pay.transfer(transfer_params)

    if not result.result_code:
        print("beecloud transfer object id: " + result.id)
    
    if hasattr(result, 'url') and result.url:
        # 支付宝需要跳转到如下支付宝链接输入支付密码确认
        return redirect(result.url)

    return str(result.result_code) + ' # ' + result.result_msg + ' # ' + result.err_detail