hedera-web/js/hedera/tpv.js

87 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2022-05-28 15:49:46 +00:00
module.exports = new Class({
Extends: Vn.Object
,tpvOrder: null
,tpvStatus: null
2022-11-28 08:51:31 +00:00
,check() {
2022-05-30 01:30:33 +00:00
this.tpvOrder = this.hash.$.tpvOrder;
this.tpvStatus = this.hash.$.tpvStatus;
if (this.tpvStatus) {
this.conn.post('TpvTransactions/end', {
orderId: this.tpvOrder,
2022-05-30 01:30:33 +00:00
status: this.tpvStatus
})
}
2022-11-28 08:51:31 +00:00
return this.tpvStatus;
}
2022-11-28 08:51:31 +00:00
,async pay(amount, company) {
await this._realPay(amount * 100, company);
}
2022-11-28 08:51:31 +00:00
,async _realPay(amount, company) {
2022-12-09 11:51:51 +00:00
if (!isNumeric(amount) || amount <= 0) {
Htk.Toast.showError(_('AmountError'));
return;
2022-11-28 08:51:31 +00:00
}
const json = await this.conn.post('TpvTransactions/start', {
amount: parseInt(amount),
urlOk: this._makeUrl('ok'),
urlKo: this._makeUrl('ko'),
company
2022-12-09 11:51:51 +00:00
});
2022-11-28 08:51:31 +00:00
const postValues = json.postValues;
2017-12-01 14:38:23 +00:00
2022-11-28 08:51:31 +00:00
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);
2022-11-28 08:51:31 +00:00
if (postValues[field])
input.value = postValues[field];
}
form.submit();
}
2022-11-28 08:51:31 +00:00
,async retryPay() {
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 '
+'WHERE t.id = #transaction';
2022-11-28 08:51:31 +00:00
const res = await this.conn.execQuery(query,
{transaction: parseInt(this.tpvOrder)});
const payment = res.fetchObject();
await this._realPay(payment.amount, payment.companyFk);
}
2022-11-16 01:46:44 +00:00
,_makeUrl(status) {
2022-10-03 13:50:39 +00:00
let path = location.protocol +'//'+ location.hostname;
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,
tpvOrder: '_transactionId_'
}, true);
return path;
}
});
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
2017-12-01 14:38:23 +00:00
}