Skip to content

Commit

Permalink
Merge branch 'BP-2060-prestashop-plugin-improvments-update' into BP-3…
Browse files Browse the repository at this point in the history
…055-In3-improvements-PrestaShop
  • Loading branch information
vegimcarkaxhija authored Oct 30, 2023
2 parents 3203dd9 + de9c2ae commit 29c0aa4
Show file tree
Hide file tree
Showing 41 changed files with 351 additions and 429 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ on:
push:
branches:
- master
- "prestashop-plugin-vue"
- develop
- 'releases/**'
pull_request:
Expand All @@ -20,4 +19,3 @@ jobs:
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
SONAR_ROOT_CERT: ${{ secrets.SONAR_ROOT_CERT }}
2 changes: 1 addition & 1 deletion api/paymentmethods/belfius/belfius.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ public function __construct()
$this->type = 'belfius';
$this->version = 0;
}
}
}
11 changes: 5 additions & 6 deletions api/paymentmethods/responsefactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ final public static function getResponse($transactionResponse = null)
} elseif (Tools::getValue('brq_primary_service')) {
$paymentmethod = Tools::getValue('brq_primary_service');
}

switch ($paymentmethod) {
case 'IDIN':
return new IdinResponse($transactionResponse);
default:
return new ResponseDefault($transactionResponse);
if($paymentmethod === 'IDIN'){
return new IdinResponse($transactionResponse);
}

return new ResponseDefault($transactionResponse);

}
}
157 changes: 63 additions & 94 deletions buckaroo3.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public function __construct()
$this->bootstrap = true;
$this->module_key = '8d2a2f65a77a8021da5d5ffccc9bbd2b';
$this->ps_versions_compliancy = ['min' => '1', 'max' => _PS_VERSION_];

parent::__construct();

$this->setContainer();

$this->displayName = $this->l('Buckaroo Payments') . ' (v ' . $this->version . ')';
Expand All @@ -65,23 +67,19 @@ public function __construct()
$this->locale = \Tools::getContextLocale($this->context);

