2015-09-11 09:37:16 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
module.exports = new Class({
|
2016-01-15 12:31:08 +00:00
|
|
|
Extends: Vn.Object
|
|
|
|
|
|
|
|
,tpvOrder: null
|
|
|
|
,tpvStatus: null
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,check(callback) {
|
2022-05-30 01:30:33 +00:00
|
|
|
this.tpvOrder = this.hash.$.tpvOrder;
|
|
|
|
this.tpvStatus = this.hash.$.tpvStatus;
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2019-02-14 15:26:13 +00:00
|
|
|
if (this.tpvStatus) {
|
2022-05-30 01:30:33 +00:00
|
|
|
const params = {
|
|
|
|
transaction: this.tpvOrder,
|
|
|
|
status: this.tpvStatus
|
|
|
|
};
|
2022-10-03 13:50:39 +00:00
|
|
|
const query = 'CALL myTpvTransaction_end(#transaction, #status)';
|
2022-05-30 01:30:33 +00:00
|
|
|
this.conn.execQuery(query, null, params);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
2016-01-15 12:31:08 +00:00
|
|
|
|
|
|
|
if (callback)
|
2019-02-14 15:26:13 +00:00
|
|
|
callback(this, this.tpvOrder, this.tpvStatus);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,pay(amount, company) {
|
2019-02-14 15:26:13 +00:00
|
|
|
this._realPay(amount * 100, company);
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,_realPay(amount, company) {
|
2019-02-14 15:26:13 +00:00
|
|
|
if (isNumeric(amount) && amount > 0) {
|
2022-10-03 13:50:39 +00:00
|
|
|
const params = {
|
2019-02-14 15:26:13 +00:00
|
|
|
amount: parseInt(amount)
|
|
|
|
,urlOk: this._makeUrl('ok')
|
|
|
|
,urlKo: this._makeUrl('ko')
|
2017-12-01 14:38:23 +00:00
|
|
|
,company: company
|
2016-05-05 15:47:45 +00:00
|
|
|
};
|
2015-12-19 15:42:38 +00:00
|
|
|
|
2019-02-14 15:26:13 +00:00
|
|
|
this.conn.send('tpv/transaction', params,
|
|
|
|
this._onTransactionStart.bind(this));
|
|
|
|
} else
|
|
|
|
Htk.Toast.showError(_('AmountError'));
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,_onTransactionStart(json) {
|
2019-02-14 15:26:13 +00:00
|
|
|
if (json) {
|
2022-10-03 13:50:39 +00:00
|
|
|
const postValues = json.postValues;
|
2017-12-01 14:38:23 +00:00
|
|
|
|
2022-10-03 13:50:39 +00:00
|
|
|
const form = document.createElement('form');
|
2017-12-11 08:38:25 +00:00
|
|
|
form.method = 'POST';
|
2016-05-05 15:47:45 +00:00
|
|
|
form.action = json.url;
|
2019-02-14 15:26:13 +00:00
|
|
|
document.body.appendChild(form);
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2019-02-14 15:26:13 +00:00
|
|
|
for (var field in postValues) {
|
2022-10-03 13:50:39 +00:00
|
|
|
const input = document.createElement('input');
|
2015-09-11 09:37:16 +00:00
|
|
|
input.type = 'hidden';
|
|
|
|
input.name = field;
|
2019-02-14 15:26:13 +00:00
|
|
|
form.appendChild(input);
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2017-12-01 14:38:23 +00:00
|
|
|
if (postValues[field])
|
|
|
|
input.value = postValues[field];
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2019-02-14 15:26:13 +00:00
|
|
|
form.submit();
|
|
|
|
} else
|
|
|
|
Htk.Toast.showWarning(_('PayError'));
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
2016-05-05 15:47:45 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,retryPay() {
|
2022-05-30 01:30:33 +00:00
|
|
|
const params = {transaction: parseInt(this.tpvOrder)};
|
2016-05-05 15:47:45 +00:00
|
|
|
|
2022-10-03 13:50:39 +00:00
|
|
|
const query = 'SELECT t.amount, m.companyFk '
|
2017-12-20 14:47:46 +00:00
|
|
|
+'FROM myTpvTransaction t '
|
|
|
|
+'JOIN tpvMerchant m ON m.id = t.merchantFk '
|
2016-05-05 15:47:45 +00:00
|
|
|
+'WHERE t.id = #transaction';
|
2019-02-14 15:26:13 +00:00
|
|
|
this.conn.execQuery(query,
|
2022-05-30 01:30:33 +00:00
|
|
|
this._onRetryPayDone.bind(this), params);
|
2016-05-05 15:47:45 +00:00
|
|
|
}
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,_onRetryPayDone(resultSet) {
|
2022-10-03 13:50:39 +00:00
|
|
|
const res = resultSet.fetchObject();
|
2016-05-05 15:47:45 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
if (res)
|
|
|
|
this._realPay(res.amount, res.companyFk);
|
2016-05-05 15:47:45 +00:00
|
|
|
else
|
2019-02-14 15:26:13 +00:00
|
|
|
Htk.Toast.showError(_('AmountError'));
|
2016-05-05 15:47:45 +00:00
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
,_makeUrl(status) {
|
2022-10-03 13:50:39 +00:00
|
|
|
let path = location.protocol +'//'+ location.hostname;
|
2015-09-11 09:37:16 +00:00
|
|
|
path += location.port ? ':'+ location.port : '';
|
|
|
|
path += location.pathname;
|
|
|
|
path += location.search ? location.search : '';
|
2022-10-03 13:50:39 +00:00
|
|
|
path += this.hash.make({
|
2017-12-01 14:38:23 +00:00
|
|
|
form: 'ecomerce/orders',
|
|
|
|
tpvStatus: status,
|
2019-02-14 15:26:13 +00:00
|
|
|
tpvOrder: '_transactionId_'
|
2015-09-11 09:37:16 +00:00
|
|
|
}, true);
|
|
|
|
return path;
|
|
|
|
}
|
2016-01-15 12:31:08 +00:00
|
|
|
});
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2019-02-14 15:26:13 +00:00
|
|
|
function isNumeric(n) {
|
|
|
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
2017-12-01 14:38:23 +00:00
|
|
|
}
|