257 lines
9.0 KiB
JavaScript
257 lines
9.0 KiB
JavaScript
supersamApp.controller('OrderPaymentController', [
|
|||
|
|
'$scope',
|
||
|
|
'$http',
|
||
|
|
'$timeout',
|
||
|
|
'$interval',
|
||
|
|
'$filter',
|
||
|
|
'config',
|
||
|
|
function($scope,
|
||
|
|
$http,
|
||
|
|
$timeout,
|
||
|
|
$interval,
|
||
|
|
$filter,
|
||
|
|
config) {
|
||
|
|
var orderPaymentApp;
|
||
|
|
orderPaymentApp = (function() {
|
||
|
|
class orderPaymentApp {
|
||
|
|
constructor() {
|
||
|
|
this.showPaymentInfoModal = this.showPaymentInfoModal.bind(this);
|
||
|
|
this.showPaymentSuccessModal = this.showPaymentSuccessModal.bind(this);
|
||
|
|
this.pageReload = this.pageReload.bind(this);
|
||
|
|
this.pay = this.pay.bind(this);
|
||
|
|
this.payQr = this.payQr.bind(this);
|
||
|
|
this.showElplatPaymentModal = this.showElplatPaymentModal.bind(this);
|
||
|
|
this.startEplatPaymentStatusCheck = this.startEplatPaymentStatusCheck.bind(this);
|
||
|
|
this.openElpatQrCodeUrl = this.openElpatQrCodeUrl.bind(this);
|
||
|
|
$scope.utilities.showContentOnLoad();
|
||
|
|
}
|
||
|
|
|
||
|
|
showPaymentInfoModal() {
|
||
|
|
return $timeout(() => {
|
||
|
|
return angular.element("#paymentInfoModal").modal("show");
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
showPaymentSuccessModal() {
|
||
|
|
var dataToSend;
|
||
|
|
$timeout(() => {
|
||
|
|
return angular.element("#paymentSuccessModal").modal("show");
|
||
|
|
});
|
||
|
|
angular.element("#paymentSuccessModal").on("hidden.bs.modal", () => {
|
||
|
|
return $scope.orderPayment.pageReload();
|
||
|
|
});
|
||
|
|
dataToSend = {
|
||
|
|
encOrderId: config.savedOrderData.encOrderId
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.getPaymentStatusUrl,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 60000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
data = response.data;
|
||
|
|
if (data.status) {
|
||
|
|
return config.savedOrderData.payment = data.payment;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
pageReload() {
|
||
|
|
return window.location.reload();
|
||
|
|
}
|
||
|
|
|
||
|
|
pay() {
|
||
|
|
var dataToSend;
|
||
|
|
if (!this.isSubmitting && !this.isStatusChecking) {
|
||
|
|
this.isSubmitting = true;
|
||
|
|
this.isStatusChecking = true;
|
||
|
|
dataToSend = {
|
||
|
|
encOrderId: config.savedOrderData.encOrderId
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.getPaymentStatusUrl,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 60000
|
||
|
|
}).then((response) => {
|
||
|
|
var data, params, widget;
|
||
|
|
this.isStatusChecking = false;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status) {
|
||
|
|
config.savedOrderData.payment = data.payment;
|
||
|
|
return this.pageReload();
|
||
|
|
} else {
|
||
|
|
params = {
|
||
|
|
publicId: config.paymentPublicId,
|
||
|
|
description: 'Оплата счета ' + config.savedOrderData.data.invoice_no + ', СуперСам',
|
||
|
|
amount: parseFloat(config.savedOrderData.data.summa_order_decimal),
|
||
|
|
currency: 'RUB',
|
||
|
|
invoiceId: config.savedOrderData.data.invoice_no,
|
||
|
|
data: {
|
||
|
|
encOrderId: config.savedOrderData.encOrderId
|
||
|
|
},
|
||
|
|
skin: 'mini',
|
||
|
|
requireEmail: false
|
||
|
|
};
|
||
|
|
if (config.savedOrderData.data.email && config.savedOrderData.data.email.length) {
|
||
|
|
params.accountId = config.savedOrderData.data.email;
|
||
|
|
}
|
||
|
|
this.isSubmitting = true;
|
||
|
|
widget = new cp.CloudPayments();
|
||
|
|
return widget.charge(params, (function(options) {
|
||
|
|
angular.element("#orderPaymentButton").hide();
|
||
|
|
$scope.orderPayment.showPaymentSuccessModal();
|
||
|
|
}), function() {
|
||
|
|
$scope.orderPayment.pageReload();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
return this.isStatusChecking = false;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
payQr() {
|
||
|
|
var dataToSend;
|
||
|
|
if (!this.isSubmitting && !this.isStatusQrChecking) {
|
||
|
|
this.isSubmitting = true;
|
||
|
|
this.isStatusQrChecking = true;
|
||
|
|
dataToSend = {
|
||
|
|
encOrderId: config.savedOrderData.encOrderId
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.getPaymentStatusUrl,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 60000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
this.isStatusQrChecking = false;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status) {
|
||
|
|
config.savedOrderData.payment = data.payment;
|
||
|
|
return this.pageReload();
|
||
|
|
} else {
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.createElplatPaymentQrUrl,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 60000
|
||
|
|
}).then((response) => {
|
||
|
|
this.isSubmitting = false;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status) {
|
||
|
|
this.elplatQRcode = data.qrInfo.qrData;
|
||
|
|
this.elplatQrcId = data.qrInfo.qrcId;
|
||
|
|
this.elplatQrPaymentPurposeL1 = data.paymentPurposeL1;
|
||
|
|
this.elplatQrPaymentPurposeL2 = data.paymentPurposeL2;
|
||
|
|
this.elplatQrPaymentAmount = data.paymentAmount;
|
||
|
|
new QRCode(document.getElementById("elplatQRcode"), {
|
||
|
|
text: this.elplatQRcode,
|
||
|
|
width: 300,
|
||
|
|
height: 300,
|
||
|
|
correctLevel: QRCode.CorrectLevel.M
|
||
|
|
});
|
||
|
|
return this.showElplatPaymentModal();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
return this.isSubmitting = false;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}).catch(() => {
|
||
|
|
return this.isStatusQrChecking = false;
|
||
|
|
});
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
showElplatPaymentModal() {
|
||
|
|
$timeout(() => {
|
||
|
|
return angular.element("#elplat-payment-modal").modal("show");
|
||
|
|
});
|
||
|
|
angular.element("#elplat-payment-modal").on("hidden.bs.modal", () => {
|
||
|
|
return $scope.orderPayment.pageReload();
|
||
|
|
});
|
||
|
|
return this.startEplatPaymentStatusCheck();
|
||
|
|
}
|
||
|
|
|
||
|
|
startEplatPaymentStatusCheck() {
|
||
|
|
if (this.elplatStatusCheckPromise) {
|
||
|
|
$interval.cancel(this.elplatStatusCheckPromise);
|
||
|
|
this.elplatStatusCheckPromise = null;
|
||
|
|
}
|
||
|
|
return this.elplatStatusCheckPromise = $interval(() => {
|
||
|
|
var dataToSend;
|
||
|
|
dataToSend = {
|
||
|
|
qrcId: this.elplatQrcId
|
||
|
|
};
|
||
|
|
return $http({
|
||
|
|
method: 'POST',
|
||
|
|
url: config.getElplatPaymentStatusUrl,
|
||
|
|
data: dataToSend,
|
||
|
|
timeout: 60000
|
||
|
|
}).then((response) => {
|
||
|
|
var data;
|
||
|
|
if (response.data) {
|
||
|
|
data = response.data;
|
||
|
|
if (data.status !== 'pending') {
|
||
|
|
$interval.cancel(this.elplatStatusCheckPromise);
|
||
|
|
this.elplatStatusCheckPromise = null;
|
||
|
|
if (data.status === 'failure') {
|
||
|
|
angular.element(".elplatFailureIcon").addClass('visible');
|
||
|
|
angular.element(".elplatInfo").hide();
|
||
|
|
angular.element(".elplatFailureStatus").show();
|
||
|
|
angular.element('.mobile-pay-button-wrap').hide();
|
||
|
|
}
|
||
|
|
if (data.status === 'success') {
|
||
|
|
angular.element(".elplatOkIcon").addClass('visible');
|
||
|
|
angular.element(".elplatInfo").hide();
|
||
|
|
angular.element(".elplatSuccessStatus").show();
|
||
|
|
return angular.element('.mobile-pay-button-wrap').hide();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}, 5000);
|
||
|
|
}
|
||
|
|
|
||
|
|
openElpatQrCodeUrl() {
|
||
|
|
return window.open(this.elplatQRcode, '_blank');
|
||
|
|
}
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.isSubmitting = false;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.isStatusChecking = false;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.isStatusQrChecking = false;
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.elplatQRcode = "";
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.elplatQrcId = "";
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.elplatQrPaymentPurposeL1 = "";
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.elplatQrPaymentPurposeL2 = "";
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.elplatQrPaymentAmount = "";
|
||
|
|
|
||
|
|
orderPaymentApp.prototype.elplatStatusCheckPromise = null;
|
||
|
|
|
||
|
|
return orderPaymentApp;
|
||
|
|
|
||
|
|
}).call(this);
|
||
|
|
$scope.config = config;
|
||
|
|
$scope.utilities = new UtilitiesClass(config,
|
||
|
|
$filter,
|
||
|
|
$timeout);
|
||
|
|
return $scope.orderPayment = new orderPaymentApp();
|
||
|
|
}
|
||
|
|
]);
|