Skip to content

Commit

Permalink
Merge branch 'master' into feature/PLUG-2946
Browse files Browse the repository at this point in the history
  • Loading branch information
woutse authored Dec 7, 2023
2 parents 67722df + d65a96c commit dcda504
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 25 deletions.
6 changes: 6 additions & 0 deletions paynlpaymentmethods/nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,10 @@
$_MODULE['<{paynlpaymentmethods}prestashop>paynlpaymentmethods_1d6ac6ba0c92bee720404ac8f441ca2d'] = 'In het invoerveld \'Failover gateway\' kunt u uw failover gateway instellen.';
$_MODULE['<{paynlpaymentmethods}prestashop>paynlpaymentmethods_e916b6d1f559188cfaa2fc0bbe61d750'] = 'Pay. verbinding mislukt';
$_MODULE['<{paynlpaymentmethods}prestashop>paynlpaymentmethods_a2d07836b692b9f4153f7f399307f629'] = 'Pay. niet verbonden';
$_MODULE['<{paynlpaymentmethods}prestashop>paynlpaymentmethods_5b8d9b6e50b6175bb993d59012749d19'] = 'Pay. Kan gedeeltelijke terugbetaling niet verwerken. Probeer het later opnieuw.';
$_MODULE['<{paynlpaymentmethods}prestashop>paynlpaymentmethods_a06edbeae74c06123799e7f0a6efb2b0'] = 'Pay. succesvol terugbetaald';
$_MODULE['<{paynlpaymentmethods}prestashop>paynlpaymentmethods_5f14b7d5ab542d6b7247465c0b56862c'] = '(Terugbetalingen kunnen niet snel achter elkaar worden gedaan)';
$_MODULE['<{paynlpaymentmethods}prestashop>paynlpaymentmethods_f51ea2cb1b551cd5a0d1cb60250cfed5'] = 'Pay. kon de gedeeltelijke terugbetaling niet verwerken. Controleer de status van uw bestelling in de Pay. admin.';
$_MODULE['<{paynlpaymentmethods}prestashop>paynlpaymentmethods_cc61945cbbf46721a053467c395c666f'] = 'Terugbetaald';

// @codingStandardsIgnoreEnd
64 changes: 40 additions & 24 deletions paynlpaymentmethods/paynlpaymentmethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,12 @@ public function __construct()
$this->registerHook('displayPaymentReturn');
}

if (!$this->isRegisteredInHook('actionProductCancel')) {
$this->registerHook('actionProductCancel');
if ($this->isRegisteredInHook('actionProductCancel')) {
$this->unregisterHook('actionProductCancel');
}

if (!$this->isRegisteredInHook('actionOrderSlipAdd')) {
$this->registerHook('actionOrderSlipAdd');
}
}

Expand Down Expand Up @@ -228,6 +232,7 @@ public function hookDisplayAdminOrder($params)
$arrTransactionDetails = $transaction->getData();
$payOrderAmount = $transaction->getPaidAmount();
$status = $arrTransactionDetails['paymentDetails']['stateName'];
$amoutRefunded = $arrTransactionDetails['paymentDetails']['refundAmount'] / 100;
$profileId = $transaction->getPaymentProfileId();
$methodName = PaymentMethod::getName($transactionId, $profileId);
$showCaptureButton = $transaction->isAuthorized();
Expand All @@ -241,14 +246,20 @@ public function hookDisplayAdminOrder($params)

$amountFormatted = number_format($order->total_paid, 2, ',', '.');
$amountPayFormatted = number_format($payOrderAmount, 2, ',', '.');
$amountFormattedRefunded = number_format($amoutRefunded, 2, ',', '.');
$amountFormattedRefundable = number_format($order->total_paid - $amoutRefunded, 2, ',', '.');

