0
1
Fork 0

Catalog text overlap fixed, tpv return url fixed

This commit is contained in:
Juan Ferrer 2019-02-14 16:26:13 +01:00
parent 27ec20369e
commit 0a5aa8e6cd
9 changed files with 121 additions and 140 deletions

View File

@ -12,3 +12,4 @@ rules:
brace-style: [error, 1tbs] brace-style: [error, 1tbs]
space-before-function-paren: [error, never] space-before-function-paren: [error, never]
padded-blocks: [error, never] padded-blocks: [error, never]
func-call-spacing: [error, never]

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (1.406.32) stable; urgency=low hedera-web (1.406.33) stable; urgency=low
* Initial Release. * Initial Release.

View File

@ -162,6 +162,7 @@
font-size: 1.1em; font-size: 1.1em;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
max-height: 2.4em;
} }
.item-info > p .item-info > p
{ {

View File

@ -1,66 +1,57 @@
Hedera.Orders = new Class Hedera.Orders = new Class({
({ Extends: Hedera.Form,
Extends: Hedera.Form
,activate: function () activate: function() {
{ this.tpv = new Hedera.Tpv({conn: this.conn});
this.tpv = new Hedera.Tpv ({conn: this.conn}); this.tpv.check(this._onTpvCheck.bind(this));
this.tpv.check (this._onTpvCheck.bind (this)); },
}
,_onTpvCheck: function (tpv, tpvOrder, tpvStatus) _onTpvCheck: function(tpv, tpvOrder, tpvStatus) {
{
if (tpvStatus === 'ko') if (tpvStatus === 'ko')
this.$('error-dialog').show (); this.$('error-dialog').show();
} },
,onBasketClick: function () onBasketClick: function() {
{ this.hash.set({form: 'ecomerce/basket'});
this.hash.set ({form: 'ecomerce/basket'}); },
}
,repeaterFunc: function (res, form) repeaterFunc: function(res, form) {
{ res.$('link').href = this.hash.make({
res.$('link').href = this.hash.make ({
form: 'ecomerce/ticket', form: 'ecomerce/ticket',
ticket: form.get ('id') ticket: form.get('id')
}); });
} },
// TPV // TPV
,balanceConditionalFunc: function (field, value) balanceConditionalFunc: function(field, value) {
{
if (value >= 0) if (value >= 0)
Vn.Node.removeClass (this.$('balance'), 'negative'); Vn.Node.removeClass(this.$('balance'), 'negative');
else else
Vn.Node.addClass (this.$('balance'), 'negative'); Vn.Node.addClass(this.$('balance'), 'negative');
} },
,onPayButtonClick: function () onPayButtonClick: function() {
{
var amount = -this.$('debt').value; var amount = -this.$('debt').value;
amount = amount <= 0 ? null : amount; amount = amount <= 0 ? null : amount;
var defaultAmountStr = ''; var defaultAmountStr = '';
if (amount !== null) if (amount !== null)
defaultAmountStr = Vn.Value.format (amount, '%.2d'); defaultAmountStr = Vn.Value.format(amount, '%.2d');
amount = prompt (_('AmountToPay:'), defaultAmountStr); amount = prompt(_('AmountToPay:'), defaultAmountStr);
if (amount != null) if (amount != null) {
{ amount = parseFloat(amount.replace(',', '.'));
amount = parseFloat (amount.replace (',', '.')); this.tpv.pay(amount, null);
this.tpv.pay (amount, null);
}
} }
},
,onDialogResponse: function (dialog, response) onDialogResponse: function(dialog, response) {
{
if (response == Htk.Dialog.Button.RETRY) if (response == Htk.Dialog.Button.RETRY)
this.tpv.retryPay (); this.tpv.retryPay();
} }
}); });

View File

@ -6,116 +6,102 @@ module.exports = new Class
,tpvOrder: null ,tpvOrder: null
,tpvStatus: null ,tpvStatus: null
,check: function (callback) ,check: function(callback) {
{ this.tpvOrder = Vn.Hash.get('tpvOrder');
this.tpvOrder = Vn.Hash.get ('tpvOrder'); this.tpvStatus = Vn.Hash.get('tpvStatus');
this.tpvStatus = Vn.Hash.get ('tpvStatus');
if (this.tpvStatus) if (this.tpvStatus) {
{ var batch = new Sql.Batch();
var batch = new Sql.Batch (); batch.addValue('transaction', this.tpvOrder);
batch.addValue ('transaction', this.tpvOrder); batch.addValue('status', this.tpvStatus);
batch.addValue ('status', this.tpvStatus);
var query = 'CALL tpvTransactionEnd (#transaction, #status)'; var query = 'CALL tpvTransactionEnd (#transaction, #status)';
this.conn.execQuery (query, null, batch); this.conn.execQuery(query, null, batch);
} }
if (callback) if (callback)
callback (this, this.tpvOrder, this.tpvStatus); callback(this, this.tpvOrder, this.tpvStatus);
} }
,pay: function (amount, company) ,pay: function(amount, company) {
{ this._realPay(amount * 100, company);
this._realPay (amount * 100, company);
} }
,_realPay: function (amount, company) ,_realPay: function(amount, company) {
{ if (isNumeric(amount) && amount > 0) {
if (isNumeric (amount) && amount > 0)
{
var params = { var params = {
amount: parseInt (amount) amount: parseInt(amount)
,urlOk: this._makeUrl ('ok') ,urlOk: this._makeUrl('ok')
,urlKo: this._makeUrl ('ko') ,urlKo: this._makeUrl('ko')
,company: company ,company: company
}; };
this.conn.send ('tpv/transaction', params, this.conn.send('tpv/transaction', params,
this._onTransactionStart.bind (this)); this._onTransactionStart.bind(this));
} } else
else Htk.Toast.showError(_('AmountError'));
Htk.Toast.showError (_('AmountError'));
} }
,_onTransactionStart: function (json) ,_onTransactionStart: function(json) {
{ if (json) {
if (json)
{
var postValues = json.postValues; var postValues = json.postValues;
var form = document.createElement ('form'); var form = document.createElement('form');
form.method = 'POST'; form.method = 'POST';
form.action = json.url; form.action = json.url;
document.body.appendChild (form); document.body.appendChild(form);
for (var field in postValues) for (var field in postValues) {
{ var input = document.createElement('input');
var input = document.createElement ('input');
input.type = 'hidden'; input.type = 'hidden';
input.name = field; input.name = field;
form.appendChild (input); form.appendChild(input);
if (postValues[field]) if (postValues[field])
input.value = postValues[field]; input.value = postValues[field];
} }
form.submit (); form.submit();
} } else
else Htk.Toast.showWarning(_('PayError'));
Htk.Toast.showWarning (_('PayError'));
} }
,retryPay: function () ,retryPay: function() {
{ var batch = new Sql.Batch();
var batch = new Sql.Batch (); batch.addValue('transaction', parseInt(this.tpvOrder));
batch.addValue ('transaction', parseInt (this.tpvOrder));
var query = 'SELECT t.amount, m.companyFk ' var query = 'SELECT t.amount, m.companyFk '
+'FROM myTpvTransaction t ' +'FROM myTpvTransaction t '
+'JOIN tpvMerchant m ON m.id = t.merchantFk ' +'JOIN tpvMerchant m ON m.id = t.merchantFk '
+'WHERE t.id = #transaction'; +'WHERE t.id = #transaction';
this.conn.execQuery (query, this.conn.execQuery(query,
this._onRetryPayDone.bind (this), batch); this._onRetryPayDone.bind(this), batch);
} }
,_onRetryPayDone: function (resultSet) ,_onRetryPayDone: function(resultSet) {
{ var res = resultSet.fetchResult();
var res = resultSet.fetchResult ();
if (res.next ()) if (res.next())
this._realPay (res.get ('amount'), res.get ('companyFk')); this._realPay(res.get('amount'), res.get('companyFk'));
else else
Htk.Toast.showError (_('AmountError')); Htk.Toast.showError(_('AmountError'));
} }
,_makeUrl: function (status) ,_makeUrl: function(status) {
{
var path = location.protocol +'//'+ location.host; var path = location.protocol +'//'+ location.host;
path += location.port ? ':'+ location.port : ''; path += location.port ? ':'+ location.port : '';
path += location.pathname; path += location.pathname;
path += location.search ? location.search : ''; path += location.search ? location.search : '';
path += Vn.Hash.make ({ path += Vn.Hash.make({
form: 'ecomerce/orders', form: 'ecomerce/orders',
tpvStatus: status, tpvStatus: status,
tpvOrder: '%s' tpvOrder: '_transactionId_'
}, true); }, true);
return path; return path;
} }
}); });
function isNumeric (n) function isNumeric(n) {
{ return !isNaN(parseFloat(n)) && isFinite(n);
return !isNaN (parseFloat(n)) && isFinite (n);
} }

