Vn.Tpv = new Class ({ initialize: function (conn, hash) { this.conn = conn; this.hash = hash; var tpvStatus = this.hash.get ('tpv_status'); if (tpvStatus) { var batch = new Sql.Batch (); batch.addValue ('transaction', this.hash.get ('tpv_order')); batch.addValue ('status', tpvStatus); var query = 'CALL transaction_end (#transaction, #status)'; this.conn.execQuery (query, null, batch); } } ,pay: function (amount, company) { 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)); this.conn.execQuery (query, this.onTransactionStart.bind (this), batch); } else if (!isNaN (amount)) (new Htk.Toast ()).showError (_('AmountError')); } ,onTransactionStart: function (resultSet) { 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'); form['Ds_Merchant_UrlOK'].value = this.makeUrl ('ok', transactionId); form['Ds_Merchant_UrlKO'].value = this.makeUrl ('ko', transactionId); form.submit (); } else alert (_('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 += this.hash.make ({ 'tpv_status': status, 'tpv_order': order }, true); return path; } });