wechat.js 1.06 KB
/**
 * @author: xiaoxiao.hao<xiaoxiao.hao@yoho.cn>
 * @date: 2017/3/23
 */
'use strict';

const helpers = global.yoho.helpers;

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    pay(user, order, info) {
        let options = {
            order_code: order.order_code,
            payment_code: info.id,
            app_key: 'yohopc'
        };

        return this.get({
            api: global.yoho.ServiceAPI,
            url: 'payment/weixin_data',
            data: options
        }).then(result => {
            if (result && result.code === 200 && result.data) {
                let url = `/shopping/newpay/weixin?url=${result.data.codeUrl}&code=${order.order_code}`;

                return {
                    code: 200,
                    data: {
                        href: helpers.urlFormat(url)
                    }
                };
            } else {
                return {
                    code: 400,
                    message: result.message
                };
            }
        });
    }
};