Tax and TPV bugs solved

This commit is contained in:
Juan Ferrer Toribio 2017-12-01 15:38:23 +01:00
parent 5c05a2ef50
commit fa4dd86862
8 changed files with 57 additions and 54 deletions

2
debian/changelog vendored
View File

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

View File

@ -34,7 +34,7 @@ Hedera.Confirm = new Class
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)
total = 0;
@ -149,10 +149,7 @@ Hedera.Confirm = new Class
this.disableButtons (false);
if (resultSet.fetchResult ())
{
Vn.Cookie.unset ('order');
this.$('success-dialog').show ();
}
}
,onDialogResponse: function ()

View File

@ -3,7 +3,7 @@
<db-form id="order-form" on-ready="onOrderReady">
<db-model property="model" result-index="1">
<custom>
CALL basket_get_vat ();
CALL basketGetTax;
SELECT o.id, o.date_send, o.note, o.company_id,
ag.description agency, v.code method,
ad.consignee, ad.zip_code, ad.city, ad.name address,
@ -15,11 +15,11 @@
JOIN customer_view c
JOIN (
SELECT
IFNULL(SUM(tax_base), 0) tax_base,
IFNULL(SUM(vat + surcharge), 0) vat
FROM t_order_vat
IFNULL(SUM(taxBase), 0) taxBase,
IFNULL(SUM(tax + equalizationTax), 0) tax
FROM tmp.orderTax
) t;
DROP TEMPORARY TABLE t_order_vat;
DROP TEMPORARY TABLE tmp.orderTax;
</custom>
</db-model>
</db-form>
@ -76,7 +76,7 @@
<t>Order total</t>
</td>
<td class="currency">
<htk-text format="%.2d€" form="order-form" column="tax_base"/>
<htk-text format="%.2d€" form="order-form" column="taxBase"/>
</td>
</tr>
<tr>
@ -84,7 +84,7 @@
<t>Order VAT</t>
</td>
<td class="currency">
<htk-text format="%.2d€" form="order-form" column="vat"/>
<htk-text format="%.2d€" form="order-form" column="tax"/>
</td>
</tr>
<tr class="total-debt sum-total">

View File

@ -41,17 +41,20 @@ Hedera.Orders = new Class
,onPayButtonClick: function ()
{
var amount = -this.$('debt').value;
amount = amount <= 0 ? null : amount;
var defaultAmountStr = '';
if (amount !== null)
defaultAmountStr = Vn.Value.format (amount, '%.2d');
amount = prompt (_('AmountToPay:'), defaultAmountStr);
var amount = parseFloat (prompt (_('AmountToPay:'), defaultAmountStr));
this.tpv.pay (amount, null);
if (amount != null)
{
amount = parseFloat (amount.replace (',', '.'));
this.tpv.pay (amount, null);
}
}
,onDialogResponse: function (dialog, response)

View File

@ -27,24 +27,24 @@ module.exports = new Class
,pay: function (amount, company)
{
this._realPpay (amount * 100, company);
this._realPay (amount * 100, company);
}
,_realPpay: function (amount, company)
{
if (amount > 0)
,_realPay: function (amount, company)
{
if (isNumeric (amount) && amount > 0)
{
var params = {
'amount': parseInt (amount)
,'urlOk': this._makeUrl ('ok')
,'urlKo': this._makeUrl ('ko')
,'company': company
amount: parseInt (amount)
,urlOk: this._makeUrl ('ok')
,urlKo: this._makeUrl ('ko')
,company: company
};
this.conn.send ('tpv/transaction', params,
this._onTransactionStart.bind (this));
}
else if (!isNaN (amount))
else
Htk.Toast.showError (_('AmountError'));
}
@ -52,27 +52,22 @@ module.exports = new Class
{
if (json)
{
var postValues = json.postValues;
var form = document.createElement ('form');
form.method = 'post';
form.action = json.url;
document.body.appendChild (form);
var fieldsMap =
{
'Ds_SignatureVersion': 'HMAC_SHA256_V1'
,'Ds_MerchantParameters': json.params
,'Ds_Signature': json.signature
};
for (var field in fieldsMap)
for (var field in postValues)
{
var input = document.createElement ('input');
input.type = 'hidden';
input.name = field;
form.appendChild (input);
if (fieldsMap[field])
input.value = fieldsMap[field];
if (postValues[field])
input.value = postValues[field];
}
form.submit ();
@ -99,7 +94,7 @@ module.exports = new Class
var res = resultSet.fetchResult ();
if (res.next ())
this._realPpay (res.get ('amount'), res.get ('company_id'));
this._realPay (res.get ('amount'), res.get ('company_id'));
else
Htk.Toast.showError (_('AmountError'));
}
@ -111,12 +106,16 @@ module.exports = new Class
path += location.pathname;
path += location.search ? location.search : '';
path += Vn.Hash.make ({
'form': 'ecomerce/orders',
'tpvStatus': status,
'tpvOrder': '%s'
form: 'ecomerce/orders',
tpvStatus: status,
tpvOrder: '%s'
}, true);
return path;
}
});
function isNumeric (n)
{
return !isNaN (parseFloat(n)) && isFinite (n);
}

View File

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

0
pages/production/ui.php Normal file
View File

View File

@ -2,7 +2,7 @@
/**
* Starts a new TPV transaction and returns the params.
**/
*/
class Transaction extends Vn\Web\JsonRequest
{
const PARAMS = ['amount'];
@ -12,24 +12,24 @@ class Transaction extends Vn\Web\JsonRequest
$amount = (int) $_REQUEST['amount'];
$companyId = empty ($_REQUEST['company']) ? NULL : $_REQUEST['company'];
$row = $db->getRow ('CALL transactionStart (#, #)',
$row = $db->getObject ('CALL transactionStart (#, #)',
[$amount, $companyId]);
if (!isset ($row))
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 : '';
$params = [
'Ds_Merchant_Amount' => $amount
,'Ds_Merchant_Order' => $transactionId
,'Ds_Merchant_MerchantCode' => $row['merchant']
,'Ds_Merchant_Currency' => $row['currency']
,'Ds_Merchant_TransactionType' => $row['transactionType']
,'Ds_Merchant_Terminal' => $row['terminal']
,'Ds_Merchant_MerchantCode' => $row->merchant
,'Ds_Merchant_Currency' => $row->currency
,'Ds_Merchant_TransactionType' => $row->transactionType
,'Ds_Merchant_Terminal' => $row->terminal
,'Ds_Merchant_MerchantURL' => $merchantUrl
,'Ds_Merchant_UrlOK' => $urlOk
,'Ds_Merchant_UrlKO' => $urlKo
@ -37,20 +37,24 @@ class Transaction extends Vn\Web\JsonRequest
$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];
$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));
$url = $row['url'];
$url = $row->url;
$postValues = [
'Ds_SignatureVersion' => 'HMAC_SHA256_V1'
,'Ds_MerchantParameters' => $encodedParams
,'Ds_Signature' => $signature
];
return [
'url' => $url
,'params' => $encodedParams
,'signature' => $signature
'url' => $url
,'postValues' => $postValues
];
}
}