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

121 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)
{
2017-04-05 14:06:07 +00:00
this.tpvOrder = this.hash.get ('tpvOrder');
this.tpvStatus = this.hash.get ('tpvStatus');
if (this.tpvStatus)
{
var query = 'CALL transactionEnd (#transaction, #status)';
2017-04-05 14:06:07 +00:00
var params = {
transaction: this.tpvOrder,
status: this.tpvStatus
};
this.conn.execQuery (query, null, params);
}
if (callback)
callback (this, this.tpvOrder, this.tpvStatus);
}
,pay: function (amount, company)
{
this._realPpay (amount * 100, company);
}
,_realPpay: function (amount, company)
{
if (amount > 0)
{
var params = {
2017-04-05 14:06:07 +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));
}
else if (!isNaN (amount))
Htk.Toast.showError (_('AmountError'));
}
2017-04-05 14:06:07 +00:00
,_onTransactionStart: function (json)
{
if (json)
{
var form = document.createElement ('form');
form.method = 'post';
form.action = json.url;
document.body.appendChild (form);
var fieldsMap =
{
2017-04-05 14:06:07 +00:00
Ds_SignatureVersion: 'HMAC_SHA256_V1'
,Ds_MerchantParameters: json.params
,Ds_Signature: json.signature
};
for (var field in fieldsMap)
{
var input = document.createElement ('input');
input.type = 'hidden';
input.name = field;
form.appendChild (input);
if (fieldsMap[field])
input.value = fieldsMap[field];
}
form.submit ();
}
else
Htk.Toast.showWarning (_('PayError'));
}
,retryPay: function ()
{
var query = 'SELECT t.amount, m.company_id '
+'FROM tpv_transaction_view t '
+'JOIN tpv_merchant m ON t.merchant_id = m.id '
+'WHERE t.id = #transaction';
2017-04-05 14:06:07 +00:00
var params = {transaction: parseInt (this.tpvOrder)};
this.conn.execQuery (query,
2017-04-05 14:06:07 +00:00
this._onRetryPayDone.bind (this), params);
}
,_onRetryPayDone: function (resultSet)
{
2017-04-08 11:42:27 +00:00
var row = resultSet.fetchObject ();
2017-04-08 11:42:27 +00:00
if (row)
this._realPpay (row.amount, row.company_id);
else
Htk.Toast.showError (_('AmountError'));
}
2017-04-05 14:06:07 +00:00
,_makeUrl: function (status)
{
var path = location.protocol +'//'+ location.host;
path += location.port ? ':'+ location.port : '';
path += location.pathname;
path += location.search ? location.search : '';
2017-04-05 14:06:07 +00:00
path += this.hash.make ({
'form': 'ecomerce/orders',
2016-09-24 14:32:31 +00:00
'tpvStatus': status,
'tpvOrder': '%s'
}, true);
return path;
}
});