Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,90 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Core\PayPal\Order\Request\ValueObject\CreatePayPalOrderRequest;
use PsCheckout\Infrastructure\Adapter\ContextInterface;
class AddProductToCartAction implements AddProductToCartActionInterface
{
/** @var ContextInterface */
private $context;
public function __construct(
ContextInterface $context
) {
$this->context = $context;
}
/**
* {@inheritDoc}
*/
public function execute(CreatePayPalOrderRequest $requestData)
{
try {
$cart = $this->createCartInstance();
} catch (\Exception $exception) {
throw new PsCheckoutException('Failed to create cart instance');
}
if (!$cart->updateQty(
$requestData->getQuantityWanted(),
$requestData->getIdProduct(),
!$requestData->getIdProductAttribute() ? null : $requestData->getIdProductAttribute(),
!$requestData->getIdCustomization() ? false : $requestData->getIdCustomization(),
'up'
)) {
$cart->delete();
throw new PsCheckoutException('Failed to add product to cart');
}
try {
$this->context->setCurrentCart($cart);
} catch (\Exception $exception) {
$cart->delete();
throw new PsCheckoutException('Failed to update cart context');
}
}
/**
* @throws \Throwable
*/
private function createCartInstance(): \Cart
{
$existingCart = $this->context->getCart();
if ($existingCart && (int) $existingCart->id) {
return $existingCart;
}
$cart = new \Cart();
$cart->id_currency = $this->context->getCurrency()->id;
$cart->id_lang = $this->context->getLanguage()->id;
$cart->add();
return $cart;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use PsCheckout\Core\PayPal\Order\Request\ValueObject\CreatePayPalOrderRequest;
interface AddProductToCartActionInterface
{
/**
* @param CreatePayPalOrderRequest $requestData
*
* @return void
*/
public function execute(CreatePayPalOrderRequest $requestData);
}

View File

@@ -0,0 +1,141 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use Address;
use Country;
use Exception;
use PsCheckout\Core\Customer\Request\ValueObject\ExpressCheckoutRequest;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Infrastructure\Adapter\ContextInterface;
use PsCheckout\Infrastructure\Adapter\CountryInterface;
use PsCheckout\Infrastructure\Repository\AddressRepositoryInterface;
use PsCheckout\Infrastructure\Repository\CountryRepositoryInterface;
use PsCheckout\Utility\Payload\PaypalCountryCodeUtility;
class CreateOrUpdateAddressAction implements CreateOrUpdateAddressActionInterface
{
/**
* @var ContextInterface
*/
private $context;
/**
* @var CountryInterface
*/
private $country;
/**
* @var CountryRepositoryInterface
*/
private $countryRepository;
/**
* @var AddressRepositoryInterface
*/
private $addressRepository;
public function __construct(
ContextInterface $context,
CountryInterface $country,
CountryRepositoryInterface $countryRepository,
AddressRepositoryInterface $addressRepository
) {
$this->context = $context;
$this->country = $country;
$this->countryRepository = $countryRepository;
$this->addressRepository = $addressRepository;
}
/**
* {@inheritDoc}
*/
public function execute(ExpressCheckoutRequest $expressCheckoutRequest)
{
if (!$expressCheckoutRequest->getShippingAddress()) {
return false;
}
// check if country is available for delivery
$shopIsoCode = PaypalCountryCodeUtility::getShopIsoCode($expressCheckoutRequest->getShippingCountryCode());
$idCountry = $this->country->getIdByIsoCode($shopIsoCode);
$idState = 0;
$country = new Country((int) $idCountry, null, (int) $this->context->getShop()->id);
if (!$country->id
|| !$country->active
|| !$country->isAssociatedToShop((int) $this->context->getShop()->id)
|| $this->country->isNeedDniByCountryId($idCountry)
) {
return false;
}
if ($country->contains_states) {
$idState = $this->countryRepository->getStateId((int) $idCountry, $expressCheckoutRequest->getShippingState());
}
// check if a PayPal address already exist for the customer and not used
$paypalAddressAlias = 'Paypal ' . $expressCheckoutRequest->getOrderId();
$paypalAddressId = $this->addressRepository->getAddressIdByAliasAndCustomer($paypalAddressAlias, $this->context->getCustomer()->id);
$paypalAddress = new Address($paypalAddressId);
$isPaypalValidAddressAndNotUsed = $paypalAddress->id && !$paypalAddress->isUsed();
if ($isPaypalValidAddressAndNotUsed) {
$address = $paypalAddress; // if yes, update it with the new address
} else {
$address = new Address(); // otherwise create a new address
}
$address->alias = $paypalAddressAlias;
$address->id_customer = $this->context->getCustomer()->id;
$address->firstname = $expressCheckoutRequest->getPayerFirstName();
$address->lastname = $expressCheckoutRequest->getPayerLastName();
$address->address1 = $expressCheckoutRequest->getShippingStreet();
$address->address2 = $expressCheckoutRequest->getShippingStreet2();
$address->postcode = $expressCheckoutRequest->getShippingPostalCode();
$address->city = $expressCheckoutRequest->getShippingCity();
$address->id_country = $idCountry;
$address->phone = $expressCheckoutRequest->getPayerPhone();
$address->id_state = $idState;
if (!$address->validateFields(false)) {
return false;
}
try {
$address->save();
} catch (Exception $exception) {
throw new PsCheckoutException($exception->getMessage(), PsCheckoutException::PSCHECKOUT_EXPRESS_CHECKOUT_CANNOT_SAVE_ADDRESS, $exception);
}
$cart = $this->context->getCart();
$cart->id_address_delivery = $address->id;
$cart->id_address_invoice = $address->id;
$products = $cart->getProducts();
foreach ($products as $product) {
$cart->setProductAddressDelivery($product['id_product'], $product['id_product_attribute'], $product['id_address_delivery'], $address->id);
}
return $cart->save();
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use PsCheckout\Core\Customer\Request\ValueObject\ExpressCheckoutRequest;
interface CreateOrUpdateAddressActionInterface
{
/**
* @param ExpressCheckoutRequest $expressCheckoutRequest
*
* @return void
*/
public function execute(ExpressCheckoutRequest $expressCheckoutRequest);
}

View File

@@ -0,0 +1,67 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use PsCheckout\Core\Customer\Request\ValueObject\ExpressCheckoutRequest;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
use PsCheckout\Infrastructure\Adapter\ContextInterface;
use PsCheckout\Infrastructure\Adapter\CustomerInterface;
class CustomerAuthenticationAction implements CustomerAuthenticationActionInterface
{
/**
* @var ConfigurationInterface
*/
private $configuration;
/**
* @var CustomerInterface
*/
private $customer;
/**
* @var ContextInterface
*/
private $context;
public function __construct(
ConfigurationInterface $configuration,
CustomerInterface $customer,
ContextInterface $context
) {
$this->configuration = $configuration;
$this->customer = $customer;
$this->context = $context;
}
/**
* @param ExpressCheckoutRequest $expressCheckoutRequest
*
* @return void
*
* @throws PsCheckoutException
*/
public function execute(ExpressCheckoutRequest $expressCheckoutRequest)
{
throw new PsCheckoutException('CustomerAuthenticationAction is deprecated and should not be used anymore.');
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use PsCheckout\Core\Customer\Request\ValueObject\ExpressCheckoutRequest;
interface CustomerAuthenticationActionInterface
{
/**
* @param ExpressCheckoutRequest $expressCheckoutRequest
*
* @return void
*/
public function execute(ExpressCheckoutRequest $expressCheckoutRequest);
}

View File

@@ -0,0 +1,153 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use Cart;
use Contact;
use Customer;
use CustomerMessage;
use CustomerThread;
use Exception;
use PsCheckout\Core\PayPal\Order\Repository\PayPalOrderRepositoryInterface;
use PsCheckout\Infrastructure\Repository\OrderRepositoryInterface;
use PsCheckout\Presentation\TranslatorInterface;
use Tools;
class CustomerNotifyAction implements CustomerNotifyActionInterface
{
/**
* @var PayPalOrderRepositoryInterface
*/
private $payPalOrderRepository;
/**
* @var OrderRepositoryInterface
*/
private $orderRepository;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* @var \Db
*/
private $db;
public function __construct(
PayPalOrderRepositoryInterface $payPalOrderRepository,
OrderRepositoryInterface $orderRepository,
TranslatorInterface $translator,
\Db $db
) {
$this->payPalOrderRepository = $payPalOrderRepository;
$this->orderRepository = $orderRepository;
$this->translator = $translator;
$this->db = $db;
}
/**
* {@inheritDoc}
*/
public function execute(Exception $exception, string $paypalOrderId)
{
$payPalOrder = $this->payPalOrderRepository->getOneBy(['id' => $paypalOrderId]);
$order = $this->orderRepository->getOneBy(['id_cart' => $payPalOrder->getIdCart()]);
if (!$payPalOrder || !$order) {
return null;
}
$cart = new Cart($payPalOrder->getIdCart());
$contacts = Contact::getContacts((int) $cart->id_lang);
if (empty($contacts)) {
return;
}
// Cannot use id_cart because we create a new cart to preserve current cart from customer changes
$token = Tools::substr(
Tools::encrypt(implode(
'|',
[
(int) $cart->id_customer,
(int) $cart->id_shop,
(int) $cart->id_lang,
(int) $exception->getCode(),
$paypalOrderId,
get_class($exception),
]
)),
0,
12
);
$isThreadAlreadyCreated = (bool) $this->db->getValue('
SELECT 1
FROM ' . _DB_PREFIX_ . 'customer_thread
WHERE id_customer = ' . (int) $cart->id_customer . '
AND id_shop = ' . (int) $cart->id_shop . '
AND status = "open"
AND token = "' . pSQL($token) . '"
');
// Prevent spam Customer Service on case of page refresh
if ($isThreadAlreadyCreated) {
return;
}
$message = $this->translator->trans('This message is sent automatically by module PrestaShop Checkout') . PHP_EOL . PHP_EOL;
$message .= $this->translator->trans('A customer encountered a processing payment error :') . PHP_EOL;
$message .= $this->translator->trans('Customer identifier:') . ' ' . (int) $cart->id_customer . PHP_EOL;
$message .= $this->translator->trans('Cart identifier:') . ' ' . (int) $cart->id . PHP_EOL;
$message .= $this->translator->trans('PayPal order identifier:') . ' ' . Tools::safeOutput($paypalOrderId) . PHP_EOL;
$message .= $this->translator->trans('Exception identifier:') . ' ' . (int) $exception->getCode() . PHP_EOL;
$message .= $this->translator->trans('Exception detail:') . ' ' . Tools::safeOutput($exception->getMessage())
. ($exception->getPrevious() !== null ? ': ' . Tools::safeOutput($exception->getPrevious()->getMessage()) : '')
. PHP_EOL . PHP_EOL;
$message .= $this->translator->trans('If you need assistance, please contact our Support Team on PrestaShop Checkout configuration page on Help subtab.') . PHP_EOL;
$customer = new Customer((int) $cart->id_customer);
$customerThread = new CustomerThread();
$customerThread->id_customer = (int) $cart->id_customer;
$customerThread->id_shop = (int) $cart->id_shop;
$customerThread->id_order = (int) $order->id;
$customerThread->id_lang = (int) $cart->id_lang;
$customerThread->id_contact = (int) $contacts[0]['id_contact'];
$customerThread->email = $customer->email;
$customerThread->status = 'open';
$customerThread->token = $token;
$customerThread->add();
$customerMessage = new CustomerMessage();
$customerMessage->id_customer_thread = $customerThread->id;
$customerMessage->message = $message;
$customerMessage->ip_address = (int) ip2long(Tools::getRemoteAddr());
$customerMessage->user_agent = $_SERVER['HTTP_USER_AGENT'];
$customerMessage->private = true;
$customerMessage->read = false;
$customerMessage->add();
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use Exception;
interface CustomerNotifyActionInterface
{
/**
* @param Exception $exception
* @param string $paypalOrderId
*
* @return void
*/
public function execute(Exception $exception, string $paypalOrderId);
}

View File

@@ -0,0 +1,90 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
use Exception;
use InvalidArgumentException;
use PsCheckout\Core\Settings\Configuration\PayPalConfiguration;
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
use RuntimeException;
class SaveBatchConfigurationAction implements SaveBatchConfigurationActionInterface
{
/**
* @var ConfigurationInterface
*/
private $configuration;
public function __construct(ConfigurationInterface $configuration)
{
$this->configuration = $configuration;
}
/**
* {@inheritDoc}
*/
public function execute(array $configuration)
{
$this->validateBatchConfiguration($configuration);
try {
foreach ($configuration as $configurationItem) {
$this->configuration->set($configurationItem['name'], $configurationItem['value']);
}
} catch (Exception $exception) {
throw new RuntimeException('Could not save configuration: ' . $exception->getMessage(), 0, $exception);
}
}
/**
* @param array $configuration an associative array where keys are configuration names and values are the corresponding settings to be saved
*
* @return void
*/
private function validateBatchConfiguration(array $configuration)
{
$blacklistedConfigurationKeys = [
PayPalConfiguration::PS_CHECKOUT_PAYPAL_ID_MERCHANT,
PayPalConfiguration::PS_CHECKOUT_PAYPAL_EMAIL_STATUS,
PayPalConfiguration::PS_CHECKOUT_PAYPAL_PAYMENT_STATUS,
];
if (empty($configuration)) {
throw new InvalidArgumentException("Config can't be empty");
}
foreach ($configuration as $configurationItem) {
if (!is_array($configurationItem)
|| !array_key_exists('name', $configurationItem)
|| !array_key_exists('value', $configurationItem)
|| empty($configurationItem['name'])
|| 0 !== strpos($configurationItem['name'], 'PS_CHECKOUT_')
) {
throw new InvalidArgumentException('Received invalid configuration key');
}
if (in_array($configurationItem['name'], $blacklistedConfigurationKeys, true)) {
throw new InvalidArgumentException('Received blacklisted configuration key');
}
}
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Action;
interface SaveBatchConfigurationActionInterface
{
/**
* Saves multiple configuration settings at once.
*
* @param array $configuration an associative array where keys are configuration names and values are the corresponding settings to be saved
*
* @return void
*
* @throw InvalidArgumentException if configuration is not valid
* @throw RuntimeException if configuration could not be saved
*/
public function execute(array $configuration);
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Address as PrestaShopAddress;
class Address implements AddressInterface
{
/**
* {@inheritDoc}
*/
public function initialize($idAddress = null): PrestaShopAddress
{
return PrestaShopAddress::initialize($idAddress);
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface AddressInterface
{
/**
* @param int|null $idAddress
*
* @return \Address
*/
public function initialize($idAddress): \Address;
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Cart as PrestaShopCart;
class Cart implements CartInterface
{
const BOTH = PrestaShopCart::BOTH;
/**
* {@inheritDoc}
*/
public function getCart(int $cartId)
{
$cart = new PrestaShopCart($cartId);
if (is_object($cart) && $cart->id) {
return $cart;
}
return null;
}
}

View File

@@ -0,0 +1,33 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Cart as PrestaShopCart;
interface CartInterface
{
/**
* @param int $cartId
*
* @return PrestaShopCart|null
*/
public function getCart(int $cartId);
}

View File

@@ -0,0 +1,119 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Configuration as PrestaShopConfiguration;
class Configuration implements ConfigurationInterface
{
private $context;
public function __construct(ContextInterface $context)
{
$this->context = $context;
}
/**
* {@inheritdoc}
*/
public function get(string $key)
{
$shopId = $this->context->getShop()->id;
$result = PrestaShopConfiguration::get($key, null, null, $shopId);
return $result ?: null;
}
/**
* {@inheritdoc}
*/
public function getInteger(string $key): int
{
return (int) $this->get($key);
}
/**
* {@inheritdoc}
*/
public function getBoolean(string $key): bool
{
return (bool) $this->get($key);
}
/**
* {@inheritdoc}
*/
public function getDeserializedRaw(string $key)
{
$configuration = $this->get($key);
if (!$configuration) {
return [];
}
return json_decode($configuration, true);
}
/**
* {@inheritdoc}
*/
public function getForSpecificShop(string $key, int $shopId, $idLang = null)
{
if (!is_int($shopId)) {
throw new \InvalidArgumentException(sprintf('Invalid argument for shopId: expected integer, got %s.', gettype($shopId)));
}
$result = PrestaShopConfiguration::get($key, $idLang, null, $shopId);
return $result ?: null;
}
/**
* {@inheritdoc}
*/
public function set(string $key, $values): bool
{
$shopId = $this->context->getShop()->id;
return PrestaShopConfiguration::updateValue($key, $values, false, null, $shopId);
}
/**
* {@inheritdoc}
*/
public function setForSpecificShop(string $key, $values, int $shopId): bool
{
if (!is_int($shopId)) {
throw new \InvalidArgumentException(sprintf('Invalid argument for shopId: expected integer, got %s.', gettype($shopId)));
}
return PrestaShopConfiguration::updateValue($key, $values, false, null, $shopId);
}
/**
* {@inheritdoc}
*/
public function deleteByName(string $key): bool
{
return PrestaShopConfiguration::deleteByName($key);
}
}

View File

@@ -0,0 +1,102 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface ConfigurationInterface
{
/**
* Get value from configuration.
*
* @param string $key
*
* @return string|null
*/
public function get(string $key);
/**
* Get integer value from configuration.
*
* @param string $key
*
* @return int
*/
public function getInteger(string $key): int;
/**
* Get boolean value from configuration.
*
* @param string $key
*
* @return bool
*/
public function getBoolean(string $key): bool;
/**
* Get deserialized raw value from configuration.
*
* @param string $key
*
* @return array|null
*/
public function getDeserializedRaw(string $key);
/**
* Get value from specific shop from configuration.
*
* @param string $key
* @param int $shopId
* @param int|null $idLang
*
* @return string|null
*/
public function getForSpecificShop(string $key, int $shopId, $idLang = null);
/**
* Update configuration key and value into database (automatically insert if key does not exist).
*
* Values are inserted/updated directly using SQL, because using (Configuration) ObjectModel
* may not insert values correctly (for example, HTML is escaped, when it should not be).
*
* @param string $key Configuration key
* @param mixed $values $values is an array if the configuration is multilingual, a single string else
*
* @return bool Update result
*/
public function set(string $key, $values): bool;
/**
* Set value from specific shop from configuration.
*
* @param string $key Configuration key
* @param mixed $values $values is an array if the configuration is multilingual, a single string else
* @param int $shopId
*
* @return bool Update result
*/
public function setForSpecificShop(string $key, $values, int $shopId): bool;
/**
* @param string $key
*
* @return bool
*/
public function deleteByName(string $key): bool;
}

View File

@@ -0,0 +1,165 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Context as PrestashopContext;
class Context implements ContextInterface
{
/**
* @var PrestashopContext
*/
private $context;
public function __construct()
{
$this->context = PrestashopContext::getContext();
}
/**
* {@inheritdoc}
*/
public function getCustomer()
{
return $this->context->customer;
}
/**
* {@inheritdoc}
*/
public function getCart()
{
return $this->context->cart;
}
/**
* {@inheritdoc}
*/
public function getCountry()
{
return $this->context->country;
}
/**
* {@inheritdoc}
*/
public function getLanguage()
{
return $this->context->language;
}
/**
* {@inheritDoc}
*/
public function getCurrency()
{
return $this->context->currency;
}
/**
* {@inheritdoc}
*/
public function getLink()
{
return $this->context->link;
}
/**
* {@inheritdoc}
*/
public function getController()
{
return $this->context->controller;
}
/**
* {@inheritdoc}
*/
public function getCurrentThemeName(): string
{
return $this->context->shop->theme_name;
}
/**
* {@inheritdoc}
*/
public function getCurrencyIsoCode(): string
{
return $this->context->currency !== null ? $this->context->currency->iso_code : 'EUR';
}
/**
* {@inheritDoc}
*/
public function getShop()
{
return $this->context->shop;
}
/**
* {@inheritDoc}
*/
public function setCurrentCart(\Cart $cart)
{
$this->context->cart = $cart;
$this->context->cart->update();
if ($cart->id_address_invoice) {
$this->context->country = (new \Country((new \Address($cart->id_address_invoice))->id_country));
}
if ($cart->id_currency) {
$this->context->currency = (new \Currency($cart->id_currency));
}
$this->context->cookie->__set('id_cart', (int) $cart->id);
$this->context->cookie->write();
}
/**
* {@inheritDoc}
*/
public function updateCustomer(\Customer $customer)
{
$this->context->updateCustomer($customer);
}
/**
* {@inheritDoc}
*/
public function resetContextCartAddresses()
{
$this->context->cart->id_address_delivery = 0;
$this->context->cart->id_address_invoice = 0;
$this->context->cart->save();
}
/**
* {@inheritDoc}
*/
public function setPayPalEmail(string $email): void
{
if (\Validate::isEmail($email)) {
$this->context->cookie->__set('paypalEmail', $email);
$this->context->cookie->write();
}
}
}

View File

@@ -0,0 +1,100 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use PrestaShopBundle\Bridge\AdminController\LegacyControllerBridgeInterface;
use PrestaShopBundle\Install\Language as InstallLanguage;
interface ContextInterface
{
/**
* @return \Customer|null
*/
public function getCustomer();
/**
* @return \Cart|null
*/
public function getCart();
/**
* @return \Country|null
*/
public function getCountry();
/**
* @return \Language|InstallLanguage|null
*/
public function getLanguage();
/**
* @return \Currency|null
*/
public function getCurrency();
/**
* @return \Link|null
*/
public function getLink();
/**
* @return \AdminController|\FrontController|LegacyControllerBridgeInterface|null
*/
public function getController();
/**
* @return string
*/
public function getCurrentThemeName(): string;
/**
* Get the currency ISO code (ISO 4217) from the context
*
* @return string
*/
public function getCurrencyIsoCode(): string;
/**
* @return \Shop|null
*/
public function getShop();
/**
* @param \Cart $cart
*
* @return void
*/
public function setCurrentCart(\Cart $cart);
/**
* @param \Customer $customer
*
* @return void
*/
public function updateCustomer(\Customer $customer);
/**
* @return void
*/
public function resetContextCartAddresses();
public function setPayPalEmail(string $email): void;
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Country as PrestaShopCountry;
class Country implements CountryInterface
{
/**
* {@inheritDoc}
*/
public function isNeedDniByCountryId(int $idCountry): bool
{
return PrestaShopCountry::isNeedDniByCountryId($idCountry);
}
/**
* {@inheritDoc}
*/
public function getIdByIsoCode(string $isoCode)
{
return PrestaShopCountry::getByIso($isoCode);
}
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface CountryInterface
{
/**
* @param int $idCountry
*
* @return bool
*/
public function isNeedDniByCountryId(int $idCountry): bool;
/**
* @param string $isoCode
*
* @return int|bool
*/
public function getIdByIsoCode(string $isoCode);
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Currency as PrestaShopCurrency;
class Currency implements CurrencyInterface
{
/**
* {@inheritDoc}
*/
public function getCurrencyInstance(int $idCurrency): PrestaShopCurrency
{
return PrestaShopCurrency::getCurrencyInstance($idCurrency);
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface CurrencyInterface
{
/**
* @param int $idCurrency
*
* @return \Currency
*/
public function getCurrencyInstance(int $idCurrency): \Currency;
}

View File

@@ -0,0 +1,42 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Customer as PrestaShopCustomer;
class Customer implements CustomerInterface
{
/**
* {@inheritDoc}
*/
public function customerHasAddress(int $idCustomer, int $idAddress): bool
{
return PrestaShopCustomer::customerHasAddress($idCustomer, $idAddress);
}
/**
* {@inheritDoc}
*/
public function customerExists(string $email): int
{
return PrestaShopCustomer::customerExists($email, true);
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface CustomerInterface
{
/**
* @param int $idCustomer
* @param int $idAddress
*
* @return bool
*/
public function customerHasAddress(int $idCustomer, int $idAddress): bool;
/**
* @param string $email
*
* @return int
*/
public function customerExists(string $email): int;
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Language as PrestaShopLanguage;
class Language implements LanguageInterface
{
public function getAllLanguages(): array
{
return PrestaShopLanguage::getLanguages(false);
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface LanguageInterface
{
/**
* Get all languages in the shop
*
* @return array<int|array>
*/
public function getAllLanguages(): array;
}

View File

@@ -0,0 +1,87 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
class Link implements LinkInterface
{
/**
* @var ContextInterface
*/
private $context;
/**
* @var string
*/
private $moduleName;
public function __construct(
ContextInterface $context,
string $moduleName
) {
$this->context = $context;
$this->moduleName = $moduleName;
}
/**
* {@inheritdoc}
*/
public function getAdminLink(string $controller, bool $withToken = true, array $sfRouteParams = [], array $params = []): string
{
$shop = $this->context->getShop();
$adminLink = $this->context->getLink()->getAdminLink($controller, $withToken, $sfRouteParams, $params);
if ($shop->virtual_uri !== '') {
$adminLink = str_replace($shop->physical_uri . $shop->virtual_uri, $shop->physical_uri, $adminLink);
}
// We have problems with links in our zoid application, since some links generated don't have domain they redirect to CDN domain
// Routes that use new symfony router are returned without the domain
if (strpos($adminLink, 'http') !== 0) {
return \Tools::getShopDomainSsl(true) . $adminLink;
}
return $adminLink;
}
/**
* {@inheritdoc}
*/
public function getModuleLink(string $controller, array $params = []): string
{
return $this->context->getLink()->getModuleLink(
$this->moduleName,
$controller,
$params,
true,
$this->context->getLanguage()->id,
$this->context->getShop()->id
);
}
/**
* {@inheritdoc}
*/
public function getPageLink(string $controller, array $params = []): string
{
return $this->context->getLink()->getPageLink($controller, true, $this->context->getLanguage()->id, $params);
}
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface LinkInterface
{
/**
* Adapter for getAdminLink from prestashop link class
*
* @param string $controller controller name
* @param bool $withToken include or not the token in the url
* @param array $sfRouteParams
* @param array $params
*
* @return string
*
* @throws \PrestaShopException
*/
public function getAdminLink(string $controller, bool $withToken = true, array $sfRouteParams = [], array $params = []): string;
/**
* @param string $controller
* @param array $params
*
* @return string
*/
public function getModuleLink(string $controller, array $params = []): string;
/**
* @param string $controller
* @param array $params
*
* @return string
*/
public function getPageLink(string $controller, array $params = []): string;
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
class ShopContext implements ShopContextInterface
{
/**
* {@inheritdoc}
*/
public function getCurrent(): array
{
return [
'context' => \Shop::getContext(),
'shop_id' => \Shop::getContextShopID(),
'group_shop_id' => \Shop::getContextShopGroupID(),
];
}
/**
* {@inheritdoc}
*/
public function setAllShopContext()
{
\Shop::setContext(\Shop::CONTEXT_ALL);
}
/**
* {@inheritdoc}
*/
public function setContext(array $context)
{
if (isset($context['shop_id'])) {
\Shop::setContext($context['context'], $context['shop_id']);
} elseif (isset($context['group_shop_id'])) {
\Shop::setContext($context['context'], $context['group_shop_id']);
} else {
\Shop::setContext($context['context']);
}
}
}

View File

@@ -0,0 +1,55 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface ShopContextInterface
{
/**
* Retrieves the current context.
*
* @return array{
* context: int|null,
* shop_id: int|null,
* group_shop_id: int|null
* } Current shop context information
*/
public function getCurrent(): array;
/**
* Sets the specified shop context.
*
* @return void
*/
public function setAllShopContext();
/**
* Sets the specified shop context.
*
* @param array{
* context: int|string|null,
* shop_id?: int|null,
* group_shop_id?: int|null
* } $context Context information to apply
*
* @return void
*/
public function setContext(array $context);
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
class SystemConfiguration implements SystemConfigurationInterface
{
/**
* {@inheritDoc}
*/
public function isApacheServer()
{
if (php_sapi_name() === 'apache2handler') {
return true;
}
if (function_exists('apache_get_version')) {
return true;
}
if (isset($_SERVER['SERVER_SOFTWARE']) && stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
return true;
}
if (isset($_SERVER['HTTPD_SERVER_ADMIN']) || isset($_SERVER['HTTPD_SERVER_NAME'])) {
return true;
}
$headers = $this->getAllHeaders();
if (isset($headers['Server']) && stripos($headers['Server'], 'apache') !== false) {
return true;
}
return false;
}
/**
* {@inheritDoc}
*/
public function getAllHeaders()
{
if (function_exists('getallheaders')) {
return getallheaders();
}
return [];
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface SystemConfigurationInterface
{
/**
* @return bool
*/
public function isApacheServer();
/**
* @return array
*/
public function getAllHeaders();
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Tools as PrestaShopTools;
class Tools implements ToolsInterface
{
/**
* {@inheritDoc}
*/
public function getValue(string $key): string
{
return (string) PrestaShopTools::getValue($key);
}
/**
* {@inheritDoc}
*/
public function redirect(string $url)
{
PrestaShopTools::redirect($url);
}
/**
* {@inheritDoc}
*/
public function getToken(bool $page): string
{
return PrestaShopTools::getToken($page);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface ToolsInterface
{
/**
* @param string $key
*
* @return string
*/
public function getValue(string $key): string;
/**
* @param string $url
*
* @return void
*/
public function redirect(string $url);
public function getToken(bool $page): string;
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
use Validate as PrestaShopValidate;
class Validate implements ValidateInterface
{
/**
* {@inheritDoc}
*/
public function isEmail(string $email): bool
{
return PrestaShopValidate::isEmail($email);
}
/**
* {@inheritDoc}
*/
public function isGenericName(string $name): bool
{
return PrestaShopValidate::isGenericName($name);
}
/**
* {@inheritDoc}
*/
public function isFileName(string $filename): bool
{
return PrestaShopValidate::isFileName($filename);
}
}

View File

@@ -0,0 +1,40 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Adapter;
interface ValidateInterface
{
/**
* @param string $email
*
* @return bool
*/
public function isEmail(string $email): bool;
/**
* @param string $name
*
* @return bool
*/
public function isGenericName(string $name): bool;
public function isFileName(string $filename): bool;
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,219 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
use PsCheckout\Core\Settings\Configuration\PayPalConfiguration;
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
use PsCheckout\Infrastructure\Adapter\SystemConfigurationInterface;
class ApplePayInstaller
{
/**
* @var SystemConfigurationInterface
*/
private $systemConfiguration;
/**
* @var ConfigurationInterface
*/
private $configuration;
public function __construct(SystemConfigurationInterface $systemConfiguration, ConfigurationInterface $configuration)
{
$this->systemConfiguration = $systemConfiguration;
$this->configuration = $configuration;
}
/**
* @return void
*
* @throws ApplePayInstallerException
*/
public function setup()
{
if ($this->systemConfiguration->isApacheServer() && !$this->checkWellKnownFileExist()) {
$this->registerModuleRoutesHook();
} else {
$this->copyWellKnownFile();
}
}
/**
* @return void
*
* @throws ApplePayInstallerException
*/
public function registerModuleRoutesHook()
{
try {
$module = \Module::getInstanceByName('ps_checkout');
$shopList = \Shop::getCompleteListOfShopsID();
if (!\Hook::registerHook($module, 'moduleRoutes', $shopList)) {
throw new ApplePayInstallerException('Failed to register moduleRoutes hook for ps_checkout.', ApplePayInstallerException::FAILED_REGISTER_HOOK);
}
} catch (\Exception $e) {
throw new ApplePayInstallerException('Failed to register moduleRoutes hook for ps_checkout.', ApplePayInstallerException::ERROR_REGISTER_HOOK, $e);
}
}
/**
* @param string $wellKnownDir
*
* @return string
*/
public function getDestinationFile($wellKnownDir)
{
return $wellKnownDir . '/apple-developer-merchantid-domain-association';
}
/**
* @return bool
*
* @throws ApplePayInstallerException
*/
public function checkWellKnownFileExist()
{
$rootDir = $this->getPrestaShopRootDir();
$wellKnownDir = $this->getWellKnownDir($rootDir);
$destinationFile = $this->getDestinationFile($wellKnownDir);
return file_exists($destinationFile);
}
/**
* @return void
*
* @throws ApplePayInstallerException
*/
public function copyWellKnownFile()
{
$rootDir = $this->getPrestaShopRootDir();
$this->checkPrestaShopIsAtDomainRoot();
$wellKnownDir = $this->getWellKnownDir($rootDir);
$sourceFile = $this->getSourceFile();
$destinationFile = $this->getDestinationFile($wellKnownDir);
if (file_exists($destinationFile) && !$this->isWritable($destinationFile)) {
throw new ApplePayInstallerException('The Apple Domain Association file is not writable in the PrestaShop root directory.', ApplePayInstallerException::APPLE_DOMAIN_FILE_NOT_WRITABLE);
}
if (!copy($sourceFile, $destinationFile)) {
throw new ApplePayInstallerException('Failed to copy the "apple-developer-merchantid-domain-association" file to the PrestaShop root directory.', ApplePayInstallerException::FAILED_COPY_APPLE_DOMAIN_FILE);
}
}
/**
* @return string
*
* @throws ApplePayInstallerException
*/
public function getPrestaShopRootDir()
{
$rootDir = defined('_PS_ROOT_DIR_') ? constant('_PS_ROOT_DIR_') : null;
if (!$rootDir || !is_dir($rootDir)) {
throw new ApplePayInstallerException('Unable to retrieve the PrestaShop Root directory path.', ApplePayInstallerException::UNABLE_RETRIEVE_ROOT_DIR);
}
return $rootDir;
}
/**
* @return void
*
* @throws ApplePayInstallerException
*/
public function checkPrestaShopIsAtDomainRoot()
{
$defaultShop = new \Shop((int) \Configuration::get('PS_SHOP_DEFAULT'));
if (!$defaultShop->physical_uri) {
throw new ApplePayInstallerException('Unable to retrieve the base URI of the shop.', ApplePayInstallerException::UNABLE_RETRIEVE_BASE_URI);
}
if ($defaultShop->physical_uri !== '/') {
throw new ApplePayInstallerException('PrestaShop is not installed at the domain root.', ApplePayInstallerException::PRESTASHOP_NOT_AT_DOMAIN_ROOT);
}
}
/**
* @param string $rootDir
*
* @return string
*
* @throws ApplePayInstallerException
*/
public function getWellKnownDir($rootDir)
{
$wellKnownDir = $rootDir . '/.well-known';
if (!is_dir($wellKnownDir)) {
if (!$this->createDir($wellKnownDir)) {
throw new ApplePayInstallerException('Failed to create the ".well-known" directory in the PrestaShop root directory.', ApplePayInstallerException::FAILED_CREATE_WELL_KNOWN_DIR);
}
}
if (!$this->isWritable($wellKnownDir)) {
throw new ApplePayInstallerException('The ".well-known" directory is not writable in the PrestaShop root directory.', ApplePayInstallerException::WELL_KNOWN_DIR_NOT_WRITABLE);
}
return $wellKnownDir;
}
/**
* @return string
*
* @throws ApplePayInstallerException
*/
public function getSourceFile()
{
$moduleDir = defined('_PS_MODULE_DIR_') ? constant('_PS_MODULE_DIR_') : null;
$moduleWellKnownDir = $moduleDir . 'ps_checkout/.well-known';
$paypalEnvironment = $this->configuration->get(PayPalConfiguration::PS_CHECKOUT_PAYMENT_MODE);
$sourceFile = "$moduleWellKnownDir/apple-$paypalEnvironment-merchantid-domain-association";
if (!file_exists($sourceFile)) {
throw new ApplePayInstallerException('The Apple Domain Association file could not be found in the module directory.', ApplePayInstallerException::APPLE_DOMAIN_FILE_NOT_FOUND);
}
return $sourceFile;
}
/**
* @param string $wellKnownDir
*
* @return bool
*/
public function createDir($wellKnownDir)
{
return mkdir($wellKnownDir, 0755, true);
}
/**
* @param string $wellKnownDir
*
* @return bool
*/
public function isWritable($wellKnownDir)
{
return is_writable($wellKnownDir);
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
use PsCheckout\Core\Exception\PsCheckoutException;
class ApplePayInstallerException extends PsCheckoutException
{
const FAILED_REGISTER_HOOK = 1001;
const ERROR_REGISTER_HOOK = 1002;
const UNABLE_RETRIEVE_ROOT_DIR = 2001;
const FAILED_CREATE_WELL_KNOWN_DIR = 2002;
const WELL_KNOWN_DIR_NOT_WRITABLE = 2003;
const PRESTASHOP_NOT_AT_DOMAIN_ROOT = 2004;
const UNABLE_RETRIEVE_BASE_URI = 2005;
const APPLE_DOMAIN_FILE_NOT_FOUND = 3001;
const APPLE_DOMAIN_FILE_NOT_WRITABLE = 3002;
const FAILED_COPY_APPLE_DOMAIN_FILE = 3003;
}

View File

@@ -0,0 +1,107 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
use PsCheckout\Core\Settings\Configuration\PayPalCodeConfiguration;
use PsCheckout\Infrastructure\Repository\CountryRepositoryInterface;
use PsCheckout\Infrastructure\Repository\CurrencyRepositoryInterface;
use PsCheckout\Utility\Common\ArrayUtility;
class CompatibilityRulesInstaller implements InstallerInterface
{
/**
* @var CountryRepositoryInterface
*/
private $countryRepository;
/**
* @var CurrencyRepositoryInterface
*/
private $currencyRepository;
public function __construct(
CountryRepositoryInterface $countryRepository,
CurrencyRepositoryInterface $currencyRepository
) {
$this->countryRepository = $countryRepository;
$this->currencyRepository = $currencyRepository;
}
/**
* {@inheritdoc}
*/
public function init(): bool
{
return $this->disableIncompatibleCountries() && $this->disableIncompatibleCurrencies();
}
/**
* Disable incompatible countries with PayPal for PrestaShop Checkout
*
* @return bool
*/
private function disableIncompatibleCountries()
{
$moduleCountryCodes = $this->countryRepository->getModuleCountryCodes(false);
// Extract the 'iso_code' values
$moduleCountryIsoCodes = array_map(function ($item) {
return $item['iso_code'];
}, $moduleCountryCodes);
$incompatibleCodes = ArrayUtility::findMissingKeys($moduleCountryIsoCodes, PayPalCodeConfiguration::getCountryCodes());
$result = true;
foreach ($incompatibleCodes as $incompatibleCode) {
// Delete incompatible country from module_country table
$result &= $this->countryRepository->deleteModuleCountryByIsoCode($incompatibleCode);
}
return $result;
}
/**
* Disable incompatible currencies with PayPal for PrestaShop Checkout
*
* @return bool
*/
private function disableIncompatibleCurrencies()
{
$moduleCurrencyCodes = $this->currencyRepository->getModuleCurrencyCodes(false);
// Extract the 'iso_code' values
$moduleCurrenciesIsoCodes = array_map(function ($item) {
return $item['iso_code'];
}, $moduleCurrencyCodes);
$incompatibleCodes = ArrayUtility::findMissingKeys($moduleCurrenciesIsoCodes, PayPalCodeConfiguration::getCurrencyCodes());
$result = true;
foreach ($incompatibleCodes as $incompatibleCode) {
// Delete incompatible currency from module_currency table
$result &= $this->currencyRepository->deleteModuleCurrencyByIsoCode($incompatibleCode);
}
return $result;
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
use PsCheckout\Core\Settings\Configuration\DefaultConfiguration;
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
use PsCheckout\Infrastructure\Repository\ShopRepositoryInterface;
class ConfigurationInstaller implements InstallerInterface
{
/**
* @var ShopRepositoryInterface
*/
private $shop;
/**
* @var ConfigurationInterface
*/
private $configuration;
public function __construct(ShopRepositoryInterface $shop, ConfigurationInterface $configuration)
{
$this->shop = $shop;
$this->configuration = $configuration;
}
/**
* {@inheritdoc}
*/
public function init(): bool
{
$result = true;
foreach ($this->shop->getAll() as $shopId) {
foreach (DefaultConfiguration::DEFAULT_CONFIGURATION_VALUES as $name => $value) {
if (!$this->configuration->getForSpecificShop($name, (int) $shopId)) {
$result = $result && $this->configuration->setForSpecificShop(
$name,
$value,
(int) $shopId
);
}
}
}
return $result;
}
}

View File

@@ -0,0 +1,237 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
class DatabaseTableInstaller implements InstallerInterface
{
/**
* @var \Db
*/
private $db;
/**
* @param \Db $db PrestaShop Db instance
*/
public function __construct(\Db $db)
{
$this->db = $db;
}
/**
* Create table
*
* @return bool
*/
public function init(): bool
{
$result = $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_order_matrice` (
`id_order_matrice` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_order_prestashop` int(10) unsigned NOT NULL,
`id_order_paypal` varchar(20) NOT NULL,
PRIMARY KEY (`id_order_matrice`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_cart` (
`id_pscheckout_cart` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_cart` int unsigned NOT NULL,
`paypal_intent` varchar(20) DEFAULT "CAPTURE",
`paypal_order` varchar(20) NULL,
`paypal_status` varchar(30) NULL,
`paypal_funding` varchar(20) NULL,
`paypal_token` text DEFAULT NULL,
`paypal_token_expire` datetime NULL,
`paypal_authorization_expire` datetime NULL,
`environment` varchar(20) NULL,
`isExpressCheckout` tinyint(1) unsigned DEFAULT 0 NOT NULL,
`isHostedFields` tinyint(1) unsigned DEFAULT 0 NOT NULL,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id_pscheckout_cart`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_funding_source` (
`name` varchar(20) NOT NULL,
`active` tinyint(1) unsigned DEFAULT 0 NOT NULL,
`position` tinyint(2) unsigned NOT NULL,
`id_shop` int unsigned NOT NULL,
PRIMARY KEY (`name`, `id_shop`),
INDEX (`id_shop`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_order` (
`id` varchar(50) NOT NULL,
`id_cart` int unsigned NOT NULL,
`status` varchar(30) NOT NULL,
`intent` varchar(50) DEFAULT "CAPTURE",
`funding_source` varchar(50) NOT NULL,
`payment_source` text,
`environment` varchar(50) NOT NULL,
`is_card_fields` tinyint(1) NOT NULL,
`is_express_checkout` tinyint(1) NOT NULL,
`customer_intent` varchar(50),
`payment_token_id` varchar(50),
`tags` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_capture` (
`id` varchar(50) NOT NULL,
`id_order` varchar(50) NOT NULL,
`status` varchar(30) NOT NULL,
`final_capture` tinyint(1) NOT NULL,
`created_at` varchar(50) NOT NULL,
`updated_at` varchar(50) NOT NULL,
`seller_protection` text,
`seller_receivable_breakdown` text,
PRIMARY KEY (`id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_refund` (
`id` varchar(50) NOT NULL,
`id_order` varchar(50) NOT NULL,
`status` varchar(30) NOT NULL,
`invoice_id` varchar(50) NOT NULL,
`custom_id` varchar(50) NOT NULL,
`acquirer_reference_number` varchar(50) NOT NULL,
`seller_payable_breakdown` text,
`id_order_slip` INT UNSIGNED,
PRIMARY KEY (`id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_authorization` (
`id` varchar(50) NOT NULL,
`id_order` varchar(50) NOT NULL,
`status` varchar(30) NOT NULL,
`expiration_time` varchar(50) NOT NULL,
`seller_protection` text,
PRIMARY KEY (`id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_purchase_unit` (
`id_order` varchar(50) NOT NULL,
`checksum` varchar(50) NOT NULL,
`reference_id` varchar(50) NOT NULL,
`items` text,
PRIMARY KEY (`reference_id`, `id_order`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_customer` (
`id_customer` int unsigned NOT NULL,
`paypal_customer_id` varchar(50) NOT NULL,
PRIMARY KEY (`id_customer`, `paypal_customer_id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_payment_token` (
`id` INT UNSIGNED AUTO_INCREMENT,
`token_id` varchar(50) NOT NULL,
`paypal_customer_id` varchar(50) NOT NULL,
`payment_source` varchar(50) NOT NULL,
`data` text NOT NULL,
`merchant_id` varchar(50) NOT NULL,
`status` varchar(50) NOT NULL,
`is_favorite` tinyint(1) unsigned DEFAULT 0 NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `token_id_merchant_id_paypal_customer_id` (`token_id`, `merchant_id`, `paypal_customer_id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
') && $this->db->execute('
CREATE TABLE IF NOT EXISTS `' . _DB_PREFIX_ . 'pscheckout_tracking` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_order` int(10) unsigned NOT NULL,
`tracking_number` varchar(64) NOT NULL,
`carrier_id` int(10) unsigned NOT NULL,
`carrier_name` varchar(64) NOT NULL,
`paypal_order_id` varchar(50) NOT NULL,
`paypal_capture_id` varchar(50) NOT NULL,
`tracker_id` varchar(64) DEFAULT NULL,
`items` text DEFAULT NULL,
`status` varchar(20) NOT NULL DEFAULT "PENDING",
`paypal_tracking_status` varchar(20) DEFAULT NULL,
`payload_checksum` varchar(64) NOT NULL,
`sent_to_paypal` tinyint(1) NOT NULL DEFAULT 0,
`date_add` datetime NOT NULL,
`date_upd` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `id_order` (`id_order`),
KEY `tracking_number` (`tracking_number`),
KEY `paypal_order_id` (`paypal_order_id`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
');
$this->checkTable();
return $result;
}
/**
* Drop table
*
* @return bool
*/
public function dropTable(): bool
{
// Avoid to lose PayPal data if module is reset or uninstalled
return true;
}
/**
* Check if existing database is up to date
* Due to `CREATE TABLE IF NOT EXISTS` we need to check if table is up to date
*
* @return void
*/
public function checkTable()
{
$fields = $this->db->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'pscheckout_cart`');
if (!empty($fields)) {
foreach ($fields as $field) {
if ($field['Field'] === 'paypal_token' && $field['Type'] !== 'text') {
$this->db->execute('ALTER TABLE `' . _DB_PREFIX_ . 'pscheckout_cart` CHANGE `paypal_token` `paypal_token` text DEFAULT NULL;');
}
if ($field['Field'] === 'paypal_status' && $field['Type'] !== 'varchar(30)') {
$this->db->execute('ALTER TABLE `' . _DB_PREFIX_ . 'pscheckout_cart` CHANGE `paypal_status` `paypal_status` varchar(30) NULL;');
}
}
$field = array_filter($fields, function ($field) {
return $field['Field'] === 'environment';
});
if (empty($field)) {
$this->db->execute('ALTER TABLE `' . _DB_PREFIX_ . 'pscheckout_cart` ADD COLUMN `environment` varchar(20) DEFAULT NULL;');
}
}
$fields = $this->db->executeS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'pscheckout_order`');
if (!empty($fields)) {
$field = array_filter($fields, function ($field) {
return $field['Field'] === 'tags';
});
if (empty($field)) {
$this->db->execute('ALTER TABLE `' . _DB_PREFIX_ . 'pscheckout_order` ADD COLUMN `tags` varchar(255) DEFAULT NULL;');
}
}
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
use PsCheckout\Core\FundingSource\Repository\FundingSourceRepositoryInterface;
use PsCheckout\Infrastructure\Repository\ShopRepositoryInterface;
class FundingSourceInstaller implements InstallerInterface
{
/**
* @var ShopRepositoryInterface
*/
private $shop;
/**
* @var FundingSourceRepositoryInterface
*/
private $fundingSourceRepository;
public function __construct(ShopRepositoryInterface $shop, FundingSourceRepositoryInterface $fundingSourceRepository)
{
$this->shop = $shop;
$this->fundingSourceRepository = $fundingSourceRepository;
}
public function init(): bool
{
foreach ($this->shop->getAll() as $shop) {
$this->fundingSourceRepository->populateWithDefaultValues((int) $shop['id_shop']);
}
return true;
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
class Installer implements InstallerInterface
{
/**
* @var InstallerInterface
*/
private $configurationInstaller;
/**
* @var InstallerInterface
*/
private $databaseTableInstaller;
/**
* @var InstallerInterface
*/
private $fundingSourceInstaller;
/**
* @var InstallerInterface
*/
private $orderStateInstaller;
/**
* @var InstallerInterface
*/
private $compatibilityRulesInstaller;
public function __construct(
InstallerInterface $configurationInstaller,
InstallerInterface $databaseTableInstaller,
InstallerInterface $fundingSourceInstaller,
InstallerInterface $orderStateInstaller,
InstallerInterface $compatibilityRulesInstaller
) {
$this->configurationInstaller = $configurationInstaller;
$this->databaseTableInstaller = $databaseTableInstaller;
$this->fundingSourceInstaller = $fundingSourceInstaller;
$this->orderStateInstaller = $orderStateInstaller;
$this->compatibilityRulesInstaller = $compatibilityRulesInstaller;
}
/**
* {@inheritdoc}
*/
public function init(): bool
{
$result = $this->configurationInstaller->init()
&& $this->databaseTableInstaller->init()
&& $this->fundingSourceInstaller->init()
&& $this->orderStateInstaller->init()
&& $this->compatibilityRulesInstaller->init();
return $result;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
interface InstallerInterface
{
/**
* @return bool
*/
public function init(): bool;
}

View File

@@ -0,0 +1,214 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Bootstrap\Install;
use PsCheckout\Core\OrderState\Configuration\OrderStateConfiguration;
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
use PsCheckout\Infrastructure\Adapter\LanguageInterface;
class OrderStateInstaller implements InstallerInterface
{
/**
* @var ConfigurationInterface
*/
private $configuration;
/**
* @var LanguageInterface
*/
private $languages;
/**
* @var string
*/
private $moduleName;
public function __construct(ConfigurationInterface $configuration, LanguageInterface $language, $moduleName)
{
$this->configuration = $configuration;
$this->languages = $language;
$this->moduleName = $moduleName;
}
/**
* {@inheritdoc}
*/
public function init(): bool
{
$this->configuration->set(OrderStateConfiguration::PS_CHECKOUT_STATE_COMPLETED, $this->configuration->get(OrderStateConfiguration::PS_OS_PAYMENT));
$this->configuration->set(OrderStateConfiguration::PS_CHECKOUT_STATE_CANCELED, $this->configuration->get(OrderStateConfiguration::PS_OS_CANCELED));
$this->configuration->set(OrderStateConfiguration::PS_CHECKOUT_STATE_ERROR, $this->configuration->get(OrderStateConfiguration::PS_OS_ERROR));
$this->configuration->set(OrderStateConfiguration::PS_CHECKOUT_STATE_REFUNDED, $this->configuration->get(OrderStateConfiguration::PS_OS_REFUND));
if (!$this->checkAlreadyInstalled(OrderStateConfiguration::PS_CHECKOUT_STATE_PENDING)) {
$pendingStateId = $this->createOrderState(
'#34209E',
[
'en' => 'Waiting for payment',
'fr' => 'En attente de paiement',
'es' => 'Esperando el pago',
'it' => 'In attesa di pagamento',
'nl' => 'Wachten op betaling',
'de' => 'Warten auf Zahlung',
'pl' => 'Oczekiwanie na płatność',
'pt' => 'Aguardando pagamento',
]
);
$this->configuration->set(OrderStateConfiguration::PS_CHECKOUT_STATE_PENDING, $pendingStateId);
}
if (!$this->checkAlreadyInstalled(OrderStateConfiguration::PS_CHECKOUT_STATE_PARTIALLY_REFUNDED)) {
$partiallyRefundedStateId = $this->createOrderState(
'#01B887',
[
'en' => 'Partial refund',
'fr' => 'Remboursement partiel',
'es' => 'Reembolso parcial',
'it' => 'Rimborso parziale',
'nl' => 'Gedeeltelijke terugbetaling',
'de' => 'Teilweise Rückerstattung',
'pl' => 'Częściowy zwrot',
'pt' => 'Reembolso parcial',
]
);
$this->configuration->set(OrderStateConfiguration::PS_CHECKOUT_STATE_PARTIALLY_REFUNDED, $partiallyRefundedStateId);
}
if (!$this->checkAlreadyInstalled(OrderStateConfiguration::PS_CHECKOUT_STATE_PARTIALLY_PAID)) {
$partiallyPaidStateId = $this->createOrderState(
'#3498D8',
[
'en' => 'Partial payment',
'fr' => 'Paiement partiel',
'es' => 'Pago parcial',
'it' => 'Pagamento parziale',
'nl' => 'Gedeeltelijke betaling',
'de' => 'Teilweise Zahlung',
'pl' => 'Częściowa płatność',
'pt' => 'Pagamento parcial',
]
);
$this->configuration->set(OrderStateConfiguration::PS_CHECKOUT_STATE_PARTIALLY_PAID, $partiallyPaidStateId);
}
if (!$this->checkAlreadyInstalled(OrderStateConfiguration::PS_CHECKOUT_STATE_AUTHORIZED)) {
$authorizedStateId = $this->createOrderState(
'#3498D8',
[
'en' => 'Authorized. To be captured by merchant',
'fr' => 'Autorisation. A capturer par le marchand',
'es' => 'Autorizado. El vendedor lo capturará',
'it' => 'Autorizzato. Sarà acquisito dal commerciante',
'nl' => 'Goedgekeurd. Door retailer te registreren.',
'de' => 'Autorisiert. Wird von Händler erfasst.',
'pl' => 'Pomyślna autoryzacja. Transfer do przeprowadzenia przez sklep',
'pt' => 'Autorizado. A ser capturado pelo comerciante',
]
);
$this->configuration->set(OrderStateConfiguration::PS_CHECKOUT_STATE_AUTHORIZED, $authorizedStateId);
}
return true;
}
/**
* @param string $color
* @param array $nameByLangIsoCode
*
* @return int|null
*
* @throws \PrestaShopException
*/
private function createOrderState(string $color, array $nameByLangIsoCode)
{
$orderState = new \OrderState();
$orderState->name = $this->fillOrderStateName($nameByLangIsoCode);
$orderState->module_name = $this->moduleName;
$orderState->unremovable = true;
$orderState->color = $color;
$orderState->delivery = false;
$orderState->shipped = false;
$orderState->pdf_delivery = false;
$orderState->pdf_invoice = false;
$orderState->hidden = false;
$orderState->invoice = false;
$orderState->send_email = false;
$orderState->paid = false;
$orderState->logable = false;
$orderState->deleted = false;
$orderState->template = [];
$orderState->save();
return $orderState->id;
}
/**
* @param array $nameByLangIsoCode
*
* @return array
*/
private function fillOrderStateName(array $nameByLangIsoCode): array
{
$orderStateNameByLangId = [];
foreach ($this->languages->getAllLanguages() as $language) {
$languageIsoCode = mb_strtolower($language['iso_code']);
if (isset($nameByLangIsoCode[$languageIsoCode])) {
$orderStateNameByLangId[(int) $language['id_lang']] = $nameByLangIsoCode[$languageIsoCode];
} else {
$orderStateNameByLangId[(int) $language['id_lang']] = $nameByLangIsoCode['en'];
}
}
return $orderStateNameByLangId;
}
/**
* @param string $orderStateKey
*
* @return bool
*/
private function checkAlreadyInstalled(string $orderStateKey): bool
{
$orderStateId = $this->configuration->getInteger($orderStateKey);
if (!$orderStateId) {
return false;
}
$orderState = new \OrderState($orderStateId);
if (!$orderState->id) {
return false;
}
if ($orderState->module_name !== $this->moduleName || $orderState->deleted) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,40 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Controller;
class AbstractAdminController extends \ModuleAdminController
{
/**
* @param array $permissions
*
* @return bool
*/
public function ensureHasPermissions(array $permissions): bool
{
foreach ($permissions as $permission) {
if (!$this->access($permission)) {
return false;
}
}
return true;
}
}

View File

@@ -0,0 +1,124 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Controller;
use Connection;
use Exception;
use ModuleFrontController;
use Ps_Checkout;
use Psr\Log\LoggerInterface;
class AbstractFrontController extends ModuleFrontController
{
/**
* @var Ps_checkout
*/
public $module;
/**
* Override checkAccess to block access for bots and invalid token
*
* @see FrontController::checkAccess()
*/
public function checkAccess()
{
return !$this->isBot() && !($this->context->customer->isLogged() && !$this->isTokenValid());
}
/**
* Override initCursedPage to return json response with 403 code on POST request
*
* @see FrontController::initCursedPage()
*/
public function initCursedPage()
{
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$this->exitWithResponse([
'httpCode' => 403,
'body' => 'Forbidden',
]);
}
parent::initCursedPage();
}
/**
* @param array $response
*
* @return void
*/
protected function exitWithResponse(array $response = [])
{
ob_end_clean();
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/json;charset=utf-8');
header('X-Robots-Tag: noindex, nofollow');
if (isset($response['httpCode'])) {
http_response_code($response['httpCode']);
}
if (!empty($response)) {
echo json_encode($response, JSON_UNESCAPED_SLASHES);
}
exit;
}
/**
* Check if the current visitor is a bot, available since PrestaShop 8.0.0
*
* @return bool
*/
public function isBot()
{
return method_exists(Connection::class, 'isBot') && Connection::isBot();
}
/**
* @param Exception $exception
*
* @return void
*/
protected function exitWithExceptionMessage(Exception $exception)
{
/** @var LoggerInterface $logger */
$logger = $this->module->getService(LoggerInterface::class);
$logger->error(
$exception->getMessage(),
[
'controller' => static::class,
'exception' => $exception,
]
);
$this->exitWithResponse([
'status' => false,
'httpCode' => 500,
'body' => [
'error' => [
'code' => $exception->getCode(),
'message' => $exception->getMessage(),
],
],
]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,28 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Enum;
class PermissionType
{
public const VIEW = 'view';
public const EDIT = 'edit';
}

View File

@@ -0,0 +1,30 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,146 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Environment;
use PsCheckout\Core\Settings\Configuration\PayPalConfiguration;
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
/**
* Get the current environment used: prod or test // sandbox or live
*/
class Env implements EnvInterface
{
/**
* Const that define all environment possible to use.
* Top of the list are taken in first if they exist in the project.
* eg: If .env.test is present in the module it will be loaded, if not present
* we try to load the next one etc ...
*
* @var array
*/
const FILE_ENV_LIST = [
'test' => '.env.test',
'prod' => '.env',
];
/**
* Environment mode: can be 'live' or 'sandbox'
*
* @var string
*/
protected $mode;
/**
* @param string $moduleName
* @param ConfigurationInterface $configuration
*/
public function __construct(
string $moduleName,
ConfigurationInterface $configuration
) {
foreach (self::FILE_ENV_LIST as $env => $fileName) {
$envFilePath = _PS_MODULE_DIR_ . $moduleName . '/' . $fileName;
if (!file_exists($envFilePath)) {
continue;
}
$envLoader = new EnvLoader();
$envLoader->load($envFilePath, false);
break;
}
$this->mode = $configuration->get(PayPalConfiguration::PS_CHECKOUT_PAYMENT_MODE);
}
/**
* {@inheritdoc}
*/
public function getEnv(string $name)
{
if (isset($_ENV[$name])) {
return $_ENV[$name];
}
if (isset($_SERVER[$name])) {
return $_SERVER[$name];
}
return getenv($name);
}
/**
* {@inheritdoc}
*/
public function getCheckoutApiUrl(): string
{
if (PayPalConfiguration::MODE_SANDBOX === $this->mode) {
return $this->getEnv('CHECKOUT_API_URL_SANDBOX');
}
return $this->getEnv('CHECKOUT_API_URL_LIVE');
}
/**
* {@inheritdoc}
*/
public function getShipmentTrackingApiUrl(): string
{
if (PayPalConfiguration::MODE_SANDBOX === $this->mode) {
return $this->getEnv('TRACKING_API_URL_SANDBOX');
}
return $this->getEnv('TRACKING_API_URL_LIVE');
}
/**
* {@inheritdoc}
*/
public function getPaymentApiUrl(): string
{
if (PayPalConfiguration::MODE_SANDBOX === $this->mode) {
return $this->getEnv('PAYMENT_API_URL_SANDBOX');
}
return $this->getEnv('PAYMENT_API_URL_LIVE');
}
/**
* {@inheritdoc}
*/
public function getPaypalClientId(): string
{
if (PayPalConfiguration::MODE_SANDBOX === $this->mode) {
return $this->getEnv('PAYPAL_CLIENT_ID_SANDBOX');
}
return $this->getEnv('PAYPAL_CLIENT_ID_LIVE');
}
/**
* {@inheritdoc}
*/
public function getBnCode(): string
{
return $this->getEnv('PAYPAL_BN_CODE');
}
}

View File

@@ -0,0 +1,62 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Environment;
interface EnvInterface
{
/**
* Get environment variable.
*
* @param string $name
*
* @return mixed
*/
public function getEnv(string $name);
/**
* @return string
*/
public function getCheckoutApiUrl(): string;
/**
* @return string
*/
public function getShipmentTrackingApiUrl(): string;
/**
* Retrieve payment api url
*
* @return string
*/
public function getPaymentApiUrl(): string;
/**
* @return string
*/
public function getPaypalClientId(): string;
/**
* Retrieve the bn code
*
* @return string
*/
public function getBnCode(): string;
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Environment;
class EnvLoader implements EnvLoaderInterface
{
/**
* @var bool
*/
private $apacheEnvSupported;
/**
* @var bool
*/
private $putEnvSupported;
/**
* @var bool
*/
private $quiet;
public function __construct($quiet = true)
{
$this->apacheEnvSupported = $this->apacheSetEnvIsSupported();
$this->putEnvSupported = $this->putEnvIsSupported();
$this->quiet = $quiet;
}
/**
* {@inheritdoc}
*/
public function load(string $path, bool $overwriteExistingVariables = true): array
{
$envVariables = $this->read($path);
foreach ($envVariables as $name => $value) {
if ($overwriteExistingVariables || (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV))) {
$this->setVariable($name, $value);
}
}
return $envVariables;
}
/**
* Returns ENV values as array, but doesn't load them as global variables
*
* @param string $path
*
* @return array
*/
private function read(string $path): array
{
if (!$this->checkFile($path)) {
return [];
}
$lines = file($path, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$envVariables = [];
foreach ($lines as $line) {
if (strpos(trim($line), '#') === 0 || strpos($line, '=') === false) {
continue;
}
list($name, $value) = explode('=', $line, 2);
$name = trim(trim($name), '"');
$value = trim(trim($value), '"');
$envVariables[$name] = $value;
}
return $envVariables;
}
/**
* @return bool
*/
private function apacheSetEnvIsSupported(): bool
{
return function_exists('apache_getenv') && function_exists('apache_setenv');
}
/**
* @return bool
*/
private function putEnvIsSupported(): bool
{
return function_exists('getenv') && function_exists('putenv');
}
/**
* @param string $path
*/
private function checkFile(string $path): bool
{
if ($this->quiet && (!file_exists($path) || !is_readable($path))) {
return false;
}
if (!file_exists($path)) {
throw new \InvalidArgumentException(sprintf('%s does not exist', $path));
}
if (!is_readable($path)) {
throw new \RuntimeException(sprintf('%s file is not readable', $path));
}
return true;
}
/**
* @param string|int $name
* @param string|int|bool $value
*/
private function setVariable($name, $value)
{
if ($this->putEnvSupported) {
putenv(sprintf('%s=%s', $name, $value));
}
if ($this->apacheEnvSupported) {
apache_setenv($name, $value);
}
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Environment;
interface EnvLoaderInterface
{
/**
* Load environment variables from file.
*
* @param string $path
* @param bool $overwriteExistingVariables
*/
public function load(string $path, bool $overwriteExistingVariables = true);
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,94 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
use Monolog\Handler\HandlerInterface;
use Monolog\Logger;
use Monolog\Processor\ProcessIdProcessor;
use Monolog\Processor\PsrLogMessageProcessor;
use PsCheckout\Core\Exception\PsCheckoutException;
use Psr\Log\LoggerInterface;
/**
* Class responsible for create Logger instance.
*/
class LoggerFactory implements LoggerFactoryInterface
{
/**
* @var string
*/
private $name;
/**
* @var HandlerInterface
*/
private $loggerHandler;
/**
* @param string $name
* @param HandlerInterface $loggerHandler
*
* @throws PsCheckoutException
*/
public function __construct(string $name, HandlerInterface $loggerHandler)
{
$this->assertNameIsValid($name);
$this->name = $name;
$this->loggerHandler = $loggerHandler;
}
/**
* @return LoggerInterface
*/
public function build(): LoggerInterface
{
return new Logger(
$this->name,
[
$this->loggerHandler,
],
[
new ProcessIdProcessor(),
new PsrLogMessageProcessor(),
]
);
}
/**
* @param string $name
*
* @throws PsCheckoutException
*/
private function assertNameIsValid(string $name)
{
if (empty($name)) {
throw new PsCheckoutException('Logger name cannot be empty.');
}
if (!is_string($name)) {
throw new PsCheckoutException('Logger name should be a string.');
}
if (!preg_match('/^[a-zA-Z0-9_.-]+$/', $name)) {
throw new PsCheckoutException('Logger name is invalid.');
}
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
use Psr\Log\LoggerInterface;
interface LoggerFactoryInterface
{
/**
* @return LoggerInterface
*/
public function build(): LoggerInterface;
}

View File

@@ -0,0 +1,121 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
use PsCheckout\Infrastructure\Adapter\Configuration;
use PsCheckout\Infrastructure\Adapter\ContextInterface;
use PsCheckout\Utility\Common\DateUtility;
use Symfony\Component\Finder\Finder;
class LoggerFileFinder implements LoggerFileFinderInterface
{
const LOGGER_DIRECTORY_PATH = _PS_ROOT_DIR_ . '/var/logs/';
/**
* @var string
*/
private $moduleName;
/**
* @var Configuration
*/
private $configuration;
/**
* @var ContextInterface
*/
private $context;
public function __construct(
string $moduleName,
ContextInterface $context,
Configuration $configuration
) {
$this->moduleName = $moduleName;
$this->configuration = $configuration;
$this->context = $context;
}
/**
* Get the list of log files matching the module and shop identifiers.
*
* @return array associative array of file names and formatted dates
*/
public function getFiles(): array
{
if (!$this->isLoggerDirectoryReadable()) {
return [];
}
$finder = new Finder();
$fileNames = [];
$fileNamePrefix = $this->generateFileNamePrefix();
// Use Finder to search for files matching the prefix and sort by name
foreach ($finder->files()->in(self::LOGGER_DIRECTORY_PATH)
->name($fileNamePrefix . '*')->sortByName() as $file) {
$fileNames[$file->getFilename()] = $this->formatFileDate($file);
}
return $fileNames;
}
/**
* Check if the logger directory is readable.
*
* @return bool
*/
private function isLoggerDirectoryReadable(): bool
{
return is_readable(self::LOGGER_DIRECTORY_PATH);
}
/**
* Generate the file name prefix based on module name and shop ID.
*
* @return string
*/
private function generateFileNamePrefix(): string
{
return $this->moduleName . '-' . $this->context->getShop()->id . '-';
}
/**
* Format the date of the log file using DateUtility.
*
* @param SplFileInfo $file
*
* @return string
*/
private function formatFileDate($file): string
{
// Extract the raw date from the file name (after the prefix)
$rawDate = str_replace($this->generateFileNamePrefix(), '', $file->getFilename());
// Return the formatted date using the DateUtility class
return DateUtility::formatDate(
$rawDate,
$this->context->getLanguage()->date_format_lite,
$this->configuration->get('PS_TIMEZONE')
);
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
interface LoggerFileFinderInterface
{
/**
* @return array|string[]
*/
public function getFiles(): array;
}

View File

@@ -0,0 +1,131 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
use InvalidArgumentException;
use PsCheckout\Infrastructure\Adapter\ValidateInterface;
use RuntimeException;
use SplFileObject;
class LoggerFileReader implements LoggerFileReaderInterface
{
/**
* @var ValidateInterface
*/
private $validate;
/**
* @var LoggerFileFinderInterface
*/
private $loggerFileFinder;
public function __construct(ValidateInterface $validate, LoggerFileFinderInterface $loggerFileFinder)
{
$this->validate = $validate;
$this->loggerFileFinder = $loggerFileFinder;
}
/**
* {@inheritdoc}
*/
public function read(string $filename, int $offset, int $limit): array
{
$this->validateParams($filename, $offset, $limit);
$logFile = new SplFileObject(LoggerFileFinder::LOGGER_DIRECTORY_PATH . $filename);
if (false === $logFile->isFile()) {
throw new RuntimeException('File not found');
}
$isEndOfFile = true;
$totalFileNewLines = 0;
$currentFileLineNumber = 0;
$fileLines = [];
if (false === $logFile->isReadable()) {
throw new RuntimeException('File is not readable');
}
while ($logFile->valid()) {
$line = $logFile->fgets();
if ($currentFileLineNumber < $offset) {
++$currentFileLineNumber;
continue;
}
if ($totalFileNewLines >= $limit) {
$isEndOfFile = false;
break;
}
if (false === empty($line)) {
$fileLines[] = $line;
++$totalFileNewLines;
++$currentFileLineNumber;
}
}
return [
'filename' => $logFile->getFilename(),
'offset' => $offset,
'limit' => $limit,
'currentOffset' => $offset + $totalFileNewLines,
'eof' => $isEndOfFile,
'lines' => $fileLines,
];
}
/**
* {@inheritdoc}
*/
public function validateFilename(string $filename): void
{
if (empty($filename)
|| !$this->validate->isFileName($filename)
|| preg_match('/\.\.(\/|\\\\)/', $filename)
) {
throw new InvalidArgumentException('Filename is invalid');
}
$files = $this->loggerFileFinder->getFiles();
if (!array_key_exists($filename, $files)) {
throw new InvalidArgumentException('File does not exist');
}
}
private function validateParams(string $filename, int $offset, int $limit): void
{
$this->validateFilename($filename);
if ($offset < 0) {
throw new InvalidArgumentException('Offset must be a positive integer or zero');
}
if ($limit <= 0) {
throw new InvalidArgumentException('Limit must be a positive integer');
}
}
}

View File

@@ -0,0 +1,39 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
use PsCheckout\Core\Exception\PsCheckoutException;
interface LoggerFileReaderInterface
{
/**
* @param string $filename
* @param int $offset
* @param int $limit
*
* @return array
*
* @throws PsCheckoutException
*/
public function read(string $filename, int $offset, int $limit): array;
public function validateFilename(string $filename): void;
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
use Monolog\Handler\HandlerInterface;
use Monolog\Handler\RotatingFileHandler;
use PsCheckout\Core\Settings\Configuration\LoggerConfiguration;
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
use PsCheckout\Infrastructure\Adapter\ContextInterface;
class LoggerHandlerFactory implements LoggerHandlerInterface
{
private $psPath = _PS_ROOT_DIR_;
private $psVersion = _PS_VERSION_;
/**
* @var ConfigurationInterface
*/
private $configuration;
/**
* @var int
*/
private $shopId;
/**
* @var string
*/
private $moduleName;
public function __construct(ConfigurationInterface $configuration, ContextInterface $context, string $moduleName)
{
$this->configuration = $configuration;
$this->shopId = $context->getShop()->id;
$this->moduleName = $moduleName;
}
/**
* {@inheritdoc}
*/
public function build(): HandlerInterface
{
return new RotatingFileHandler(
$this->getPath() . $this->getFileName(),
$this->getMaxFiles(),
$this->getLoggerLevel()
);
}
/**
* {@inheritdoc}
*/
private function getPath(): string
{
if (version_compare($this->psVersion, '1.7.4', '<')) {
return $this->psPath . '/app/logs/';
}
return $this->psPath . '/var/logs/';
}
/**
* @return string
*/
private function getFileName(): string
{
return $this->moduleName . '-' . $this->shopId;
}
/**
* @return int
*/
private function getMaxFiles(): int
{
$maxFiles = (int) $this->configuration->get(LoggerConfiguration::PS_CHECKOUT_LOGGER_MAX_FILES);
if (!$maxFiles) {
return LoggerConfiguration::PS_CHECKOUT_LOGGER_MAX_FILES_DEFAULT;
}
return $maxFiles;
}
/**
* @return int
*/
private function getLoggerLevel(): int
{
$loggerLevel = (int) $this->configuration->get(LoggerConfiguration::PS_CHECKOUT_LOGGER_LEVEL);
if (!$loggerLevel) {
return LoggerConfiguration::LEVEL_ERROR;
}
return $loggerLevel;
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
use Monolog\Handler\HandlerInterface;
interface LoggerHandlerInterface
{
/**
* @return HandlerInterface
*/
public function build(): HandlerInterface;
}

View File

@@ -0,0 +1,71 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Logger;
use Psr\Log\LoggerInterface;
class NullLogger implements LoggerInterface
{
public function emergency($message, array $context = [])
{
// TODO: Implement emergency() method.
}
public function alert($message, array $context = [])
{
// TODO: Implement alert() method.
}
public function critical($message, array $context = [])
{
// TODO: Implement critical() method.
}
public function error($message, array $context = [])
{
// TODO: Implement error() method.
}
public function warning($message, array $context = [])
{
// TODO: Implement warning() method.
}
public function notice($message, array $context = [])
{
// TODO: Implement notice() method.
}
public function info($message, array $context = [])
{
// TODO: Implement info() method.
}
public function debug($message, array $context = [])
{
// TODO: Implement debug() method.
}
public function log($level, $message, array $context = [])
{
// TODO: Implement log() method.
}
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;

View File

@@ -0,0 +1,51 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use DbQuery;
class AddressRepository implements AddressRepositoryInterface
{
/**
* @var \Db
*/
private $db;
public function __construct(\Db $db)
{
$this->db = $db;
}
/**
* {@inheritDoc}
*/
public function getAddressIdByAliasAndCustomer(string $alias, int $idCustomer): int
{
$query = new DbQuery();
$query->select('id_address');
$query->from('address');
$query->where('alias = \'' . pSQL($alias) . '\'');
$query->where('id_customer = ' . $idCustomer);
$query->where('deleted = 0');
return (int) $this->db->getValue($query);
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface AddressRepositoryInterface
{
/**
* @param string $alias
* @param int $customerId
*
* @return int
*/
public function getAddressIdByAliasAndCustomer(string $alias, int $customerId): int;
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
class CartRepository extends CollectionRepository implements CartRepositoryInterface
{
public function __construct()
{
parent::__construct(\Cart::class);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface CartRepositoryInterface
{
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use PrestaShopCollection;
abstract class CollectionRepository implements ReadOnlyCollectionRepositoryInterface
{
/**
* @var string
*/
private $fullyClassifiedClassName;
public function __construct($fullyClassifiedClassName)
{
$this->fullyClassifiedClassName = $fullyClassifiedClassName;
}
/**
* {@inheritDoc}
*/
public function getOneBy(array $keyValueCriteria, $langId = null)
{
$psCollection = new \PrestaShopCollection($this->fullyClassifiedClassName, $langId);
foreach ($keyValueCriteria as $field => $value) {
$psCollection = $psCollection->where($field, '=', $value);
}
$first = $psCollection->getFirst();
return $first ?: null;
}
/** {@inheritDoc} */
public function getAllBy(array $keyValueCriteria, $langId = null): array
{
$psCollection = new PrestaShopCollection($this->fullyClassifiedClassName, $langId);
foreach ($keyValueCriteria as $field => $value) {
$psCollection = $psCollection->where($field, '=', $value);
}
return $psCollection->getResults() ?? [];
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Db;
use PsCheckout\Infrastructure\Adapter\ConfigurationInterface;
use Shop;
class ConfigurationRepository implements ConfigurationRepositoryInterface
{
/**
* @var Db
*/
private $db;
/**
* @var ConfigurationInterface
*/
private $configuration;
public function __construct(
Db $db,
ConfigurationInterface $configuration
) {
$this->db = $db;
$this->configuration = $configuration;
}
/** {@inheritdoc} */
public function handleConfigurationOnShopToggle()
{
// This is the same query as in Shop::isFeatureActive()
// Due to static cache in Shop::isFeatureActive(), we have to execute this to retrieve an accurate value
$isMultiShopEnabled = (bool) $this->db->getValue('SELECT value FROM ' . _DB_PREFIX_ . 'configuration WHERE name = "PS_MULTISHOP_FEATURE_ACTIVE"')
&& $this->db->getValue('SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'shop') > 1;
// When values are equal, it means there is nothing to do
// because the multistore value in the shop has not changed and configuration values are correct
if (Shop::isFeatureActive() === $isMultiShopEnabled) {
return;
}
$defaultShop = new Shop($this->configuration->getInteger('PS_SHOP_DEFAULT'));
$shopIdCondition = $isMultiShopEnabled ? (int) $defaultShop->id : 'NULL';
$shopGroupIdCondition = $isMultiShopEnabled ? (int) $defaultShop->id_shop_group : 'NULL';
$this->db->execute(
'UPDATE ' . _DB_PREFIX_ . 'configuration
SET id_shop = ' . $shopIdCondition . ', id_shop_group = ' . $shopGroupIdCondition . '
WHERE name LIKE "PS_CHECKOUT_%"
AND name NOT LIKE "PS_CHECKOUT_STATE_%"
AND name NOT LIKE "PS_CHECKOUT_LOGGER_%"
AND id_shop ' . ($isMultiShopEnabled ? 'IS NULL' : '= ' . (int) $defaultShop->id)
);
}
}

View File

@@ -0,0 +1,31 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface ConfigurationRepositoryInterface
{
/**
* @return void
*
* @throws \PrestaShopDatabaseException
*/
public function handleConfigurationOnShopToggle();
}

View File

@@ -0,0 +1,95 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use DbQuery;
class CountryRepository implements CountryRepositoryInterface
{
/**
* @var string
*/
private $moduleName;
public function __construct($moduleName)
{
$this->moduleName = $moduleName;
}
/**
* {@inheritdoc}
*/
public function getModuleCountryCodes(bool $onlyActive = true): array
{
$active = $onlyActive ? ' AND c.active = 1' : null;
$shopCodes = \Db::getInstance()->executeS(
'
SELECT c.iso_code
FROM ' . _DB_PREFIX_ . 'country c
JOIN ' . _DB_PREFIX_ . 'module_country mc ON mc.id_country = c.id_country
JOIN ' . _DB_PREFIX_ . 'module m ON m.id_module = mc.id_module
WHERE m.name = "' . pSQL($this->moduleName) . '"
AND mc.id_shop = ' . (int) \Context::getContext()->shop->id
. $active
);
return $shopCodes ?: [];
}
/**
* {@inheritdoc}
*/
public function deleteModuleCountryByIsoCode(string $isoCode): bool
{
return \Db::getInstance()->execute(
'
DELETE mc FROM ' . _DB_PREFIX_ . 'module_country AS mc
INNER JOIN ' . _DB_PREFIX_ . 'country AS c ON mc.id_country = c.id_country
WHERE c.iso_code = "' . pSQL($isoCode) . '"
AND mc.id_module = ' . (int) \Module::getModuleIdByName($this->moduleName) . '
AND mc.id_shop = ' . (int) \Context::getContext()->shop->id
);
}
/**
* {@inheritdoc}
*/
public function getCountryIsoCodeById(int $idCountry): string
{
return \Country::getIsoById($idCountry) ?: '';
}
/**
* {@inheritDoc}
*/
public function getStateId(int $idCountry, string $state)
{
$query = new DbQuery();
$query->select('id_state');
$query->from('state');
$query->where('name LIKE \'%' . pSQL($state) . '%\'');
$query->where('active = 1');
$query->where('id_country = ' . (int) $idCountry);
return (int) \Db::getInstance()->getValue($query) ?? null;
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface CountryRepositoryInterface
{
/**
* Get the module ISO country codes.
*
* @param bool $onlyActive
*
* @return array
*/
public function getModuleCountryCodes(bool $onlyActive = true): array;
/**
* Delete module country by ISO code.
*
* @param string $isoCode
*
* @return bool
*/
public function deleteModuleCountryByIsoCode(string $isoCode): bool;
/**
* @param int $idCountry
*
* @return string
*/
public function getCountryIsoCodeById(int $idCountry): string;
/**
* @param int $idCountry
* @param string $state
*
* @return int|null
*/
public function getStateId(int $idCountry, string $state);
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Currency as PrestaShopCurrency;
class CurrencyRepository implements CurrencyRepositoryInterface
{
/**
* @var string
*/
private $moduleName;
public function __construct(string $moduleName)
{
$this->moduleName = $moduleName;
}
/**
* {@inheritdoc}
*/
public function getModuleCurrencyCodes(bool $onlyActive = true): array
{
$active = $onlyActive ? ' AND c.active = 1' : null;
$shopCodes = \Db::getInstance()->executeS(
'
SELECT c.iso_code
FROM ' . _DB_PREFIX_ . 'currency c
JOIN ' . _DB_PREFIX_ . 'module_currency mc ON mc.id_currency = c.id_currency
JOIN ' . _DB_PREFIX_ . 'module m ON m.id_module = mc.id_module
WHERE m.name = "' . $this->moduleName . '"
AND mc.id_shop = ' . (int) \Context::getContext()->shop->id
. $active
);
return $shopCodes ?: [];
}
/**
* {@inheritdoc}
*/
public function deleteModuleCurrencyByIsoCode(string $isoCode): bool
{
return \Db::getInstance()->execute(
'
DELETE mc FROM ' . _DB_PREFIX_ . 'module_currency AS mc
INNER JOIN ' . _DB_PREFIX_ . 'currency AS c ON c.id_currency = mc.id_currency
WHERE c.iso_code = "' . pSQL($isoCode) . '"
AND mc.id_module = ' . (int) \Module::getModuleIdByName($this->moduleName) . '
AND mc.id_shop = ' . (int) \Context::getContext()->shop->id
) ?: false;
}
/**
* {@inheritDoc}
*/
public function getIdByIsoCode(string $isoCode, int $shopId = 0): int
{
return (int) PrestaShopCurrency::getIdByIsoCode($isoCode, $shopId);
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface CurrencyRepositoryInterface
{
/**
* Get the module ISO currency codes.
*
* @param bool $onlyActive
*
* @return array
*/
public function getModuleCurrencyCodes(bool $onlyActive = true): array;
/**
* Delete module currency by ISO code.
*
* @param string $isoCode
*
* @return bool
*/
public function deleteModuleCurrencyByIsoCode(string $isoCode): bool;
/**
* @param string $isoCode
* @param int $shopId
*
* @return int
*/
public function getIdByIsoCode(string $isoCode, int $shopId = 0): int;
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
class CustomerRepository extends CollectionRepository implements CustomerRepositoryInterface
{
public function __construct()
{
parent::__construct(\Customer::class);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface CustomerRepositoryInterface extends ReadOnlyCollectionRepositoryInterface
{
}

View File

@@ -0,0 +1,147 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use PsCheckout\Core\FundingSource\Repository\FundingSourceRepositoryInterface;
use PsCheckout\Core\Settings\Configuration\FundingSourceConfig;
class FundingSourceRepository implements FundingSourceRepositoryInterface
{
/**
* @var \Db
*/
private $db;
const TABLE_NAME = 'pscheckout_funding_source';
public function __construct(\Db $db)
{
$this->db = $db;
}
/**
* {@inheritdoc}
*/
public function getOneBy(array $keyValueCriteria)
{
$query = new \DbQuery();
$query->select('*')
->from(self::TABLE_NAME);
foreach ($keyValueCriteria as $key => $value) {
$query->where("$key = '" . pSQL($value) . "'");
}
$result = $this->db->getRow($query);
return $result ?: null;
}
/**
* {@inheritdoc}
*/
public function getAllForSpecificShop(int $shopId): array
{
$query = new \DbQuery();
$query->select('*')
->from(self::TABLE_NAME)
->where('id_shop = ' . (int) $shopId)
->orderBy('position ASC');
$result = $this->db->executeS($query);
return $result ?: [];
}
/**
* {@inheritdoc}
*/
public function getAllActiveForSpecificShop(int $shopId): array
{
$query = new \DbQuery();
$query->select('*')
->from(self::TABLE_NAME)
->where('active = 1')
->where('id_shop = ' . (int) $shopId)
->orderBy('position ASC');
$result = $this->db->executeS($query);
return $result ?: [];
}
/**
* {@inheritdoc}
*/
public function upsert(array $data, int $shopId): bool
{
if ($this->getOneBy(['name' => $data['name'], 'id_shop' => (int) $shopId])) {
return (bool) $this->db->update(
self::TABLE_NAME,
[
'position' => (int) $data['position'],
'active' => (int) $data['isEnabled'],
],
'`name` = "' . pSQL($data['name']) . '" AND `id_shop` = ' . (int) $shopId
);
}
return (bool) $this->db->insert(
self::TABLE_NAME,
[
'name' => pSQL($data['name']),
'position' => (int) $data['position'],
'active' => (int) $data['isEnabled'],
'id_shop' => (int) $shopId,
]
);
}
/**
* {@inheritdoc}
*/
public function populateWithDefaultValues(int $shopId)
{
$positionCounter = 0;
foreach (FundingSourceConfig::FUNDING_SOURCES as $name) {
$query = new \DbQuery();
$query->select('*')
->from(self::TABLE_NAME)
->where('name = \'' . pSQL($name) . '\'')
->where('id_shop = ' . $shopId);
// Prepare the data to insert or update
$data = [
'name' => pSQL($name),
'active' => (int) !in_array($name, ['google_pay', 'apple_pay', 'venmo']),
'position' => ++$positionCounter,
'id_shop' => (int) $shopId,
];
if ($this->db->getRow($query)) {
\Db::getInstance()->update(self::TABLE_NAME, $data, 'name = \'' . pSQL($name) . '\' AND id_shop = ' . (int) $shopId);
} else {
\Db::getInstance()->insert(self::TABLE_NAME, $data);
}
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
class GenderRepository implements GenderRepositoryInterface
{
/**
* {@inheritDoc}
*/
public function getGenderNameById($idGender, $idLanguage = null)
{
return (new \Gender($idGender, $idLanguage))->name ?: '';
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface GenderRepositoryInterface
{
/**
* @param int $idGender
* @param int $idLanguage
*
* @return string
*/
public function getGenderNameById($idGender, $idLanguage);
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
class LanguageRepository extends CollectionRepository implements LanguageRepositoryInterface
{
public function __construct()
{
parent::__construct(\Language::class);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface LanguageRepositoryInterface extends ReadOnlyCollectionRepositoryInterface
{
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Exception;
use OrderHistory;
use PsCheckout\Core\Order\Exception\OrderException;
class OrderHistoryRepository implements OrderHistoryRepositoryInterface
{
/**
* {@inheritDoc}
*/
public function create(int $orderStateId, int $orderId, bool $useExistingPayments): bool
{
$history = new OrderHistory();
$history->id_order = $orderId;
try {
$history->changeIdOrderState($orderStateId, $orderId, $useExistingPayments);
$historyAdded = $history->addWithemail(true);
} catch (Exception $exception) {
throw new OrderException(sprintf('Failed to update status or send email when changing OrderState #%d of Order #%d.', $orderStateId, $orderId), OrderException::FAILED_UPDATE_ORDER_STATUS, $exception);
}
if (!$historyAdded) {
throw new OrderException(sprintf('Failed to update status or send email when changing OrderState #%d of Order #%d.', $orderStateId, $orderId), OrderException::FAILED_UPDATE_ORDER_STATUS);
}
return $historyAdded;
}
}

View File

@@ -0,0 +1,37 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use PsCheckout\Core\Order\Exception\OrderException;
interface OrderHistoryRepositoryInterface
{
/**
* @param int $orderStateId
* @param int $orderId
* @param bool $useExistingPayments
*
* @return bool
*
* @throws OrderException
*/
public function create(int $orderStateId, int $orderId, bool $useExistingPayments): bool;
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
class OrderRepository extends CollectionRepository implements OrderRepositoryInterface
{
public function __construct()
{
parent::__construct(\Order::class);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface OrderRepositoryInterface
{
}

View File

@@ -0,0 +1,29 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
class OrderStateRepository extends CollectionRepository implements OrderStateRepositoryInterface
{
public function __construct()
{
parent::__construct(\OrderState::class);
}
}

View File

@@ -0,0 +1,25 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
interface OrderStateRepositoryInterface
{
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Db;
use DbQuery;
use Exception;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Core\PayPal\Customer\Repository\PayPalCustomerRepositoryInterface;
class PayPalCustomerRepository implements PayPalCustomerRepositoryInterface
{
const TABLE_NAME = 'pscheckout_customer';
/**
* @var \Db
*/
private $db;
public function __construct(Db $db)
{
$this->db = $db;
}
/**
* {@inheritDoc}
*/
public function getPayPalCustomerIdByCustomerId(int $customerId)
{
try {
$query = new DbQuery();
$query->select('`paypal_customer_id`');
$query->from(self::TABLE_NAME);
$query->where(sprintf('`id_customer` = %d', (int) $customerId));
$payPalCustomerId = $this->db->getValue($query);
return $payPalCustomerId ?? null;
} catch (Exception $exception) {
throw new PsCheckoutException('Failed to find PayPal Customer ID', 0, $exception);
}
}
/**
* {@inheritDoc}
*/
public function save(int $customerId, string $paypalCustomerId)
{
try {
$this->db->insert(
self::TABLE_NAME,
[
'id_customer' => $customerId,
'paypal_customer_id' => pSQL($paypalCustomerId),
],
false,
true,
\Db::REPLACE
);
} catch (Exception $exception) {
throw new PsCheckoutException('Failed to save PayPal Customer ID', 0, $exception);
}
}
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Exception;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Core\PayPal\Order\Entity\PayPalOrderAuthorization;
use PsCheckout\Core\PayPal\Order\Repository\PayPalOrderAuthorizationRepositoryInterface;
class PayPalOrderAuthorizationRepository implements PayPalOrderAuthorizationRepositoryInterface
{
const TABLE_NAME = 'pscheckout_authorization';
/**
* @var \Db
*/
private $db;
public function __construct(\Db $db)
{
$this->db = $db;
}
/**
* {@inheritDoc}
*/
public function save(PayPalOrderAuthorization $payPalOrderAuthorization)
{
try {
return $this->db->insert(
self::TABLE_NAME,
[
'id' => pSQL($payPalOrderAuthorization->getId()),
'id_order' => pSQL($payPalOrderAuthorization->getIdOrder()),
'status' => pSQL($payPalOrderAuthorization->getStatus()),
'expiration_time' => pSQL($payPalOrderAuthorization->getExpirationTime()),
'seller_protection' => pSQL(json_encode($payPalOrderAuthorization->getSellerProtection())),
],
false,
true,
\Db::REPLACE
);
} catch (Exception $exception) {
throw new PsCheckoutException('Error while saving PayPal Order Authorization', 0, $exception);
}
}
}

View File

@@ -0,0 +1,117 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Exception;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Core\PayPal\Order\Entity\PayPalOrderCapture;
use PsCheckout\Core\PayPal\Order\Repository\PayPalOrderCaptureRepositoryInterface;
class PayPalOrderCaptureRepository implements PayPalOrderCaptureRepositoryInterface
{
const TABLE_NAME = 'pscheckout_capture';
/**
* @var \Db
*/
private $db;
public function __construct(\Db $db)
{
$this->db = $db;
}
/**
* {@inheritDoc}
*/
public function save(PayPalOrderCapture $payPalOrderCapture)
{
try {
return $this->db->insert(
self::TABLE_NAME,
[
'id' => pSQL($payPalOrderCapture->getId()),
'id_order' => pSQL($payPalOrderCapture->getIdOrder()),
'status' => pSQL($payPalOrderCapture->getStatus()),
'final_capture' => (int) $payPalOrderCapture->getFinalCapture(),
'created_at' => pSQL($payPalOrderCapture->getCreatedAt()),
'updated_at' => pSQL($payPalOrderCapture->getUpdatedAt()),
'seller_protection' => pSQL(json_encode($payPalOrderCapture->getSellerProtection())),
'seller_receivable_breakdown' => pSQL(json_encode($payPalOrderCapture->getSellerReceivableBreakdown())),
],
false,
true,
\Db::REPLACE
);
} catch (Exception $exception) {
throw new PsCheckoutException('Error while saving PayPal Order Capture', 0, $exception);
}
}
/**
* {@inheritDoc}
*/
public function getByOrderId(string $payPalOrderId): array
{
try {
$query = new \DbQuery();
$query->select('*');
$query->from(self::TABLE_NAME);
$query->where('id_order = "' . pSQL($payPalOrderId) . '"');
$capturesData = $this->db->executeS($query);
if (empty($capturesData)) {
return [];
}
$captures = [];
foreach ($capturesData as $captureData) {
$captures[] = $this->buildPayPalOrderCapture($captureData);
}
return $captures;
} catch (Exception $exception) {
throw new PsCheckoutException('Error while getting PayPal Order Captures', 0, $exception);
}
}
/**
* Build PayPalOrderCapture entity from database data
*
* @param array $captureData
*
* @return PayPalOrderCapture
*/
private function buildPayPalOrderCapture(array $captureData): PayPalOrderCapture
{
return new PayPalOrderCapture(
$captureData['id'],
$captureData['id_order'],
$captureData['status'],
$captureData['created_at'],
$captureData['updated_at'],
json_decode($captureData['seller_protection'], true) ?: [],
json_decode($captureData['seller_receivable_breakdown'], true) ?: [],
(bool) $captureData['final_capture']
);
}
}

View File

@@ -0,0 +1,61 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Exception;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Core\PayPal\Order\Repository\PayPalOrderMatrixRepositoryInterface;
class PayPalOrderMatrixRepository implements PayPalOrderMatrixRepositoryInterface
{
const TABLE_NAME = 'pscheckout_order_matrice';
/**
* @var \Db
*/
private $db;
public function __construct(\Db $db)
{
$this->db = $db;
}
/**
* {@inheritDoc}
*/
public function upsert(string $payPalOrderId, int $orderId)
{
try {
$this->db->insert(
self::TABLE_NAME,
[
'id_order_prestashop' => $orderId,
'id_order_paypal' => pSQL($payPalOrderId),
],
false,
true,
\Db::REPLACE
);
} catch (Exception $exception) {
throw new PsCheckoutException('Error while saving PayPal Order Matrix', 0, $exception);
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Exception;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Core\PayPal\Order\Entity\PayPalOrderPurchaseUnit;
use PsCheckout\Core\PayPal\Order\Repository\PayPalOrderPurchaseUnitRepositoryInterface;
class PayPalOrderPurchaseUnitRepository implements PayPalOrderPurchaseUnitRepositoryInterface
{
const TABLE_NAME = 'pscheckout_purchase_unit';
/**
* @var \Db
*/
private $db;
public function __construct(\Db $db)
{
$this->db = $db;
}
/**
* {@inheritDoc}
*/
public function save(PayPalOrderPurchaseUnit $payPalOrderPurchaseUnit)
{
try {
$this->db->insert(
self::TABLE_NAME,
[
'id_order' => pSQL($payPalOrderPurchaseUnit->getIdOrder()),
'checksum' => pSQL($payPalOrderPurchaseUnit->getChecksum()),
'reference_id' => pSQL($payPalOrderPurchaseUnit->getReferenceId()),
'items' => pSQL(json_encode($payPalOrderPurchaseUnit->getItems())),
],
false,
true,
\Db::REPLACE
);
} catch (Exception $exception) {
throw new PsCheckoutException('Error while saving PayPal Order Purchase Unit', 0, $exception);
}
}
}

View File

@@ -0,0 +1,68 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PsCheckout\Infrastructure\Repository;
use Exception;
use PsCheckout\Core\Exception\PsCheckoutException;
use PsCheckout\Core\PayPal\Order\Entity\PayPalOrderRefund;
use PsCheckout\Core\PayPal\Order\Repository\PayPalOrderRefundRepositoryInterface;
class PayPalOrderRefundRepository implements PayPalOrderRefundRepositoryInterface
{
const TABLE_NAME = 'pscheckout_refund';
/**
* @var \Db
*/
private $db;
public function __construct(\Db $db)
{
$this->db = $db;
}
/**
* {@inheritDoc}
*/
public function save(PayPalOrderRefund $payPalOrderRefund)
{
try {
return $this->db->insert(
self::TABLE_NAME,
[
'id' => pSQL($payPalOrderRefund->getId()),
'id_order' => pSQL($payPalOrderRefund->getIdOrder()),
'status' => pSQL($payPalOrderRefund->getStatus()),
'invoice_id' => pSQL($payPalOrderRefund->getStatus()),
'custom_id' => pSQL($payPalOrderRefund->getCustomId()),
'acquirer_reference_number' => pSQL($payPalOrderRefund->getAcquirerReferenceNumber()),
'seller_payable_breakdown' => pSQL(json_encode($payPalOrderRefund->getSellerPayableBreakdown())),
'id_order_slip' => (int) $payPalOrderRefund->getIdOrderSlip(),
],
false,
true,
\Db::REPLACE
);
} catch (Exception $exception) {
throw new PsCheckoutException('Error while saving PayPal Order Refund', 0, $exception);
}
}
}

Some files were not shown because too many files have changed in this diff Show More