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

const ServiceAPI = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;
const PAY_URL = 'https://gateway.95516.com/gateway/api/frontTransReq.do';

const Unionpay = {
    pay(user, order, info) {
        return ServiceAPI.get('payment/unionpay_data', {
            order_code: order.order_code,
            payment_code: info.id,
            uid: user.uid,
            front_url: info.protocol + ':' + helpers.urlFormat('/shopping/pay/callback/unionpay')
        }).then(result => {
            if (result && result.code === 200 && result.data) {
                return {
                    code: 200, // reqType是post方式,默认
                    data: Object.assign({reqType: PAY_URL}, result.data)
                };
            }

            return {
                code: 400,
                message: result.message
            };
        });
    },
    notify(data) {
        let orderCode = parseInt(data.orderId, 10);

        // https://open.unionpay.com/ajweb/help/faq/list?id=234&level=0&from=0
        if (!data.respCode || (data.respCode.indexOf('00') < 0 && data.respCode.indexOf('A6') < 0)) {
            return {payResult: -1};
        }

        return {
            bankName: '',
            orderCode: orderCode,
            payResult: 200,
            totalFee: data.txnAmt * 0.01,
            tradeNo: data.queryId,
            bankBillNo: ''
        };
    }
};

module.exports = Unionpay;