0
1
Fork 0
hedera-web-mindshore/js/hedera/tpv.js

122 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
module.exports = new Class
({
Extends: Vn.Object
,tpvOrder: null
,tpvStatus: null
,check: function (callback)
{
2016-09-24 14:32:31 +00:00
this.tpvOrder = Vn.Hash.get ('tpvOrder');
this.tpvStatus = Vn.Hash.get ('tpvStatus');
if (this.tpvStatus)
{
var batch = new Sql.Batch ();
batch.addValue ('transaction', this.tpvOrder);
batch.addValue ('status', this.tpvStatus);
2017-12-20 14:47:46 +00:00
var query = 'CALL tpvTransactionEnd (#transaction, #status)';
this.conn.execQuery (query, null, batch);
}
if (callback)
callback (this, this.tpvOrder, this.tpvStatus);
}
,pay: function (amount, company)
{
2017-12-01 14:38:23 +00:00
this._realPay (amount * 100, company);
}
2017-12-01 14:38:23 +00:00
,_realPay: function (amount, company)
{
if (isNumeric (amount) && amount > 0)
{
var params = {
2017-12-01 14:38:23 +00:00
amount: parseInt (amount)
,urlOk: this._makeUrl ('ok')
,urlKo: this._makeUrl ('ko')
,company: company
};
2016-09-24 14:32:31 +00:00
this.conn.send ('tpv/transaction', params,
this._onTransactionStart.bind (this));
}
2017-12-01 14:38:23 +00:00
else
Htk.Toast.showError (_('AmountError'));
}
2017-12-11 08:38:25 +00:00
,_onTransactionStart: function (json)
{
if (json)
{
2017-12-01 14:38:23 +00:00
var postValues = json.postValues;
var form = document.createElement ('form');
2017-12-11 08:38:25 +00:00
form.method = 'POST';
form.action = json.url;
document.body.appendChild (form);
2017-12-01 14:38:23 +00:00
for (var field in postValues)
{
var input = document.createElement ('input');
input.type = 'hidden';
input.name = field;
form.appendChild (input);
2017-12-01 14:38:23 +00:00
if (postValues[field])
input.value = postValues[field];
}
form.submit ();
}
else
Htk.Toast.showWarning (_('PayError'));
}
,retryPay: function ()
{
var batch = new Sql.Batch ();
batch.addValue ('transaction', parseInt (this.tpvOrder));
2017-12-20 11:34:04 +00:00
var 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';
this.conn.execQuery (query,
this._onRetryPayDone.bind (this), batch);
}
,_onRetryPayDone: function (resultSet)
{
var res = resultSet.fetchResult ();
if (res.next ())
2017-12-20 11:34:04 +00:00
this._realPay (res.get ('amount'), res.get ('companyFk'));
else
Htk.Toast.showError (_('AmountError'));
}
2017-12-11 08:38:25 +00:00
,_makeUrl: function (status)
{
var path = location.protocol +'//'+ location.host;
path += location.port ? ':'+ location.port : '';
path += location.pathname;
path += location.search ? location.search : '';
path += Vn.Hash.make ({
2017-12-01 14:38:23 +00:00
form: 'ecomerce/orders',
tpvStatus: status,
tpvOrder: '%s'
}, true);
return path;
}
});
2017-12-01 14:38:23 +00:00
function isNumeric (n)
{
return !isNaN (parseFloat(n)) && isFinite (n);
}