View File

@ -1,5 +1,5 @@
var HashListener = require ('./hash-listener'); var HashListener = require('./hash-listener');
/** /**
* Class to handle the URL. * Class to handle the URL.
@ -11,15 +11,15 @@ module.exports =
,_listener: null ,_listener: null
,initialize: function() { ,initialize: function() {
this._listener = new HashListener (); this._listener = new HashListener();
this._hashChangedHandler = this._hashChanged.bind (this); this._hashChangedHandler = this._hashChanged.bind(this);
window.addEventListener ('hashchange', this._hashChangedHandler); window.addEventListener('hashchange', this._hashChangedHandler);
this._hashChanged (); this._hashChanged();
} }
,destroy: function() { ,destroy: function() {
window.removeEventListener ('hashchange', this._hashChangedHandler); window.removeEventListener('hashchange', this._hashChangedHandler);
} }
,getListener: function() { ,getListener: function() {
@ -46,7 +46,7 @@ module.exports =
for (var key in map) for (var key in map)
newMap[key] = map[key]; newMap[key] = map[key];
this.set (newMap); this.set(newMap);
} }
/** /**
@ -60,7 +60,7 @@ module.exports =
if (map[key] === null || map[key] === undefined) if (map[key] === null || map[key] === undefined)
delete map[key]; delete map[key];
var newHash = this.make (map); var newHash = this.make(map);
if (!map) if (!map)
map = {}; map = {};
@ -73,7 +73,7 @@ module.exports =
location.hash = newHash; location.hash = newHash;
this._blockChanged = false; this._blockChanged = false;
this._listener.changed (); this._listener.changed();
} }
} }
@ -109,10 +109,10 @@ module.exports =
return; return;
var newMap = hashMap = {}; var newMap = hashMap = {};
var kvPairs = newHash.substr(2).split ('&'); var kvPairs = newHash.substr(2).split('&');
for (var i = 0; i < kvPairs.length; i++) { for (var i = 0; i < kvPairs.length; i++) {
var kvPair = kvPairs[i].split ('=', 2); var kvPair = kvPairs[i].split('=', 2);
if (kvPair[0]) if (kvPair[0])
newMap[decodeURIComponent(kvPair[0])] = decodeURIComponent(kvPair[1]); newMap[decodeURIComponent(kvPair[0])] = decodeURIComponent(kvPair[1]);
@ -120,6 +120,6 @@ module.exports =
this._hashMap = newMap; this._hashMap = newMap;
this._hash = newHash; this._hash = newHash;
this._listener.changed (); this._listener.changed();
} }
}; };

View File

@ -8,10 +8,9 @@ module.exports =
* *
* @param {string} key The variable name * @param {string} key The variable name
**/ **/
getQuery: function (key) getQuery: function(key) {
{ var regExp = new RegExp('[\?\&]'+ key +'=([^\&]*)(\&?)', 'i');
var regExp = new RegExp ('[\?\&]'+ key +'=([^\&]*)(\&?)', 'i'); var value = location.search.match(regExp);
var value = location.search.match (regExp);
return value ? value[1] : value; return value ? value[1] : value;
} }
@ -22,21 +21,18 @@ module.exports =
* @param {string} key The variable name * @param {string} key The variable name
* @param {string} value The new value * @param {string} value The new value
**/ **/
,setQuery: function (key, value) ,setQuery: function(key, value) {
{
var changed = true; var changed = true;
var found = false; var found = false;
var newPair = key +'='+ value; var newPair = key +'='+ value;
var kvPairs = location.search.substr(1).split ('?'); var kvPairs = location.search.substr(1).split('?');
for (var i = 0; i < kvPairs.length; i++) for (var i = 0; i < kvPairs.length; i++) {
{ var kvPair = kvPairs[i].split('=', 1);
var kvPair = kvPairs[i].split ('=', 1);
if (kvPair[0] == key) if (kvPair[0] == key) {
{
if (kvPair[1] != value) if (kvPair[1] != value)
kvPairs.splice (i, 1, newPair); kvPairs.splice(i, 1, newPair);
else else
changed = false; changed = false;
@ -46,29 +42,26 @@ module.exports =
} }
if (!found) if (!found)
kvPairs.push (newPair); kvPairs.push(newPair);
if (changed) if (changed)
document.location.hash = '?'+ kvPairs.join ('&'); document.location.hash = '?'+ kvPairs.join('&');
} }
,makeUri: function (map) ,makeUri: function(map) {
{
var post = ''; var post = '';
for (var key in map) for (var key in map) {
{
var value = map[key]; var value = map[key];
if (post.length > 2)
post += '&';
if (value === null || value === undefined) if (value === null || value === undefined)
continue; continue;
if (typeof value == 'boolean') if (typeof value == 'boolean')
value = value ? '1' : '0'; value = value ? '1' : '0';
if (post.length > 2)
post += '&';
post += key +'='+ encodeURIComponent (value); post += encodeURIComponent(key) +'='+ encodeURIComponent(value);
} }
return post; return post;

View File

@ -1,6 +1,6 @@
{ {
"name": "hedera-web", "name": "hedera-web",
"version": "1.406.32", "version": "1.406.33",
"description": "Verdnatura web page", "description": "Verdnatura web page",
"license": "GPL-3.0", "license": "GPL-3.0",
"repository": { "repository": {

View File

@ -17,9 +17,11 @@ class Transaction extends Vn\Web\JsonRequest {
throw new Exception('Transaction error'); throw new Exception('Transaction error');
$transactionId = str_pad($row->transactionId, 12, '0', STR_PAD_LEFT); $transactionId = str_pad($row->transactionId, 12, '0', STR_PAD_LEFT);
$urlOk = empty($_REQUEST['urlOk']) ? '' : sprintf($_REQUEST['urlOk'], $transactionId);
$urlKo = empty($_REQUEST['urlKo']) ? '' : sprintf($_REQUEST['urlKo'], $transactionId);
$merchantUrl = $row->merchantUrl ? $row->merchantUrl : ''; $merchantUrl = $row->merchantUrl ? $row->merchantUrl : '';
$urlOk = empty($_REQUEST['urlOk']) ? '' :
str_replace('_transactionId_', $transactionId, $_REQUEST['urlOk']);
$urlKo = empty($_REQUEST['urlKo']) ? '' :
str_replace('_transactionId_', $transactionId, $_REQUEST['urlKo']);
$params = [ $params = [
'Ds_Merchant_Amount' => $amount 'Ds_Merchant_Amount' => $amount
@ -39,9 +41,16 @@ class Transaction extends Vn\Web\JsonRequest {
$bytes = [0, 0, 0, 0, 0, 0, 0, 0]; $bytes = [0, 0, 0, 0, 0, 0, 0, 0];
$iv = implode(array_map('chr', $bytes)); $iv = implode(array_map('chr', $bytes));
$key = mcrypt_encrypt(MCRYPT_3DES, $key, $transactionId, MCRYPT_MODE_CBC, $iv);
$signature = base64_encode(hash_hmac('sha256', $encodedParams, $key, TRUE)); $paddedData = $transactionId;
if (strlen($paddedData) % 8) {
$paddedData = str_pad($paddedData,
strlen($paddedData) + 8 - strlen($paddedData) % 8, "\0");
}
$encryptedData = openssl_encrypt($paddedData,
'des-ede3-cbc', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING , $iv);
$signature = base64_encode(hash_hmac('sha256', $encodedParams, $encryptedData, TRUE));
$url = $row->url; $url = $row->url;
$postValues = [ $postValues = [