captain-ui
Version:
有赞vue wap业务组件库
186 lines (153 loc) • 6.31 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
/* eslint-disable camelcase */
import { AjaxError, ZanError } from '../../../common/zan_error';
import api from '../api/cashier';
var CashierOrderManager =
/*#__PURE__*/
function () {
function CashierOrderManager(options) {
this.account = options.account || '';
this.cashierRequestUrl = options.cashierRequestUrl;
this.payRequestUrl = options.payRequestUrl;
this.qrcodeRequestUrl = options.qrcodeRequestUrl;
this.payStatusUrl = options.payStatusUrl; // api function
this.requestPayWithPayWay = options.requestPayWithPayWay || api.requestPayWithPayWay;
this.requestPay = options.requestPay || api.requestPay;
this.requestCashier = options.requestCashier || api.requestCashier;
this.requestQrcodePay = options.requestQrcodePay || api.requestQrcodePay;
this.requestPayStatus = options.requestPayStatus || api.requestPayStatus; // this.extraData = options.extraData;
this.fail = options.fail;
this._isOrderCreated = false;
this._isPayProcessing = false;
this._cashierNo = '';
this._payWays = {};
this._payReturnedData = {};
this._cashierData = {};
this._payData = {};
}
var _proto = CashierOrderManager.prototype;
_proto.getCashierNo = function getCashierNo() {
if (!this.isOrderCreated) console.warn('收单未生成');
return this._cashierNo;
};
_proto.getPayWays = function getPayWays() {
if (!this.isOrderCreated) console.warn('收单未生成');
return this._payWays;
};
_proto.getPayReturnedData = function getPayReturnedData() {
if (!this.isPayProcessed) console.warn('收单未生成');
return this._payReturnedData;
};
_proto.isOrderCreated = function isOrderCreated() {
return this._isOrderCreated;
};
_proto.getQrcodePay = function getQrcodePay(callback) {
var _this = this;
if (this._isPayProcessing) return this.fail(new ZanError('支付进行中'));
if (!this._isOrderCreated) return this.fail(new ZanError('收单未生成'));
var postData = {
acquireNo: this._cashierNo
}; // 打包新支付预下单模式请求参数
_extends(postData, {
prepay_id: this._cashierData.prepay_id,
cashier_salt: this._cashierData.cashier_salt,
cashier_sign: this._cashierData.cashier_sign,
partner_id: this._cashierData.partner_id
});
this.requestQrcodePay(this.qrcodeRequestUrl, postData).then(function (qrcodeUrl) {
callback(qrcodeUrl);
}).catch(function (resp) {
_this.fail(new AjaxError(resp));
});
};
_proto.getPayStatus = function getPayStatus(callback) {
var _this2 = this;
if (this._isPayProcessing) return this.fail(new ZanError('支付进行中'));
if (!this._isOrderCreated) return this.fail(new ZanError('收单未生成'));
var postData = {
acquireNo: this._cashierNo
}; // 打包新支付预下单模式请求参数
_extends(postData, {
prepay_id: this._cashierData.prepay_id,
cashier_salt: this._cashierData.cashier_salt,
cashier_sign: this._cashierData.cashier_sign,
partner_id: this._cashierData.partner_id
});
this.requestPayStatus(this.payStatusUrl, postData).then(function (payStatus) {
callback(payStatus);
}).catch(function (resp) {
_this2.fail(new AjaxError(resp));
});
};
_proto.createCashierOrder = function createCashierOrder(cashierData, callback) {
var _this3 = this;
if (this._isOrderCreated) return console.warn('收单已生成'); // 存储交易数据。
this._cashierData = cashierData;
this.requestCashier(this.cashierRequestUrl, cashierData).then(function (data) {
_this3._cashierNo = data.unifiedAquireOrder;
_this3._payWays = data.payChannels || data.pay_channels;
if (!_this3._payWays) {
return _this3.fail(new ZanError('无可用支付方式'));
}
_this3._isOrderCreated = true;
if (typeof callback === 'function') callback(data);
}).catch(function (resp) {
_this3.fail(new AjaxError(resp));
});
};
_proto.doPayAction = function doPayAction(data, callback) {
var _this4 = this;
if (this._isPayProcessing) return this.fail(new ZanError('支付进行中'));
if (!this._isOrderCreated) return this.fail(new ZanError('收单未生成'));
this._isPayProcessing = true;
var postData = {
payDataJson: this._cashierData,
payTool: data.payWay.pay_channel,
acquireNo: this._cashierNo,
password: data.password || '',
accept_price: data.accept_price || 0,
new_price: typeof data.new_price !== 'undefined' && data.new_price !== null && data.new_price !== '' ? data.new_price : -1,
value_card_no: data.payWay.value_card_no
}; // 打包新支付预下单模式请求参数
_extends(postData, {
prepay_id: this._cashierData.prepay_id,
cashier_salt: this._cashierData.cashier_salt,
cashier_sign: this._cashierData.cashier_sign,
pay_token: data.password,
partner_id: this._cashierData.partner_id,
pay_tool: data.payWay.pay_channel,
node_extra: data.nodeExtra,
out_biz_ctx: data.outBizCtx
});
this.requestPay(this.payRequestUrl, postData).then(function (payData) {
_this4._isPayProcessing = false; // 如果是改价,需要用户同意的话,就先弹出弹窗
if (payData.adjust_price) {
// 改价弹框由业务处理
_this4.fail(new AjaxError({
code: 400101,
msg: 'adjust price',
data: payData
}));
} else {
_this4._payData = payData;
callback(payData);
}
}).catch(function (resp) {
_this4._isPayProcessing = false;
_this4.fail(new AjaxError(resp));
});
};
_proto.doPayWithPayWay = function doPayWithPayWay(cashierData, payWayData, callback) {
var _this5 = this;
this.requestPayWithPayWay(this.payRequestUrl, cashierData, payWayData, this.fail).then(function (data) {
if (typeof callback === 'function') callback(data);
}).catch(function (resp) {
_this5.fail(new AjaxError(resp));
});
};
_proto.getIsPaying = function getIsPaying() {
return this._isPayProcessing;
};
return CashierOrderManager;
}();
export default CashierOrderManager;