Tax and TPV bugs solved
This commit is contained in:
parent
5c05a2ef50
commit
fa4dd86862
|
@ -1,4 +1,4 @@
|
||||||
hedera-web (1.405.24) stable; urgency=low
|
hedera-web (1.405.25) stable; urgency=low
|
||||||
|
|
||||||
* Initial Release.
|
* Initial Release.
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ Hedera.Confirm = new Class
|
||||||
Vn.Node.setText (this.$('method'), _('Warehouse'));
|
Vn.Node.setText (this.$('method'), _('Warehouse'));
|
||||||
}
|
}
|
||||||
|
|
||||||
var total = form.get ('tax_base') + form.get ('vat');
|
var total = form.get ('taxBase') + form.get ('tax');
|
||||||
|
|
||||||
if (total === null)
|
if (total === null)
|
||||||
total = 0;
|
total = 0;
|
||||||
|
@ -149,10 +149,7 @@ Hedera.Confirm = new Class
|
||||||
this.disableButtons (false);
|
this.disableButtons (false);
|
||||||
|
|
||||||
if (resultSet.fetchResult ())
|
if (resultSet.fetchResult ())
|
||||||
{
|
|
||||||
Vn.Cookie.unset ('order');
|
|
||||||
this.$('success-dialog').show ();
|
this.$('success-dialog').show ();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
,onDialogResponse: function ()
|
,onDialogResponse: function ()
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<db-form id="order-form" on-ready="onOrderReady">
|
<db-form id="order-form" on-ready="onOrderReady">
|
||||||
<db-model property="model" result-index="1">
|
<db-model property="model" result-index="1">
|
||||||
<custom>
|
<custom>
|
||||||
CALL basket_get_vat ();
|
CALL basketGetTax;
|
||||||
SELECT o.id, o.date_send, o.note, o.company_id,
|
SELECT o.id, o.date_send, o.note, o.company_id,
|
||||||
ag.description agency, v.code method,
|
ag.description agency, v.code method,
|
||||||
ad.consignee, ad.zip_code, ad.city, ad.name address,
|
ad.consignee, ad.zip_code, ad.city, ad.name address,
|
||||||
|
@ -15,11 +15,11 @@
|
||||||
JOIN customer_view c
|
JOIN customer_view c
|
||||||
JOIN (
|
JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
IFNULL(SUM(tax_base), 0) tax_base,
|
IFNULL(SUM(taxBase), 0) taxBase,
|
||||||
IFNULL(SUM(vat + surcharge), 0) vat
|
IFNULL(SUM(tax + equalizationTax), 0) tax
|
||||||
FROM t_order_vat
|
FROM tmp.orderTax
|
||||||
) t;
|
) t;
|
||||||
DROP TEMPORARY TABLE t_order_vat;
|
DROP TEMPORARY TABLE tmp.orderTax;
|
||||||
</custom>
|
</custom>
|
||||||
</db-model>
|
</db-model>
|
||||||
</db-form>
|
</db-form>
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
<t>Order total</t>
|
<t>Order total</t>
|
||||||
</td>
|
</td>
|
||||||
<td class="currency">
|
<td class="currency">
|
||||||
<htk-text format="%.2d€" form="order-form" column="tax_base"/>
|
<htk-text format="%.2d€" form="order-form" column="taxBase"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -84,7 +84,7 @@
|
||||||
<t>Order VAT</t>
|
<t>Order VAT</t>
|
||||||
</td>
|
</td>
|
||||||
<td class="currency">
|
<td class="currency">
|
||||||
<htk-text format="%.2d€" form="order-form" column="vat"/>
|
<htk-text format="%.2d€" form="order-form" column="tax"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="total-debt sum-total">
|
<tr class="total-debt sum-total">
|
||||||
|
|
|
@ -41,17 +41,20 @@ Hedera.Orders = new Class
|
||||||
,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);
|
||||||
|
|
||||||
var amount = parseFloat (prompt (_('AmountToPay:'), defaultAmountStr));
|
if (amount != null)
|
||||||
|
{
|
||||||
this.tpv.pay (amount, null);
|
amount = parseFloat (amount.replace (',', '.'));
|
||||||
|
this.tpv.pay (amount, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
,onDialogResponse: function (dialog, response)
|
,onDialogResponse: function (dialog, response)
|
||||||
|
|
|
@ -27,24 +27,24 @@ module.exports = new Class
|
||||||
|
|
||||||
,pay: function (amount, company)
|
,pay: function (amount, company)
|
||||||
{
|
{
|
||||||
this._realPpay (amount * 100, company);
|
this._realPay (amount * 100, company);
|
||||||
}
|
}
|
||||||
|
|
||||||
,_realPpay: function (amount, company)
|
,_realPay: function (amount, company)
|
||||||
{
|
{
|
||||||
if (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 if (!isNaN (amount))
|
else
|
||||||
Htk.Toast.showError (_('AmountError'));
|
Htk.Toast.showError (_('AmountError'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,27 +52,22 @@ module.exports = new Class
|
||||||
{
|
{
|
||||||
if (json)
|
if (json)
|
||||||
{
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
var fieldsMap =
|
for (var field in postValues)
|
||||||
{
|
|
||||||
'Ds_SignatureVersion': 'HMAC_SHA256_V1'
|
|
||||||
,'Ds_MerchantParameters': json.params
|
|
||||||
,'Ds_Signature': json.signature
|
|
||||||
};
|
|
||||||
|
|
||||||
for (var field in fieldsMap)
|
|
||||||
{
|
{
|
||||||
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 (fieldsMap[field])
|
if (postValues[field])
|
||||||
input.value = fieldsMap[field];
|
input.value = postValues[field];
|
||||||
}
|
}
|
||||||
|
|
||||||
form.submit ();
|
form.submit ();
|
||||||
|
@ -99,7 +94,7 @@ module.exports = new Class
|
||||||
var res = resultSet.fetchResult ();
|
var res = resultSet.fetchResult ();
|
||||||
|
|
||||||
if (res.next ())
|
if (res.next ())
|
||||||
this._realPpay (res.get ('amount'), res.get ('company_id'));
|
this._realPay (res.get ('amount'), res.get ('company_id'));
|
||||||
else
|
else
|
||||||
Htk.Toast.showError (_('AmountError'));
|
Htk.Toast.showError (_('AmountError'));
|
||||||
}
|
}
|
||||||
|
@ -111,12 +106,16 @@ module.exports = new Class
|
||||||
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: '%s'
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function isNumeric (n)
|
||||||
|
{
|
||||||
|
return !isNaN (parseFloat(n)) && isFinite (n);
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "hedera-web",
|
"name": "hedera-web",
|
||||||
"version": "1.405.24",
|
"version": "1.405.25",
|
||||||
"description": "Verdnatura web page",
|
"description": "Verdnatura web page",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts a new TPV transaction and returns the params.
|
* Starts a new TPV transaction and returns the params.
|
||||||
**/
|
*/
|
||||||
class Transaction extends Vn\Web\JsonRequest
|
class Transaction extends Vn\Web\JsonRequest
|
||||||
{
|
{
|
||||||
const PARAMS = ['amount'];
|
const PARAMS = ['amount'];
|
||||||
|
@ -12,24 +12,24 @@ class Transaction extends Vn\Web\JsonRequest
|
||||||
$amount = (int) $_REQUEST['amount'];
|
$amount = (int) $_REQUEST['amount'];
|
||||||
$companyId = empty ($_REQUEST['company']) ? NULL : $_REQUEST['company'];
|
$companyId = empty ($_REQUEST['company']) ? NULL : $_REQUEST['company'];
|
||||||
|
|
||||||
$row = $db->getRow ('CALL transactionStart (#, #)',
|
$row = $db->getObject ('CALL transactionStart (#, #)',
|
||||||
[$amount, $companyId]);
|
[$amount, $companyId]);
|
||||||
|
|
||||||
if (!isset ($row))
|
if (!isset ($row))
|
||||||
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);
|
$urlOk = empty ($_REQUEST['urlOk']) ? '' : sprintf ($_REQUEST['urlOk'], $transactionId);
|
||||||
$urlKo = empty ($_REQUEST['urlKo']) ? '' : sprintf ($_REQUEST['urlKo'], $transactionId);
|
$urlKo = empty ($_REQUEST['urlKo']) ? '' : sprintf ($_REQUEST['urlKo'], $transactionId);
|
||||||
$merchantUrl = $row['merchantUrl'] ? $row['merchantUrl'] : '';
|
$merchantUrl = $row->merchantUrl ? $row->merchantUrl : '';
|
||||||
|
|
||||||
$params = [
|
$params = [
|
||||||
'Ds_Merchant_Amount' => $amount
|
'Ds_Merchant_Amount' => $amount
|
||||||
,'Ds_Merchant_Order' => $transactionId
|
,'Ds_Merchant_Order' => $transactionId
|
||||||
,'Ds_Merchant_MerchantCode' => $row['merchant']
|
,'Ds_Merchant_MerchantCode' => $row->merchant
|
||||||
,'Ds_Merchant_Currency' => $row['currency']
|
,'Ds_Merchant_Currency' => $row->currency
|
||||||
,'Ds_Merchant_TransactionType' => $row['transactionType']
|
,'Ds_Merchant_TransactionType' => $row->transactionType
|
||||||
,'Ds_Merchant_Terminal' => $row['terminal']
|
,'Ds_Merchant_Terminal' => $row->terminal
|
||||||
,'Ds_Merchant_MerchantURL' => $merchantUrl
|
,'Ds_Merchant_MerchantURL' => $merchantUrl
|
||||||
,'Ds_Merchant_UrlOK' => $urlOk
|
,'Ds_Merchant_UrlOK' => $urlOk
|
||||||
,'Ds_Merchant_UrlKO' => $urlKo
|
,'Ds_Merchant_UrlKO' => $urlKo
|
||||||
|
@ -37,20 +37,24 @@ class Transaction extends Vn\Web\JsonRequest
|
||||||
|
|
||||||
$encodedParams = base64_encode (json_encode ($params));
|
$encodedParams = base64_encode (json_encode ($params));
|
||||||
|
|
||||||
$key = base64_decode ($row['secretKey']);
|
$key = base64_decode ($row->secretKey);
|
||||||
|
|
||||||
$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);
|
$key = mcrypt_encrypt (MCRYPT_3DES, $key, $transactionId, MCRYPT_MODE_CBC, $iv);
|
||||||
|
|
||||||
$signature = base64_encode (hash_hmac ('sha256', $encodedParams, $key, TRUE));
|
$signature = base64_encode (hash_hmac ('sha256', $encodedParams, $key, TRUE));
|
||||||
$url = $row['url'];
|
|
||||||
|
$url = $row->url;
|
||||||
|
$postValues = [
|
||||||
|
'Ds_SignatureVersion' => 'HMAC_SHA256_V1'
|
||||||
|
,'Ds_MerchantParameters' => $encodedParams
|
||||||
|
,'Ds_Signature' => $signature
|
||||||
|
];
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'url' => $url
|
'url' => $url
|
||||||
,'params' => $encodedParams
|
,'postValues' => $postValues
|
||||||
,'signature' => $signature
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue