Skip to content

Commit

Permalink
release: module update from ifthenpay/dev_prestashop_8 (ifthenpay/dev…
Browse files Browse the repository at this point in the history
  • Loading branch information
joaocouto-ifthenpay committed Apr 28, 2023
1 parent 04ab6a6 commit d2526c3
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 225 deletions.
1 change: 0 additions & 1 deletion ifthenpay/classes/Admin/Payments/CCardAdminRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
exit;
}

use PrestaShop\Module\Ifthenpay\Utility\Utility;
use PrestaShop\Module\Ifthenpay\Base\Payments\CCardBase;
use PrestaShop\Module\Ifthenpay\Contracts\Admin\AdminRefundInterface;

Expand Down
1 change: 0 additions & 1 deletion ifthenpay/classes/Admin/Payments/MbwayAdminRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
exit;
}

use PrestaShop\Module\Ifthenpay\Utility\Utility;
use PrestaShop\Module\Ifthenpay\Base\Payments\MbwayBase;
use PrestaShop\Module\Ifthenpay\Contracts\Admin\AdminRefundInterface;

Expand Down
47 changes: 0 additions & 47 deletions ifthenpay/classes/Admin/Payments/PayshopAdminRefund.php

This file was deleted.

8 changes: 2 additions & 6 deletions ifthenpay/classes/Base/PaymentBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use PrestaShop\Module\Ifthenpay\Factory\Builder\BuilderFactory;
use PrestaShop\Module\Ifthenpay\Factory\Payment\GatewayFactory;
use PrestaShop\Module\Ifthenpay\Factory\Models\IfthenpayModelFactory;
use PrestaShop\Module\Ifthenpay\Utility\Utility;

abstract class PaymentBase
{
Expand All @@ -58,7 +59,7 @@ public function __construct(
$this->emailDefaultData = $emailDefaultData;
$this->ifthenpayGateway = GatewayFactory::build('gateway');
$this->ifthenpayModule = $ifthenpayModule;
$this->securityCode = $this->GenerateSecurityCode();
$this->securityCode = Utility::GenerateSecurityCode();
}

public function setPaymentModel($type, $id = null)
Expand Down Expand Up @@ -109,9 +110,4 @@ public function getPaymentDataFromDb()
return $this->paymentDataFromDb;
}

protected function GenerateSecurityCode() {
$rnd = rand(10000, 99999);
$code = strval($rnd);
return $code;
}
}
1 change: 0 additions & 1 deletion ifthenpay/classes/Base/Payments/PayshopBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,5 @@ protected function setEmailVariables()
}

$this->emailDefaultData['{validade}'] = $validade;
$this->emailDefaultData['{securityCode}'] = $this->securityCode;
}
}
8 changes: 3 additions & 5 deletions ifthenpay/classes/Factory/Admin/AdminRefundFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
}

use PrestaShop\Module\Ifthenpay\Admin\Payments\MbwayAdminRefund;
use PrestaShop\Module\Ifthenpay\Admin\Payments\PayshopAdminRefund;
use PrestaShop\Module\Ifthenpay\Admin\Payments\CCardAdminRefund;

class AdminRefundFactory
{
Expand All @@ -46,11 +46,9 @@ public static function build(
case 'mbway':
return new MbwayAdminRefund($ifthenpayModule, $paymentDefaultData, $smartyDefaultData, $emailDefaultData);
case 'ccard':
return new MbwayAdminRefund($ifthenpayModule, $paymentDefaultData, $smartyDefaultData, $emailDefaultData);
case 'payshop':
return new PayshopAdminRefund($ifthenpayModule, $paymentDefaultData, $smartyDefaultData, $emailDefaultData);
return new CCardAdminRefund($ifthenpayModule, $paymentDefaultData, $smartyDefaultData, $emailDefaultData);
default:
throw new \Exception('Unknown Admin Remember class');
throw new \Exception('Unknown Admin Refund class');
}
}
}
2 changes: 1 addition & 1 deletion ifthenpay/classes/Utility/Utility.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public static function dataToString($data)
return $strData;
}

