Skip to content

Commit

Permalink
Merge pull request #1146 from PrestaShopCorp/release/8.3.4.1
Browse files Browse the repository at this point in the history
Release 8.3.5.0
  • Loading branch information
Matt75 committed Oct 25, 2023
2 parents 9139920 + 09a0df4 commit 4ef6518
Show file tree
Hide file tree
Showing 21 changed files with 439 additions and 118 deletions.
18 changes: 18 additions & 0 deletions classes/PsCheckoutCart.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class PsCheckoutCart extends ObjectModel
*/
public $paypal_authorization_expire;

/**
* @var string|null PayPal environment information
*/
public $environment = 'LIVE';

/**
* @var bool
*/
Expand Down Expand Up @@ -147,6 +152,11 @@ class PsCheckoutCart extends ObjectModel
'allow_null' => true,
'required' => false,
],
'environment' => [
'type' => self::TYPE_STRING,
'allow_null' => true,
'required' => false,
],
'isExpressCheckout' => [
'type' => self::TYPE_BOOL,
'validate' => 'isBool',
Expand Down Expand Up @@ -246,6 +256,14 @@ public function getPaypalAuthorizationExpireDate()
return $this->paypal_authorization_expire;
}

/**
* @return string
*/
public function getEnvironment()
{
return $this->environment === 'SANDBOX' ? $this->environment : 'LIVE';
}

/**
* @return bool
*/
Expand Down
2 changes: 1 addition & 1 deletion config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<module>
<name>ps_checkout</name>
<displayName><![CDATA[PrestaShop Checkout]]></displayName>
<version><![CDATA[8.3.4.0]]></version>
<version><![CDATA[8.3.5.0]]></version>
<description><![CDATA[Provide the most commonly used payment methods to your customers in this all-in-one module, and manage all your sales in a centralized interface.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[payments_gateways]]></tab>
Expand Down
20 changes: 20 additions & 0 deletions controllers/admin/AdminAjaxPrestashopCheckoutController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use PrestaShop\Module\PrestashopCheckout\Order\State\Exception\OrderStateException;
use PrestaShop\Module\PrestashopCheckout\Order\State\OrderStateInstaller;
use PrestaShop\Module\PrestashopCheckout\Order\State\Service\OrderStateMapper;
use PrestaShop\Module\PrestashopCheckout\PayPal\Mode;
use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration;
use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalOrderProvider;
use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalPayLaterConfiguration;
Expand Down Expand Up @@ -377,6 +378,24 @@ public function ajaxProcessFetchOrder()
}
}

/** @var PayPalConfiguration $configurationPayPal */
$configurationPayPal = $this->module->getService('ps_checkout.paypal.configuration');

if ($configurationPayPal->getPaymentMode() !== $psCheckoutCart->getEnvironment()) {
http_response_code(422);
$this->ajaxDie(json_encode([
'status' => false,
'errors' => [
strtr(
$this->l('PayPal Order [PAYPAL_ORDER_ID] is not in the same environment as PrestaShop Checkout'),
[
'[PAYPAL_ORDER_ID]' => $psCheckoutCart->paypal_order,
]
),
],
]));
}

/** @var PayPalOrderProvider $paypalOrderProvider */
$paypalOrderProvider = $this->module->getService('ps_checkout.paypal.provider.order');

Expand All @@ -398,6 +417,7 @@ public function ajaxProcessFetchOrder()
'orderPaymentDisplayName' => $fundingSourceTranslationProvider->getPaymentMethodName($psCheckoutCart->paypal_funding),
'orderPaymentLogoUri' => $this->module->getPathUri() . 'views/img/' . $psCheckoutCart->paypal_funding . '.svg',
'psCheckoutCart' => $psCheckoutCart,
'isProductionEnv' => $psCheckoutCart->getEnvironment() === Mode::LIVE,
]);