$this->context->smarty->assign(array(
'lang' => $this->getMultiLang(),
'this_version' => $this->version,
'PrestaOrderId' => $orderId,
'amountFormatted' => $amountFormatted,
'amountPayFormatted' => $amountPayFormatted,
'amountFormattedRefunded' => $amountFormattedRefunded,
'amountFormattedRefundable' => $amountFormattedRefundable,
'amount' => $order->total_paid,
'currency' => $currency,
'amoutRefunded' => $amoutRefunded,
'currency' => $currency->iso_code,
'pay_orderid' => $transactionId,
'status' => $status,
'method' => $methodName,
Expand Down Expand Up @@ -322,35 +333,39 @@ public function hookActionOrderStatusPostUpdate($params)
* @param array $params
* @return void
*/
public function hookActionProductCancel($params)
public function hookActionOrderSlipAdd(array $params)
{
if ($params['action'] == CancellationActionType::PARTIAL_REFUND && $params['order']->module == 'paynlpaymentmethods') {
if ($params['order']->module == 'paynlpaymentmethods') {
try {
$cartId = $params['order']->id_cart ?? null;
$orderId = Order::getIdByCartId($cartId);
$order = new Order($orderId);

$order = $params['order'];
$productList = $params['productList'];
$orderPayments = $order->getOrderPayments();
$orderPayment = reset($orderPayments);

if (!empty($orderPayment)) {
$currencyId = $orderPayment->id_currency;
$currency = new Currency($currencyId);
$strCurrency = $currency->iso_code;

$transactionId = $orderPayment->transaction_id ?? null;
$refundAmount = $params['cancel_amount'] ?? null;

PayHelper::sdkLogin();
\Paynl\Transaction::refund($transactionId, $refundAmount, null, null, null, $strCurrency);

$this->payLog('Partial Refund', 'Partial Refund (' . $refundAmount . ') success ', $transactionId);
} else {
throw new Exception('Order has no Payments.');
$refundAmount = 0;
foreach ($productList as $key => $product) {
if (!empty($product['amount']) && $product['amount'] > 0) {
$refundAmount += $product['amount'];
}
}
if ($refundAmount > 0) {
$currencyId = $orderPayment->id_currency;
$currency = new Currency($currencyId);
$strCurrency = $currency->iso_code;
$transactionId = $orderPayment->transaction_id ?? null;
PayHelper::sdkLogin();
\Paynl\Transaction::refund($transactionId, $refundAmount, null, null, null, $strCurrency);
$this->payLog('Partial Refund', 'Partial Refund (' . $refundAmount . ') success ', $transactionId);
$this->get('session')->getFlashBag()->add('success', $this->l('Pay. successfully refunded ') . '(' . $refundAmount . ').');
}
}
} catch (Exception $e) {
$this->payLog('Partial Refund', 'Partial Refund failed (' . $e->getMessage() . ') ');
throw new Exception($this->l('Pay. Could not process Partial Refund please try again later.'));
$friendlyMessage = null;
if ($e->getMessage() == 'PAY-14 - Refund too fast ') {
$friendlyMessage = $this->l('(Refunds can\'t be done in quick succession)');
}
$this->get('session')->getFlashBag()->add('error', $this->l('Pay. could not process partial refund, please check the status of your order in the Pay. admin. ') . $friendlyMessage);
}
}
return;
Expand All @@ -376,6 +391,7 @@ private function getMultiLang()
$lang['capturing'] = $this->l('Processing');
$lang['currency'] = $this->l('Currency');
$lang['amount'] = $this->l('Amount');
$lang['refunded'] = $this->l('Refunded');
$lang['invalidamount'] = $this->l('Invalid amount');
$lang['succesfully_refunded'] = $this->l('Succesfully refunded');
$lang['succesfully_captured'] = $this->l('Succesfully captured');
Expand Down
Binary file modified paynlpaymentmethods/views/images/252.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paynlpaymentmethods/views/images/288.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paynlpaymentmethods/views/images/291.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paynlpaymentmethods/views/images/294.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paynlpaymentmethods/views/images/297.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added paynlpaymentmethods/views/images/300.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion paynlpaymentmethods/views/templates/hook/payorder.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@
<div class="labelvalue">{$currency} {$amountFormatted}</div>
<div class="label">{$lang.amount} (PAY.)</div>
<div class="labelvalue">EUR {$amountPayFormatted}</div>
<div class="label">{$lang.refunded} (PAY.)</div>
<div class="labelvalue">EUR {$amountFormattedRefunded}</div>
</div>
<div>
<hr>
{if $showRefundButton eq true}
<div class="payOption" id="refund-div" style="display: inline-block">
<div class="label">{$lang.amount_to_refund} ({$currency}) :
<input type="text" placeholder="0,00" value="{$amountFormatted}" id="pay-refund-amount"
<input type="text" placeholder="0,00" value="{$amountFormattedRefundable}" id="pay-refund-amount"
class="fixed-width-sm" style="display: inline;margin-right:10px"/>
</div>
<button type="button" id="pay-refund-button" class="btn btn-danger" style="display: inline">{$lang.refund_button}</button>
Expand Down

0 comments on commit dcda504

Please sign in to comment.