2015-09-11 09:37:16 +00:00
|
|
|
|
|
|
|
Vn.Tpv =
|
|
|
|
{
|
|
|
|
check: function (conn)
|
|
|
|
{
|
|
|
|
var tpvStatus = Vn.Hash.get ('tpv_status');
|
|
|
|
|
|
|
|
if (tpvStatus)
|
|
|
|
{
|
|
|
|
var batch = new Sql.Batch ();
|
|
|
|
batch.addValue ('transaction', Vn.Hash.get ('tpv_order'));
|
|
|
|
batch.addValue ('status', tpvStatus);
|
|
|
|
|
|
|
|
var query = 'CALL transaction_end (#transaction, #status)';
|
|
|
|
|
|
|
|
conn.execQuery (query, null, batch);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,pay: function (conn, amount, company)
|
|
|
|
{
|
|
|
|
if (amount > 0)
|
|
|
|
{
|
2015-12-19 15:42:38 +00:00
|
|
|
var request = new Vn.HttpRequest ();
|
|
|
|
request.add
|
|
|
|
({
|
|
|
|
'action': 'tpv'
|
|
|
|
,'amount': parseInt (amount * 100)
|
|
|
|
,'urlOk': this._makeUrl ('ok')
|
|
|
|
,'urlKo': this._makeUrl ('ko')
|
|
|
|
,'company': company
|
|
|
|
});
|
|
|
|
|
|
|
|
request.send ('rest.php',
|
|
|
|
this._onTransactionStart.bind (this, request));
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
else if (!isNaN (amount))
|
|
|
|
Htk.Toast.showError (_('AmountError'));
|
|
|
|
}
|
|
|
|
|
2015-12-19 15:42:38 +00:00
|
|
|
,_onTransactionStart: function (request, success)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
2015-12-19 15:42:38 +00:00
|
|
|
var data = null;
|
|
|
|
var error = null;
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
try {
|
|
|
|
var json = request.getJson ();
|
|
|
|
var data = json.data;
|
|
|
|
|
|
|
|
if (json.error)
|
|
|
|
error = new Vn.Error (
|
|
|
|
json.error.domain,
|
|
|
|
json.error.code,
|
|
|
|
json.error.message);
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
error = e;
|
|
|
|
}
|
2015-09-11 09:37:16 +00:00
|
|
|
|
2015-12-19 15:42:38 +00:00
|
|
|
if (success && data)
|
2015-09-11 09:37:16 +00:00
|
|
|
{
|
|
|
|
var form = document.createElement ('form');
|
|
|
|
form.method = 'post';
|
2015-12-19 15:42:38 +00:00
|
|
|
form.action = data.url;
|
2015-09-11 09:37:16 +00:00
|
|
|
document.body.appendChild (form);
|
|
|
|
|
|
|
|
var fieldsMap =
|
|
|
|
{
|
2015-12-19 15:42:38 +00:00
|
|
|
'Ds_SignatureVersion': 'HMAC_SHA256_V1'
|
|
|
|
,'Ds_MerchantParameters': data.params
|
|
|
|
,'Ds_Signature': data.signature
|
2015-09-11 09:37:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (var field in fieldsMap)
|
|
|
|
{
|
|
|
|
var input = document.createElement ('input');
|
|
|
|
input.type = 'hidden';
|
|
|
|
input.name = field;
|
|
|
|
form.appendChild (input);
|
|
|
|
|
|
|
|
if (fieldsMap[field])
|
2015-12-19 15:42:38 +00:00
|
|
|
input.value = fieldsMap[field];
|
2015-09-11 09:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
form.submit ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Htk.Toast.showWarning (_('PayError'));
|
|
|
|
}
|
|
|
|
|
|
|
|
,_makeUrl: function (status, order)
|
|
|
|
{
|
|
|
|
var path = location.protocol +'//'+ location.host;
|
|
|
|
path += location.port ? ':'+ location.port : '';
|
|
|
|
path += location.pathname;
|
|
|
|
path += location.search ? location.search : '';
|
|
|
|
path += Vn.Hash.make ({
|
|
|
|
'form': 'ecomerce/orders',
|
|
|
|
'tpv_status': status,
|
2015-12-19 15:42:38 +00:00
|
|
|
'tpv_order': '%s'
|
2015-09-11 09:37:16 +00:00
|
|
|
}, true);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Vn.BasketChecker =
|
|
|
|
{
|
|
|
|
check: function (conn, callback)
|
|
|
|
{
|
|
|
|
conn.execQuery ('CALL basket_check ()',
|
|
|
|
this._onBasketCheck.bind (this, callback));
|
|
|
|
}
|
|
|
|
|
|
|
|
,_onBasketCheck: function (callback, resultSet)
|
|
|
|
{
|
|
|
|
var status = resultSet.fetchValue ();
|
|
|
|
|
|
|
|
if (!status)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var isOk = status == 'UPDATED' || status == 'OK';
|
|
|
|
|
|
|
|
if (status == 'UPDATED')
|
|
|
|
Htk.Toast.showWarning (_('OrderItemsUpdated'));
|
|
|
|
if (callback)
|
|
|
|
callback (isOk);
|
|
|
|
if (!isOk)
|
|
|
|
Vn.Hash.set ({'form': 'ecomerce/checkout'});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|