UNPKG

captain-ui

Version:

有赞vue wap业务组件库

192 lines (158 loc) 6.78 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); exports.__esModule = true; exports.default = void 0; var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")); var _zan_error = require("../../../common/zan_error"); var _cashier = _interopRequireDefault(require("../api/cashier")); /* eslint-disable camelcase */ 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 || _cashier.default.requestPayWithPayWay; this.requestPay = options.requestPay || _cashier.default.requestPay; this.requestCashier = options.requestCashier || _cashier.default.requestCashier; this.requestQrcodePay = options.requestQrcodePay || _cashier.default.requestQrcodePay; this.requestPayStatus = options.requestPayStatus || _cashier.default.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 _zan_error.ZanError('支付进行中')); if (!this._isOrderCreated) return this.fail(new _zan_error.ZanError('收单未生成')); var postData = { acquireNo: this._cashierNo }; // 打包新支付预下单模式请求参数 (0, _extends2.default)(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 _zan_error.AjaxError(resp)); }); }; _proto.getPayStatus = function getPayStatus(callback) { var _this2 = this; if (this._isPayProcessing) return this.fail(new _zan_error.ZanError('支付进行中')); if (!this._isOrderCreated) return this.fail(new _zan_error.ZanError('收单未生成')); var postData = { acquireNo: this._cashierNo }; // 打包新支付预下单模式请求参数 (0, _extends2.default)(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 _zan_error.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 _zan_error.ZanError('无可用支付方式')); } _this3._isOrderCreated = true; if (typeof callback === 'function') callback(data); }).catch(function (resp) { _this3.fail(new _zan_error.AjaxError(resp)); }); }; _proto.doPayAction = function doPayAction(data, callback) { var _this4 = this; if (this._isPayProcessing) return this.fail(new _zan_error.ZanError('支付进行中')); if (!this._isOrderCreated) return this.fail(new _zan_error.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 }; // 打包新支付预下单模式请求参数 (0, _extends2.default)(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 _zan_error.AjaxError({ code: 400101, msg: 'adjust price', data: payData })); } else { _this4._payData = payData; callback(payData); } }).catch(function (resp) { _this4._isPayProcessing = false; _this4.fail(new _zan_error.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 _zan_error.AjaxError(resp)); }); }; _proto.getIsPaying = function getIsPaying() { return this._isPayProcessing; }; return CashierOrderManager; }(); var _default = CashierOrderManager; exports.default = _default;