$response = ResponseFactory::getResponse();
if ($response) {
if ($response->isValid()) {
if ($response->brq_transaction_type == 'I150') {
$this->displayName = 'Group transaction';
} else {
if ($response->hasSucceeded()) {
$this->displayName = $response->payment_method;
} else {
if (isset($response->status) && $response->status > 0) {
$this->displayName = (new RawPaymentMethodRepository())->getPaymentMethodsLabel($response->payment_method);
} else {
$this->displayName = $this->l('Buckaroo Payments (v 4.0.1)');
}
}
}
if ($response && $response->isValid()) {
if ($response->brq_transaction_type == 'I150') {
$this->displayName = 'Group transaction';
} elseif ($response->hasSucceeded()) {
$this->displayName = $response->payment_method;
} elseif (isset($response->status) && $response->status > 0) {
$this->displayName =
(new RawPaymentMethodRepository())->getPaymentMethodsLabel($response->payment_method);
} else {
$this->displayName = $this->l('Buckaroo Payments (v 4.0.1)');
}
}

if (!Configuration::get('BUCKAROO_MERCHANT_KEY')
|| !Configuration::get('BUCKAROO_SECRET_KEY')
|| !Configuration::get('BUCKAROO_ORDER_STATE_DEFAULT')
Expand Down Expand Up @@ -134,15 +132,10 @@ public function hookDisplayOrderConfirmation(array $params)
{
$order = isset($params['objOrder']) ? $params['objOrder'] : null;
$order = isset($params['order']) ? $params['order'] : $order;
if (!$order) {
return '';
}
$cart = new Cart($order->id_cart);

if (!$cart) {
if (!$order || !($cart = new Cart($order->id_cart))) {
return '';
}

$buckarooFee = $this->getBuckarooFeeByCartId($cart->id);
if (!$buckarooFee) {
return '';
Expand All @@ -153,7 +146,8 @@ public function hookDisplayOrderConfirmation(array $params)

return '<script>
document.addEventListener("DOMContentLoaded", function(){
$(".total-value").before($("<tr><td>Buckaroo Fee</td><td>' . $this->formatPrice($buckarooFee) . '</td></tr>"))
$(".total-value").before(
$("<tr><td>Buckaroo Fee</td><td>' . $this->formatPrice($buckarooFee) . '</td></tr>"))
});
</script>';
}
Expand Down Expand Up @@ -280,7 +274,7 @@ private function isActivated()
$websiteKey = Configuration::get('BUCKAROO_MERCHANT_KEY');
$secretKey = Configuration::get('BUCKAROO_SECRET_KEY');

return $this->checkKeys($websiteKey, $secretKey);
return $this->active && $this->checkKeys($websiteKey, $secretKey);
}

private function checkKeys($websiteKey, $secretKey): bool
Expand All @@ -295,8 +289,8 @@ private function checkKeys($websiteKey, $secretKey): bool

public function hookPaymentOptions($params)
{
if (!$this->active || !$this->isActivated()) {
return;
if (!$this->isActivated()) {
return [];
}

$cookie = new Cookie('ps');
Expand Down Expand Up @@ -339,21 +333,22 @@ public function hookPaymentOptions($params)
}

$phone_afterpay_billing = '';

if (!empty($phone_mobile_billing)) {
$phone_afterpay_billing = $phone_mobile_billing;
}
if (empty($phone_afterpay_billing) && !empty($phone_billing)) {
} elseif (!empty($phone_billing)){
$phone_afterpay_billing = $phone_billing;
}

$address_differ = 0;

if ($cart->id_address_delivery != $cart->id_address_invoice
&& $lastNameShipping == $lastNameBilling
&& $firstNameShipping == $firstNameBilling) {
$address_differ = 2;
} elseif ($cart->id_address_delivery != $cart->id_address_invoice) {
$address_differ = 1;
if($cart->id_address_delivery != $cart->id_address_invoice){
if($lastNameShipping == $lastNameBilling
&& $firstNameShipping == $firstNameBilling){
$address_differ = 2;
}else{
$address_differ = 1;
}
}

$buckarooConfigService = $this->getBuckarooConfigService();
Expand Down Expand Up @@ -405,69 +400,45 @@ public function hookPaymentReturn($params)
if (!$this->active) {
return;
}
if(Tools::getValue('response_received')
|| (Tools::getValue('id_order') && Tools::getValue('success'))){

if (Tools::getValue('response_received')) {
switch (Tools::getValue('response_received')) {
case 'transfer':
$order = new Order(Tools::getValue('id_order'));
$price = $order->getOrdersTotalPaid();
$message = $this->context->cookie->HtmlText;
$this->context->smarty->assign(
[
'is_guest' => ($this->context->customer->is_guest
|| $this->context->customer->id == false),
'order' => $order,
'message' => $message,
'price' => $this->formatPrice($price),
]
);

return $this->display(__FILE__, 'payment_return_redirectsuccess.tpl');
default:
$order = new Order(Tools::getValue('id_order'));
$price = $order->getOrdersTotalPaid();
$this->context->smarty->assign(
[
'is_guest' => ($this->context->customer->is_guest
|| $this->context->customer->id == false),
'order' => $order,
'price' => $this->formatPrice($price),
]
);

return $this->display(__FILE__, 'payment_return_success.tpl');
}
} else {
if (Tools::getValue('id_order') && Tools::getValue('success')) {
$order = new Order(Tools::getValue('id_order'));
if ($order) {
$price = $order->getOrdersTotalPaid();
$this->context->smarty->assign(
[
'is_guest' => ($this->context->customer->is_guest || $this->context->customer->id == false), // phpcs:ignore
'order' => $order,
'price' => $this->formatPrice($price),
]
);

return $this->display(__FILE__, 'payment_return_success.tpl');
} else {
Tools::redirect('index.php?fc=module&module=buckaroo3&controller=error');
exit;
}
} else {
Tools::redirect('index.php?fc=module&module=buckaroo3&controller=error');
exit;
$order = new Order(Tools::getValue('id_order'));
$price = $this->formatPrice($order->getOrdersTotalPaid());
$isGuest = $this->context->customer->is_guest || !$this->context->customer->id;

if(Tools::getValue('response_received') == 'transfer'){

$this->context->smarty->assign(
[
'is_guest' => $isGuest,
'order' => $order,
'price' => $price,
'message' => $this->context->cookie->HtmlText
]
);
return $this->display(__FILE__, 'payment_return_redirectsuccess.tpl');
}
$this->context->smarty->assign(
[
'is_guest' => $isGuest,
'order' => $order,
'price' => $this->formatPrice($price),
]
);
return $this->display(__FILE__, 'payment_return_success.tpl');

}
Tools::redirect('index.php?fc=module&module=buckaroo3&controller=error');
exit;
}

public function hookDisplayHeader()
{

Media::addJsDef([
'buckarooAjaxUrl' => $this->context->link->getModuleLink('buckaroo3', 'ajax'),
'buckarooFees' => '',
'buckarooFees' => $this->getBuckarooFeeService()->getBuckarooFees(),
'buckarooMessages' => [
'validation' => [
'date' => $this->l('Please enter correct birthdate date'),
Expand Down Expand Up @@ -586,16 +557,14 @@ public function isPaymentModeActive($method)
{
$isLive = (int) \Configuration::get(Config::BUCKAROO_TEST);
$configArray = $this->getBuckarooConfigService()->getConfigArrayForMethod($method);
if ($configArray === null) {
return false;
}

if ($isLive === 0) {
return isset($configArray['mode']) && $configArray['mode'] === 'test';
} elseif ($isLive === 1) {
return isset($configArray['mode']) && $configArray['mode'] === 'live';
if (!empty($configArray) && isset($configArray['mode'])) {
if ($isLive === 0) {
return $configArray['mode'] === 'test';
} elseif ($isLive === 1) {
return $configArray['mode'] === 'live';
}
}

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/IssuersIdeal.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private function getCacheIssuers()
{
$issuersString = \Configuration::get(self::CACHE_ISSUERS_KEY);
if (!is_string($issuersString)) {
return;
return null;
}

return json_decode($issuersString, true);
Expand Down
2 changes: 1 addition & 1 deletion classes/IssuersPayByBank.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function getSelectedIssuerLogo()
$selectedIssuer = array_filter($issuers, function ($issuer) {
return $issuer['selected'];
});
if (count($selectedIssuer) > 0) {
if (!empty($selectedIssuer)) {
$selectedIssuer = reset($selectedIssuer);

return '../../PayByBank issuers/' . $selectedIssuer['logo'];
Expand Down
9 changes: 3 additions & 6 deletions controllers/admin/AdminBuckarooController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
*/
class AdminBuckarooController extends ModuleAdminController
{
public function __construct()
{
parent::__construct();
}

public function initContent()
{
$configure = $this->context->link->getAdminLink('AdminModules', false) . '&configure=' . $this->module->name . '&tab_module=' . $this->module->tab . '&module_name=' . $this->module->name . '&token=' . Tools::getAdminTokenLite('AdminModules');
$configure = $this->context->link->getAdminLink('AdminModules', false)
. '&configure=' . $this->module->name . '&tab_module=' . $this->module->tab
. '&module_name=' . $this->module->name . '&token=' . Tools::getAdminTokenLite('AdminModules');
Tools::redirectAdmin($configure);
exit;
}
Expand Down
6 changes: 0 additions & 6 deletions controllers/admin/AdminBuckaroologController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@ public function __construct()
$this->bootstrap = true;
parent::__construct();
}

public function display()
{
parent::display();
}

public function renderList()
{
$file = dirname(__FILE__) . '/../../api/log/report_log.txt';
Expand Down
4 changes: 2 additions & 2 deletions controllers/admin/AdminRefundController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ public function refund(Request $request)
$orderId = $request->get('orderId');
$refundAmount = $request->get('refundAmount');

if (!is_scalar($orderId) || $orderId === null) {
if (!is_scalar($orderId)) {
return $this->renderError('Invalid value for `orderId`');
}

if (!is_scalar($refundAmount) || $refundAmount === null) {
if (!is_scalar($refundAmount)) {
return $this->renderError('Invalid value for `refundAmount`');
}

Expand Down
Loading

0 comments on commit 29c0aa4

Please sign in to comment.