public function GenerateSecurityCode() {
public static function GenerateSecurityCode() {
$rnd = rand(10000, 99999);
$code = strval($rnd);
return $code;
Expand Down
5 changes: 2 additions & 3 deletions ifthenpay/controllers/admin/refund.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,16 @@ public function postProcess()

$response = IfthenpayStrategyFactory::build('ifthenpayAdminRefund', $order, $this->module)->execute();
IfthenpayLogProcess::addLog('Refund notification sent with success', IfthenpayLogProcess::INFO, $order->id);
// Utility::setPrestashopCookie('success', $this->module->l('Refund notification sent with success!', pathinfo(__FILE__)['filename']));

// Return Security Code to AJAX success
/* Return Security Code to AJAX success */
$data = array('code' => $response);
die(json_encode($data));

} catch (Exception $th) {
IfthenpayLogProcess::addLog('Error sending refund notification - ' . $th->getMessage(), IfthenpayLogProcess::ERROR, $order->id);
Utility::setPrestashopCookie('error', $this->module->l('Error sending refund notification!', pathinfo(__FILE__)['filename']));
}

Utility::redirectAdminOrder($order);
}
}
24 changes: 14 additions & 10 deletions ifthenpay/ifthenpay.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -927,12 +927,17 @@ public function hookdisplayAdminOrder($params)
$this,
$message
)->execute();

$this->smarty->assign($ifthenpayAdminOrder->getSmartyVariables()->toArray());
$this->smarty->assign('paymentMethods', (array) unserialize($this->ifthenpayConfig['IFTHENPAY_USER_PAYMENT_METHODS']));

// commented out since it would quickly add records to table unnecessarily
// IfthenpayLogProcess::addLog('Payment order successfully withdrawn (hookdisplayAdminOrder).', IfthenpayLogProcess::INFO, $params['id_order']);
$this->smarty->assign('refundNotAvailable', $this->l('The partial refund feature is not available for '));
$this->smarty->assign('confirmRefund', $this->l('Are you sure you want to make a refund? If so, you will receive a security code via email.'));
$this->smarty->assign('refundNotification', $this->l('Refund notification sent with success!'));
$this->smarty->assign('promptCode', $this->l('Please enter the security code from the email sent:'));
$this->smarty->assign('timeExceeded', $this->l('the validation time has been exceeded!'));
$this->smarty->assign('invalidCode', $this->l('Invalid security code'));
$this->smarty->assign('validationSuccessful', $this->l('Security code was inserted successfully! You can now proceed with the refund.'));

return $this->display(__FILE__, 'admin.tpl');

} catch (\Throwable $th) {
Expand Down Expand Up @@ -1100,31 +1105,30 @@ public function hookActionProductCancel($params)
$router = $this->get('router');
$paymentData = IfthenpayModelFactory::build($payment)->getByOrderId((string) $orderID);

if ($payment == 'payshop' || $payment == 'multibanco') {
if ($payment == 'multibanco' || $payment == 'payshop') {

$type = 'warning';
$msg = 'It is not possible to proceed with the refund through '.$payment;
$msg = $this->l('The partial refund feature is not available for ').$payment;

IfthenpayLogProcess::addLog($msg, IfthenpayLogProcess::WARNING, $orderID);
$this->get('session')->getFlashBag()->add($type, $msg);
Tools::redirectAdmin($router->generate('admin_orders_view', ['orderId'=> $orderID]));
}

$ifthenpayGateway = GatewayFactory::build('gateway');

$body = [
'backofficekey' => $this->ifthenpayConfig['IFTHENPAY_BACKOFFICE_KEY'],
'requestId' => $paymentData['transaction_id'],
'amount' => $params['cancel_amount']
];


$ifthenpayGateway = GatewayFactory::build('gateway');
$response = $ifthenpayGateway->refund($body);

if($response['Code'] != 1) {

$type = 'error';
IfthenpayLogProcess::addLog($response['Message'], IfthenpayLogProcess::ERROR, $orderID);
$this->get('session')->getFlashBag()->add($type, $response['Message']);
$this->get('session')->getFlashBag()->add($type, $this->l('An error occurred during the request to the Ifthenpay API Gateway. We were unable to refund the intended payment.'));
Tools::redirectAdmin($router->generate('admin_orders_view', ['orderId'=> $orderID]));
}
else {
Expand Down
Loading

0 comments on commit d2526c3

Please sign in to comment.