108 lines
2.4 KiB
JavaScript
108 lines
2.4 KiB
JavaScript
|
|
module.exports = new Class({
|
|
Extends: Vn.Object
|
|
|
|
,tpvOrder: null
|
|
,tpvStatus: null
|
|
|
|
,check: function(callback) {
|
|
this.tpvOrder = this.hash.$.tpvOrder;
|
|
this.tpvStatus = this.hash.$.tpvStatus;
|
|
|
|
if (this.tpvStatus) {
|
|
const params = {
|
|
transaction: this.tpvOrder,
|
|
status: this.tpvStatus
|
|
};
|
|
const query = 'CALL myTpvTransaction_end(#transaction, #status)';
|
|
this.conn.execQuery(query, null, params);
|
|
}
|
|
|
|
if (callback)
|
|
callback(this, this.tpvOrder, this.tpvStatus);
|
|
}
|
|
|
|
,pay: function(amount, company) {
|
|
this._realPay(amount * 100, company);
|
|
}
|
|
|
|
,_realPay: function(amount, company) {
|
|
if (isNumeric(amount) && amount > 0) {
|
|
const params = {
|
|
amount: parseInt(amount)
|
|
,urlOk: this._makeUrl('ok')
|
|
,urlKo: this._makeUrl('ko')
|
|
,company: company
|
|
};
|
|
|
|
this.conn.send('tpv/transaction', params,
|
|
this._onTransactionStart.bind(this));
|
|
} else
|
|
Htk.Toast.showError(_('AmountError'));
|
|
}
|
|
|
|
,_onTransactionStart: function(json) {
|
|
if (json) {
|
|
const postValues = json.postValues;
|
|
|
|
const form = document.createElement('form');
|
|
form.method = 'POST';
|
|
form.action = json.url;
|
|
document.body.appendChild(form);
|
|
|
|
for (var field in postValues) {
|
|
const input = document.createElement('input');
|
|
input.type = 'hidden';
|
|
input.name = field;
|
|
form.appendChild(input);
|
|
|
|
if (postValues[field])
|
|
input.value = postValues[field];
|
|
}
|
|
|
|
form.submit();
|
|
} else
|
|
Htk.Toast.showWarning(_('PayError'));
|
|
}
|
|
|
|
,retryPay: function() {
|
|
const params = {transaction: parseInt(this.tpvOrder)};
|
|
|
|
const query = 'SELECT t.amount, m.companyFk '
|
|
+'FROM myTpvTransaction t '
|
|
+'JOIN tpvMerchant m ON m.id = t.merchantFk '
|
|
+'WHERE t.id = #transaction';
|
|
this.conn.execQuery(query,
|
|
this._onRetryPayDone.bind(this), params);
|
|
}
|
|
|
|
,_onRetryPayDone: function(resultSet) {
|
|
const res = resultSet.fetchObject();
|
|
|
|
if (res)
|
|
this._realPay(res.amount, res.companyFk);
|
|
else
|
|
Htk.Toast.showError(_('AmountError'));
|
|
}
|
|
|
|
,_makeUrl: function(status) {
|
|
let path = location.protocol +'//'+ location.hostname;
|
|
path += location.port ? ':'+ location.port : '';
|
|
path += location.pathname;
|
|
path += location.search ? location.search : '';
|
|
path += this.hash.make({
|
|
form: 'ecomerce/orders',
|
|
tpvStatus: status,
|
|
tpvOrder: '_transactionId_'
|
|
}, true);
|
|
|
|
alert(path);
|
|
|
|
return path;
|
|
}
|
|
});
|
|
|
|
function isNumeric(n) {
|
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
}
|