Skip to content

Commit

Permalink
fixed some issues with images, created some more services
Browse files Browse the repository at this point in the history
  • Loading branch information
vegimcarkaxhija committed Oct 26, 2023
1 parent fc9b4c5 commit 6a137d2
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 256 deletions.
4 changes: 1 addition & 3 deletions api/paymentmethods/idin/idin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/

use Buckaroo\PrestaShop\Classes\Config;

require_once dirname(__FILE__) . '/../paymentmethod.php';
require_once dirname(__FILE__) . '/../paymentmethod.php';

class Idin extends PaymentMethod
{
Expand Down
149 changes: 23 additions & 126 deletions buckaroo3.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,29 @@
if (!defined('_PS_VERSION_')) {
exit;
}
require_once _PS_ROOT_DIR_ . '/modules/buckaroo3/vendor/autoload.php';
require_once _PS_MODULE_DIR_ . 'buckaroo3/vendor/autoload.php';
require_once _PS_MODULE_DIR_ . 'buckaroo3/api/paymentmethods/responsefactory.php';
require_once _PS_MODULE_DIR_ . 'buckaroo3/controllers/front/common.php';
include_once _PS_MODULE_DIR_ . 'buckaroo3/library/logger.php';

use Buckaroo\BuckarooClient;
use Buckaroo\PrestaShop\Classes\CapayableIn3;
use Buckaroo\PrestaShop\Classes\IssuersIdeal;
use Buckaroo\PrestaShop\Classes\IssuersPayByBank;
use Buckaroo\PrestaShop\Classes\JWTAuth;
use Buckaroo\PrestaShop\Src\Config\Config;
use Buckaroo\PrestaShop\Src\Entity\BkConfiguration;
use Buckaroo\PrestaShop\Src\Entity\BkCountries;
use Buckaroo\PrestaShop\Src\Entity\BkOrdering;
use Buckaroo\PrestaShop\Src\Entity\BkPaymentMethods;
use Buckaroo\PrestaShop\Src\Form\Modifier\ProductFormModifier;
use Buckaroo\PrestaShop\Src\Install\DatabaseTableInstaller;
use Buckaroo\PrestaShop\Src\Install\DatabaseTableUninstaller;
use Buckaroo\PrestaShop\Src\Install\IdinColumnsRemover;
use Buckaroo\PrestaShop\Src\Install\Installer;
use Buckaroo\PrestaShop\Src\Install\Uninstaller;
use Buckaroo\PrestaShop\Src\Refund\Settings as RefundSettings;
use Buckaroo\PrestaShop\Src\Repository\BkConfigurationRepositoryInterface;
use Buckaroo\PrestaShop\Src\Repository\BkCountriesRepositoryInterface;
use Buckaroo\PrestaShop\Src\Repository\BkPaymentMethodRepositoryInterface;
use Buckaroo\PrestaShop\Src\Repository\RawPaymentMethodRepository;
use Buckaroo\PrestaShop\Src\Service\BuckarooConfigService;
use Buckaroo\PrestaShop\Src\Service\BuckarooCountriesService;
use Buckaroo\PrestaShop\Src\Service\BuckarooFeeService;
use Buckaroo\PrestaShop\Src\Service\BuckarooIdinService;
use Buckaroo\PrestaShop\Src\Service\BuckarooPaymentService;
use Buckaroo\PrestaShop\Src\Service\BuckarooIdinService;
use PrestaShop\PrestaShop\Core\Localization\Exception\LocalizationException;

class Buckaroo3 extends PaymentModule
{
public $buckarooPaymentService;
public $buckarooFeeService;
public $buckarooConfigService;
public $buckarooCountriesService;
public $bkOrderingRepository;
private $issuersPayByBank;
private $issuersCreditCard;
private $capayableIn3;
public $symContainer;
public $entityManager;
public $logger;
private $locale;

Expand Down Expand Up @@ -288,27 +266,15 @@ public function getContent()
$userProvider->getUsername()
)->getValue();
$this->context->smarty->assign([
'pathApp' => $this->_path . 'views/js/buckaroo.vue.js',
'baseUrl' => explode("?",$this->context->link->getAdminLink(AdminDashboard::class))[0],
'pathApp' => $this->_path . 'views/js/buckaroo.vue.js?2135132',
'baseUrl' => $this->context->shop->getBaseURL(true),
'adminUrl' => explode("?",$this->context->link->getAdminLink(AdminDashboard::class))[0],
'token' => $token,
]);

return $this->context->smarty->fetch('module:buckaroo3/views/templates/admin/app.tpl');
}

private function generateToken($jwt)
{
$data = [];

if ($this->context->employee->isLoggedBack()) {
$data = ['employee_id' => $this->context->employee->id];
} elseif ($this->context->customer->isLogged()) {
$data = ['user_id' => $this->context->customer->id];
}

return $jwt->encode($data);
}

