2015-09-11 09:37:16 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports = new Class
|
2016-01-15 12:31:08 +00:00
|
|
|
({
|
|
|
|
Extends: Vn.Object
|
|
|
|
|
|
|
|
,tpvOrder: null
|
|
|
|
,tpvStatus: null
|
|
|
|
|
|
|
|
,check: function (callback)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2016-09-24 14:32:31 +00:00
|
|
|
this.tpvOrder = Vn.Hash.get ('tpvOrder');
|
|
|
|
this.tpvStatus = Vn.Hash.get ('tpvStatus');
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2016-01-15 12:31:08 +00:00
|
|
|
if (this.tpvStatus)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
|
|
|
var batch = new Sql.Batch ();
|
2016-01-15 12:31:08 +00:00
|
|
|
batch.addValue ('transaction', this.tpvOrder);
|
|
|
|
batch.addValue ('status', this.tpvStatus);
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2016-10-15 18:58:30 +00:00
|
|
|
var query = 'CALL transactionEnd (#transaction, #status)';
|
2016-01-15 12:31:08 +00:00
|
|
|
this.conn.execQuery (query, null, batch);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
2016-01-15 12:31:08 +00:00
|
|
|
|
|
|
|
if (callback)
|
|
|
|
callback (this, this.tpvOrder, this.tpvStatus);
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
2016-01-15 12:31:08 +00:00
|
|
|
,pay: function (amount, company)
|
|
|
|
{
|
2017-12-01 14:38:23 +00:00
|
|
|
this._realPay (amount * 100, company);
|
2016-01-15 12:31:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-01 14:38:23 +00:00
|
|
|
,_realPay: function (amount, company)
|
|
|
|
{
|
|
|
|
if (isNumeric (amount) && amount > 0)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2016-05-05 15:47:45 +00:00
|
|
|
var params = {
|
2017-12-01 14:38:23 +00:00
|
|
|
amount: parseInt (amount)
|
|
|
|
,urlOk: this._makeUrl ('ok')
|
|
|
|
,urlKo: this._makeUrl ('ko')
|
|
|
|
,company: company
|
2016-05-05 15:47:45 +00:00
|
|
|
};
|
2015-12-19 15:42:38 +00:00
|
|
|
|
2016-09-24 14:32:31 +00:00
|
|
|
this.conn.send ('tpv/transaction', params,
|
2016-05-05 15:47:45 +00:00
|
|
|
this._onTransactionStart.bind (this));
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
2017-12-01 14:38:23 +00:00
|
|
|
else
|
2015-09-11 09:37:16 +00:00
|
|
|
Htk.Toast.showError (_('AmountError'));
|
|
|
|
}
|
2016-01-15 12:31:08 +00:00
|
|
|
|
2017-12-11 08:38:25 +00:00
|
|
|
,_onTransactionStart: function (json)
|
2016-01-15 12:31:08 +00:00
|
|
|
{
|
2016-05-05 15:47:45 +00:00
|
|
|
if (json)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2017-12-01 14:38:23 +00:00
|
|
|
var postValues = json.postValues;
|
|
|
|
|
2015-09-11 09:37:16 +00:00
|
|
|
var 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;
|
2015-09-11 09:37:16 +00:00
|
|
|
document.body.appendChild (form);
|
|
|
|
|
2017-12-01 14:38:23 +00:00
|
|
|
for (var field in postValues)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
|
|
|
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];
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
form.submit ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Htk.Toast.showWarning (_('PayError'));
|
|
|
|
}
|
2016-05-05 15:47:45 +00:00
|
|
|
|
|
|
|
,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 '
|
2016-05-05 15:47:45 +00:00
|
|
|
+'FROM tpv_transaction_view t '
|
2017-12-20 11:34:04 +00:00
|
|
|
+'JOIN tpvMerchant m ON m.id = t.merchant_id '
|
2016-05-05 15:47:45 +00:00
|
|
|
+'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'));
|
2016-05-05 15:47:45 +00:00
|
|
|
else
|
|
|
|
Htk.Toast.showError (_('AmountError'));
|
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2017-12-11 08:38:25 +00:00
|
|
|
,_makeUrl: function (status)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
|
|
|
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'
|
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
|
|
|
|
2017-12-01 14:38:23 +00:00
|
|
|
function isNumeric (n)
|
|
|
|
{
|
|
|
|
return !isNaN (parseFloat(n)) && isFinite (n);
|
|
|
|
}
|