# -*- coding: utf-8 -*-

from django.conf import settings
from pywe_pay import WeChatPay


WECHAT = settings.WECHAT


def test_pay(brand_id, openid, amount=100, trade_type='JSAPI', pay_type='PACKET'):
    # 根据 trade_type 获取 wechat 配置
    wxcfg = WECHAT.get('{}:{}'.format(brand_id, trade_type), {})
    # WeChatPay 初始化
    wxpay = WeChatPay(wxcfg.get('appID'), wxcfg.get('apiKey'), wxcfg.get('mchID'), mch_cert=wxcfg.get('mch_cert'), mch_key=wxcfg.get('mch_key'))

    if pay_type == 'TRANSFER':
        ret_data = wxpay.transfer.transfer(openid, amount, u'支付测试，企业付款', check_name='NO_CHECK')
    elif pay_type == 'PACKET':
        wxrpk = wxcfg.get('redpack', {})
        ret_data = wxpay.redpack.send(
            openid,
            amount,
            send_name=wxrpk.get('SEND_NAME'),
            act_name=wxrpk.get('ACT_NAME'),
            wishing=wxrpk.get('WISHING'),
            remark=wxrpk.get('REMARK'),
        )

    print ret_data