private function isActivated()
{
$websiteKey = Configuration::get('BUCKAROO_MERCHANT_KEY');
Expand Down Expand Up @@ -390,29 +356,9 @@ public function hookPaymentOptions($params)
$address_differ = 1;
}

$this->issuersPayByBank = new IssuersPayByBank();

$this->issuersCreditCard = $this->getBuckarooConfigService()->getActiveCreditCards();

$this->capayableIn3 = new CapayableIn3();

$this->entityManager = $this->get('doctrine.orm.entity_manager');

$bkPaymentMethodRepository = $this->getRepository(BkPaymentMethods::class, BkPaymentMethodRepositoryInterface::class);

$bkOrderingRepository = $this->getBuckarooOrderingRepository();
$buckarooConfigService = $this->getBuckarooConfigService();

$this->buckarooPaymentService = new BuckarooPaymentService(
$this,
$this->getBuckarooConfigService(),
$this->issuersPayByBank,
$this->logger,
$this->context,
$this->capayableIn3,
$this->getBuckarooFeeService(),
$bkOrderingRepository,
$bkPaymentMethodRepository
);
$buckarooPaymentService = $this->symContainer->get('buckaroo.config.api.payment.service');

try {
$this->context->smarty->assign(
Expand All @@ -431,31 +377,22 @@ public function hookPaymentOptions($params)
'phone_afterpay_billing' => $phone_afterpay_billing,
'total' => $cart->getOrderTotal(true, 3),
'country' => Country::getIsoById(Tools::getCountry()),
'afterpay_show_coc' => $this->buckarooPaymentService->showAfterpayCoc($cart),
'billink_show_coc' => $this->buckarooPaymentService->showBillinkCoc($cart),
'afterpay_show_coc' => $buckarooPaymentService->showAfterpayCoc($cart),
'billink_show_coc' => $buckarooPaymentService->showBillinkCoc($cart),
'idealIssuers' => (new IssuersIdeal())->get(),
'idealDisplayMode' => $this->buckarooConfigService->getConfigValue('ideal', 'display_type'),
'paybybankIssuers' => $this->issuersPayByBank->getIssuerList(),
'payByBankDisplayMode' => $this->buckarooConfigService->getConfigValue('paybybank', 'display_type'),
'creditcardIssuers' => $this->issuersCreditCard,
'creditCardDisplayMode' => $this->buckarooConfigService->getConfigValue('creditcard', 'display_type'),
'in3Method' => (new CapayableIn3())->getMethod(),
'idealDisplayMode' => $buckarooConfigService->getConfigValue('ideal', 'display_type'),
'paybybankIssuers' => (new IssuersPayByBank)->getIssuerList(),
'payByBankDisplayMode' => $buckarooConfigService->getConfigValue('paybybank', 'display_type'),
'creditcardIssuers' => $buckarooConfigService->getActiveCreditCards(),
'creditCardDisplayMode' => $buckarooConfigService->getConfigValue('creditcard', 'display_type'),
'in3Method' => $this->get('buckaroo.classes.issuers.capayableIn3')->getMethod(),
]
);
} catch (Exception $e) {
$this->logger->logError('Buckaroo3::hookPaymentOptions - ' . $e->getMessage());
}

return $this->buckarooPaymentService->getPaymentOptions($cart);
}

public function getEntityManager()
{
if (!$this->entityManager) {
$this->entityManager = $this->symContainer->get('doctrine.orm.entity_manager');
}

return $this->entityManager;
return $buckarooPaymentService->getPaymentOptions($cart);
}

