2015-07-10 12:30:08 +00:00
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
Vn.Tpv =
|
|
|
|
{
|
|
|
|
check: function (conn)
|
2015-07-10 12:30:08 +00:00
|
|
|
{
|
2015-07-28 19:14:26 +00:00
|
|
|
var tpvStatus = Vn.Hash.get ('tpv_status');
|
2015-07-10 12:30:08 +00:00
|
|
|
|
|
|
|
if (tpvStatus)
|
|
|
|
{
|
|
|
|
var batch = new Sql.Batch ();
|
2015-07-28 19:14:26 +00:00
|
|
|
batch.addValue ('transaction', Vn.Hash.get ('tpv_order'));
|
2015-07-10 12:30:08 +00:00
|
|
|
batch.addValue ('status', tpvStatus);
|
|
|
|
|
|
|
|
var query = 'CALL transaction_end (#transaction, #status)';
|
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
conn.execQuery (query, null, batch);
|
2015-07-10 12:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
,pay: function (conn, amount, company)
|
2015-07-10 12:30:08 +00:00
|
|
|
{
|
|
|
|
if (amount > 0)
|
|
|
|
{
|
|
|
|
var query = 'CALL transaction_start (#company, #amount)';
|
|
|
|
|
|
|
|
var batch = new Sql.Batch ();
|
|
|
|
batch.addValue ('company', company);
|
|
|
|
batch.addValue ('amount', parseInt (amount * 100));
|
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
conn.execQuery (query,
|
|
|
|
this._onTransactionStart.bind (this), batch);
|
2015-07-10 12:30:08 +00:00
|
|
|
}
|
|
|
|
else if (!isNaN (amount))
|
2015-08-17 18:02:14 +00:00
|
|
|
Htk.Toast.showError (_('AmountError'));
|
2015-07-10 12:30:08 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
,_onTransactionStart: function (resultSet)
|
2015-07-10 12:30:08 +00:00
|
|
|
{
|
|
|
|
var res = resultSet.fetchResult ();
|
|
|
|
|
|
|
|
if (res && res.next ())
|
|
|
|
{
|
|
|
|
var form = document.createElement ('form');
|
|
|
|
form.method = 'post';
|
|
|
|
form.action = res.get ('url');
|
|
|
|
document.body.appendChild (form);
|
|
|
|
|
|
|
|
var fieldsMap =
|
|
|
|
{
|
|
|
|
'Ds_Merchant_Amount': 'amount'
|
|
|
|
,'Ds_Merchant_Order': 'ds_order'
|
|
|
|
,'Ds_Merchant_MerchantCode': 'id'
|
|
|
|
,'Ds_Merchant_Currency': 'currency'
|
|
|
|
,'Ds_Merchant_TransactionType': 'transaction_type'
|
|
|
|
,'Ds_Merchant_Terminal': 'terminal'
|
|
|
|
,'Ds_Merchant_MerchantURL': 'merchant_url'
|
|
|
|
,'Ds_Merchant_MerchantSignature': 'signature'
|
|
|
|
,'Ds_Merchant_UrlOK': null
|
|
|
|
,'Ds_Merchant_UrlKO': null
|
|
|
|
};
|
|
|
|
|
|
|
|
for (var field in fieldsMap)
|
|
|
|
{
|
|
|
|
var input = document.createElement ('input');
|
|
|
|
input.type = 'hidden';
|
|
|
|
input.name = field;
|
|
|
|
form.appendChild (input);
|
|
|
|
|
|
|
|
if (fieldsMap[field])
|
|
|
|
input.value = res.get (fieldsMap[field]);
|
|
|
|
}
|
|
|
|
|
|
|
|
var transactionId = res.get ('ds_order');
|
2015-07-28 19:14:26 +00:00
|
|
|
form['Ds_Merchant_UrlOK'].value = this._makeUrl ('ok', transactionId);
|
|
|
|
form['Ds_Merchant_UrlKO'].value = this._makeUrl ('ko', transactionId);
|
2015-07-10 12:30:08 +00:00
|
|
|
|
|
|
|
form.submit ();
|
|
|
|
}
|
|
|
|
else
|
2015-08-17 18:02:14 +00:00
|
|
|
Htk.Toast.showWarning (_('PayError'));
|
2015-07-10 12:30:08 +00:00
|
|
|
}
|
|
|
|
|
2015-07-28 19:14:26 +00:00
|
|
|
,_makeUrl: function (status, order)
|
2015-07-10 12:30:08 +00:00
|
|
|
{
|
|
|
|
var path = location.protocol +'//'+ location.host;
|
|
|
|
path += location.port ? ':'+ location.port : '';
|
|
|
|
path += location.pathname;
|
|
|
|
path += location.search ? location.search : '';
|
2015-07-28 19:14:26 +00:00
|
|
|
path += Vn.Hash.make ({
|
2015-08-17 18:02:14 +00:00
|
|
|
'form': 'ecomerce/orders',
|
2015-07-10 12:30:08 +00:00
|
|
|
'tpv_status': status,
|
|
|
|
'tpv_order': order
|
|
|
|
}, true);
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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')
|
2015-08-17 18:02:14 +00:00
|
|
|
Htk.Toast.showWarning (_('OrderItemsUpdated'));
|
2015-07-28 19:14:26 +00:00
|
|
|
if (callback)
|
|
|
|
callback (isOk);
|
|
|
|
if (!isOk)
|
|
|
|
Vn.Hash.set ({'form': 'ecomerce/checkout'});
|
|
|
|
}
|
|
|
|
};
|
2015-07-10 12:30:08 +00:00
|
|
|
|