$this->ajaxDie(json_encode([
Expand Down
5 changes: 5 additions & 0 deletions controllers/front/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException;
use PrestaShop\Module\PrestashopCheckout\Handler\CreatePaypalOrderHandler;
use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository;
use Psr\SimpleCache\CacheInterface;

/**
* This controller receive ajax call on customer click on a payment button
Expand Down Expand Up @@ -118,6 +119,10 @@ public function postProcess()
throw new PsCheckoutException(sprintf('Unable to patch PayPal Order - Exception %s : %s', $response['exceptionCode'], $response['exceptionMessage']), PsCheckoutException::PSCHECKOUT_UPDATE_ORDER_HANDLE_ERROR);
}

/** @var CacheInterface $orderPayPalCache */
$orderPayPalCache = $this->module->getService('ps_checkout.cache.paypal.order');
$orderPayPalCache->delete($psCheckoutCart->getPaypalOrderId());

$this->module->getLogger()->info(
'PayPal Order patched',
[
Expand Down
9 changes: 8 additions & 1 deletion controllers/front/create.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PrestaShop\Module\PrestashopCheckout\Controller\AbstractFrontController;
use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException;
use PrestaShop\Module\PrestashopCheckout\Handler\CreatePaypalOrderHandler;
use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalConfiguration;
use PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository;

/**
Expand Down Expand Up @@ -145,6 +146,8 @@ public function postProcess()
$orderId = isset($bodyValues['orderID']) ? $bodyValues['orderID'] : null;
$isExpressCheckout = isset($bodyValues['isExpressCheckout']) && $bodyValues['isExpressCheckout'];
$isHostedFields = isset($bodyValues['isHostedFields']) && $bodyValues['isHostedFields'];
/** @var PayPalConfiguration $configuration */
$configuration = $this->module->getService('ps_checkout.paypal.configuration');

$this->module->getLogger()->info(
'PayPal Order created',
Expand All @@ -154,6 +157,9 @@ public function postProcess()
'isExpressCheckout' => $isExpressCheckout,
'isHostedFields' => $isHostedFields,
'id_cart' => (int) $this->context->cart->id,
'amount' => $this->context->cart->getOrderTotal(true, Cart::BOTH),
'environment' => $configuration->getPaymentMode(),
'intent' => $configuration->getIntent(),
]
);

Expand All @@ -165,9 +171,10 @@ public function postProcess()
$psCheckoutCart->paypal_funding = $fundingSource;
$psCheckoutCart->paypal_order = $response['body']['id'];
$psCheckoutCart->paypal_status = $response['body']['status'];
$psCheckoutCart->paypal_intent = 'AUTHORIZE' === Configuration::get('PS_CHECKOUT_INTENT') ? 'AUTHORIZE' : 'CAPTURE';
$psCheckoutCart->paypal_intent = $configuration->getIntent();
$psCheckoutCart->paypal_token = $response['body']['client_token'];
$psCheckoutCart->paypal_token_expire = (new DateTime())->modify('+3550 seconds')->format('Y-m-d H:i:s');
$psCheckoutCart->environment = $configuration->getPaymentMode();
$psCheckoutCart->isExpressCheckout = isset($bodyValues['isExpressCheckout']) && $bodyValues['isExpressCheckout'];
$psCheckoutCart->isHostedFields = isset($bodyValues['isHostedFields']) && $bodyValues['isHostedFields'];
$psCheckoutCartRepository->save($psCheckoutCart);
Expand Down
62 changes: 43 additions & 19 deletions controllers/front/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,29 @@ class Ps_CheckoutValidateModuleFrontController extends AbstractFrontController
public function postProcess()
{
try {
$bodyContent = file_get_contents('php://input');

if (empty($bodyContent)) {
$this->exitWithResponse([
'httpCode' => 400,
'body' => 'Payload invalid',
]);
}

$bodyValues = json_decode($bodyContent, true);

if (empty($bodyValues)) {
$this->exitWithResponse([
'httpCode' => 400,
'body' => 'Payload invalid',
]);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$bodyContent = file_get_contents('php://input');

if (empty($bodyContent)) {
$this->exitWithResponse([
'httpCode' => 400,
'body' => 'Payload invalid',
]);
}

$bodyValues = json_decode($bodyContent, true);

if (empty($bodyValues)) {
$this->exitWithResponse([
'httpCode' => 400,
'body' => 'Payload invalid',
]);
}
} else {
$bodyValues = [
'orderID' => Tools::getValue('token'),
'payerID' => Tools::getValue('PayerID'),
];
}

if (empty($bodyValues['orderID']) || false === Validate::isGenericName($bodyValues['orderID'])) {
Expand Down Expand Up @@ -94,9 +101,9 @@ public function postProcess()
$eventDispatcher->dispatch(new CheckoutCompletedEvent(
$psCheckoutCart->getIdCart(),
$this->paypalOrderId,
(isset($bodyValues['fundingSource']) && Validate::isGenericName($bodyValues['fundingSource'])) ? $bodyValues['fundingSource'] : null,
isset($bodyValues['isExpressCheckout']) && $bodyValues['isExpressCheckout'],
isset($bodyValues['isHostedFields']) && $bodyValues['isHostedFields']
(isset($bodyValues['fundingSource']) && Validate::isGenericName($bodyValues['fundingSource'])) ? $bodyValues['fundingSource'] : $psCheckoutCart->getPaypalFundingSource(),
isset($bodyValues['isExpressCheckout']) && $bodyValues['isExpressCheckout'] || $psCheckoutCart->isExpressCheckout(),
isset($bodyValues['isHostedFields']) && $bodyValues['isHostedFields'] || $psCheckoutCart->isHostedFields()
));

$this->sendOkResponse($this->generateResponse());
Expand Down Expand Up @@ -200,6 +207,23 @@ private function sendOkResponse($response)

$cart = new Cart($psCheckoutCart->getIdCart());

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
Tools::redirect($this->context->link->getPageLink(
'order-confirmation',
true,
(int) $order->id_lang,
[
'paypal_status' => $response['status'],
'paypal_order' => $response['paypalOrderId'],
'paypal_transaction' => $response['transactionIdentifier'],
'id_cart' => $psCheckoutCart->getIdCart(),
'id_module' => (int) $this->module->id,
'id_order' => (int) $order->id,
'key' => $cart->secure_key,
]
));
}

$this->exitWithResponse([
'status' => true,
'httpCode' => 200,
Expand Down

0 comments on commit 4ef6518

Please sign in to comment.