/**
Expand Down Expand Up @@ -527,11 +464,10 @@ public function hookPaymentReturn($params)

public function hookDisplayHeader()
{
$buckarooFeeService = $this->getBuckarooFeeService();

Media::addJsDef([
'buckarooAjaxUrl' => $this->context->link->getModuleLink('buckaroo3', 'ajax'),
'buckarooFees' => $buckarooFeeService->getBuckarooFees(),
'buckarooFees' => '',
'buckarooMessages' => [
'validation' => [
'date' => $this->l('Please enter correct birthdate date'),
Expand Down Expand Up @@ -649,7 +585,7 @@ public function hookDisplayPDFInvoice($params)
public function isPaymentModeActive($method)
{
$isLive = (int) \Configuration::get(Config::BUCKAROO_TEST);
$configArray = $this->buckarooConfigService->getConfigArrayForMethod($method);
$configArray = $this->getBuckarooConfigService()->getConfigArrayForMethod($method);
if ($configArray === null) {
return false;
}
Expand All @@ -665,13 +601,11 @@ public function isPaymentModeActive($method)

public function isIdinProductBoxShow($params)
{
$buckarooConfigService = $this->getBuckarooConfigService();

if (!$this->isPaymentModeActive('idin')) {
return false;
}

switch ($buckarooConfigService->getConfigValue('idin', 'display_mode')) {
switch ($this->getBuckarooConfigService()->getConfigValue('idin', 'display_mode')) {
case 'product':
return $this->isProductBuckarooIdinEnabled($params['product']->id);
case 'global':
Expand All @@ -691,13 +625,12 @@ private function isProductBuckarooIdinEnabled($productId)

public function isIdinCheckout($cart)
{
$buckarooConfigService = $this->getBuckarooConfigService();

if (!$this->isPaymentModeActive('idin')) {
return false;
}

switch ($buckarooConfigService->getConfigValue('idin', 'display_mode')) {
switch ($this->getBuckarooConfigService()->getConfigValue('idin', 'display_mode')) {
case 'product':
foreach ($cart->getProducts(true) as $value) {
return $this->isProductBuckarooIdinEnabled($value['id_product']);
Expand All @@ -712,42 +645,17 @@ public function isIdinCheckout($cart)
return false;
}

public function getBuckarooCountriesService()
{
if (!isset($this->buckarooCountriesService)) {
$bkCountriesRepository = $this->getRepository(BkCountries::class, BkCountriesRepositoryInterface::class);
$this->buckarooCountriesService = new BuckarooCountriesService($bkCountriesRepository);
}

return $this->buckarooCountriesService;
}

public function getBuckarooOrderingRepository()
{
if (!isset($this->bkOrderingRepository)) {
$this->bkOrderingRepository = $this->getEntityManager()->getRepository(BkOrdering::class);
}

return $this->bkOrderingRepository;
}

public function getBuckarooConfigService()
{
return $this->get('buckaroo.config.api.config.service');
return $this->symContainer->get('buckaroo.config.api.config.service');
}

public function getBuckarooFeeService()
{
if (!isset($this->buckarooFeeService)) {
$bkPaymentMethodRepository = $this->getRepository(BkPaymentMethods::class, BkPaymentMethodRepositoryInterface::class);
$bkConfigurationRepository = $this->getRepository(BkConfiguration::class, BkConfigurationRepositoryInterface::class);

$this->buckarooFeeService = new BuckarooFeeService($bkConfigurationRepository, $bkPaymentMethodRepository, $this->logger);
}

return $this->buckarooFeeService;
return $this->symContainer->get('buckaroo.config.api.fee.service');
}


public function hookDisplayProductExtraContent($params)
{
if ($this->isIdinProductBoxShow($params)) {
Expand Down Expand Up @@ -803,17 +711,6 @@ private function updateProductFormHandler(array $params)
}
}

private function getRepository($class, $expectedInterface = null)
{
$repository = $this->getEntityManager()->getRepository($class);

if ($expectedInterface && !$repository instanceof $expectedInterface) {
throw new \RuntimeException("The {$class} repository must implement {$expectedInterface}.");
}

return $repository;
}

private function setContainer()
{
global $kernel;
Expand Down
14 changes: 3 additions & 11 deletions classes/CapayableIn3.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,19 @@
*/

namespace Buckaroo\PrestaShop\Classes;

use Buckaroo\PrestaShop\Src\Service\BuckarooConfigService;

class CapayableIn3
{
/**
* @var BuckarooConfigService
*/
protected BuckarooConfigService $buckarooConfigService;
protected $apiVersion;
protected $paymentLogo;
public const VERSION_V2 = 'V2';
public const LOGO_IN3_IDEAL = 'in3_ideal';
public const LOGO_IN3_IDEAL_FILENAME = 'In3_ideal.svg?v1';
public const LOGO_DEFAULT = 'In3.svg?v';

public function __construct()
public function __construct($buckarooConfigService)
{
$this->buckarooConfigService = \Module::getInstanceByName('buckaroo3')->getBuckarooConfigService();
$this->apiVersion = $this->buckarooConfigService->getConfigValue('in3', 'version');
$this->paymentLogo = $this->buckarooConfigService->getConfigValue('in3', 'payment_logo');
$this->apiVersion = $buckarooConfigService->getConfigValue('in3', 'version');
$this->paymentLogo = $buckarooConfigService->getConfigValue('in3', 'payment_logo');
}

public function isV3(): bool
Expand Down
44 changes: 0 additions & 44 deletions classes/JWTAuth.php

This file was deleted.

3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
],
"require": {
"php": ">=7.4",
"buckaroo/sdk": "^1.8.0",
"firebase/php-jwt": "^6.8"
"buckaroo/sdk": "^1.8.0"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 6a137d2

Please sign in to comment.