Skip to content

Commit

Permalink
Remove PayPal Client Token
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt75 committed Feb 1, 2024
1 parent 07cd957 commit a7c8e8d
Show file tree
Hide file tree
Showing 11 changed files with 0 additions and 611 deletions.
13 changes: 0 additions & 13 deletions config/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,6 @@ services:
arguments:
- "@ps_checkout.cache.paypal.order"

ps_checkout.paypal.provider.client_token:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\PayPalClientTokenProvider'
public: true
arguments:
- "@ps_checkout.repository.pscheckoutcart"

ps_checkout.prestashop.router:
class: 'PrestaShop\Module\PrestashopCheckout\Routing\Router'
public: true
Expand Down Expand Up @@ -469,7 +463,6 @@ services:
PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentRefundedQuery: "ps_checkout.query.handler.order.get_order_for_payment_refunded"
PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForPaymentReversedQuery: "ps_checkout.query.handler.order.get_order_for_payment_reversed"
PrestaShop\Module\PrestashopCheckout\Order\Query\GetOrderForApprovalReversedQuery: "ps_checkout.query.handler.order.get_order_for_approval_reversed"
PrestaShop\Module\PrestashopCheckout\PayPal\Identity\Query\GetClientTokenPayPalQuery: "ps_checkout.query.handler.paypal.identity.get_client_token"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetCurrentPayPalOrderStatusQuery: "ps_checkout.query.handler.paypal.order.get_current_paypal_order_status"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForCheckoutCompletedQuery: "ps_checkout.query.handler.paypal.order.get_paypal_order_for_checkout_completed"
PrestaShop\Module\PrestashopCheckout\PayPal\Order\Query\GetPayPalOrderForOrderConfirmationQuery: "ps_checkout.query.handler.paypal.order.get_paypal_order_for_order_confirmation"
Expand Down Expand Up @@ -618,12 +611,6 @@ services:
arguments:
- "@ps_checkout.repository.pscheckoutcart"

ps_checkout.query.handler.paypal.identity.get_client_token:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Identity\QueryHandler\GetClientTokenPayPalQueryHandler'
public: true
arguments:
- "@ps_checkout.event.dispatcher"

ps_checkout.query.handler.paypal.order.get_paypal_order_for_checkout_completed:
class: 'PrestaShop\Module\PrestashopCheckout\PayPal\Order\QueryHandler\GetPayPalOrderForCheckoutCompletedQueryHandler'
public: true
Expand Down
11 changes: 0 additions & 11 deletions controllers/front/token.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/

use PrestaShop\Module\PrestashopCheckout\Controller\AbstractFrontController;
use PrestaShop\Module\PrestashopCheckout\PayPal\PayPalClientTokenProvider;

/**
* This controller receive ajax call to retrieve a PayPal Client Token
Expand All @@ -46,9 +45,6 @@ public function postProcess()
]);
}

/** @var PayPalClientTokenProvider $clientTokenProvider */
$clientTokenProvider = $this->module->getService('ps_checkout.paypal.provider.client_token');

/** @var \PrestaShop\Module\PrestashopCheckout\Repository\PsCheckoutCartRepository $psCheckoutCartRepository */
$psCheckoutCartRepository = $this->module->getService('ps_checkout.repository.pscheckoutcart');

Expand All @@ -60,13 +56,6 @@ public function postProcess()
$psCheckoutCart->id_cart = (int) $this->context->cart->id;
}

if ($psCheckoutCart->isPaypalClientTokenExpired()) {
$psCheckoutCart->paypal_order = '';
$psCheckoutCart->paypal_token = $clientTokenProvider->getPayPalClientToken();
$psCheckoutCart->paypal_token_expire = (new DateTime())->modify('+3550 seconds')->format('Y-m-d H:i:s');
$psCheckoutCartRepository->save($psCheckoutCart);
}

$this->exitWithResponse([
'status' => true,
'httpCode' => 200,
Expand Down
13 changes: 0 additions & 13 deletions ps_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -1058,19 +1058,6 @@ public function hookActionFrontControllerSetMedia()
}
// END To be refactored in services

if ($frontControllerValidator->shouldGeneratePayPalClientToken($controller)
&& $payPalConfiguration->isHostedFieldsEnabled() && in_array($payPalConfiguration->getCardHostedFieldsStatus(), ['SUBSCRIBED', 'LIMITED'], true)
) {
try {
/** @var \PrestaShop\Module\PrestashopCheckout\PayPal\PayPalClientTokenProvider $clientTokenProvider */
$clientTokenProvider = $this->getService('ps_checkout.paypal.provider.client_token');

$payPalClientToken = $clientTokenProvider->getPayPalClientToken();
} catch (Exception $exception) {
$this->getLogger()->warning('Unable to retrieve PayPal Client Token', ['exception' => $exception]);
}
}

Media::addJsDef([
$this->name . 'Version' => $version->getSemVersion(),
$this->name . 'AutoRenderDisabled' => (bool) Configuration::get('PS_CHECKOUT_AUTO_RENDER_DISABLED'),
Expand Down
70 changes: 0 additions & 70 deletions src/Api/Payment/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
namespace PrestaShop\Module\PrestashopCheckout\Api\Payment;

use PrestaShop\Module\PrestashopCheckout\Api\Payment\Client\PaymentClient;
use PrestaShop\Module\PrestashopCheckout\Exception\PsCheckoutException;

/**
* Handle order requests
Expand Down Expand Up @@ -122,73 +121,4 @@ public function patch($payload)

return $this->post($payload);
}

/**
* @param string $merchantId
*
* @return string
*
* @throws PsCheckoutException
*/
public function generateClientToken($merchantId)
{
$this->setRoute('/payments/order/generate_client_token');

$response = $this->post([
'return_payload' => true,
'payee' => [
'merchant_id' => $merchantId,
],
]);

if (empty($response['body']) || empty($response['body']['client_token'])) {
$exception = null;

if (!empty($response['exceptionMessage'])) {
$exception = new \Exception($response['exceptionMessage'], $response['exceptionCode']);
}

throw new PsCheckoutException('Unable to retrieve PayPal Client Token', PsCheckoutException::MISSING_PAYPAL_CLIENT_TOKEN, $exception);
}

return $response['body']['client_token'];
}

/**
* @param string $merchantId
* @param int|null $customerId
*
* @return array{client_token:string, id_token: string, expires_in: int}
*
* @throws PsCheckoutException
*/
public function getClientToken($merchantId, $customerId = null)
{
$this->setRoute('/payments/order/generate_client_token');

$payload = [
'return_payload' => true,
'payee' => [
'merchant_id' => $merchantId,
],
];

if ($customerId) {
$payload['customer_id'] = $customerId;
}

$response = $this->post($payload);

if (empty($response['body']) || empty($response['body']['client_token'])) {
$exception = null;

if (!empty($response['exceptionMessage'])) {
$exception = new \Exception($response['exceptionMessage'], $response['exceptionCode']);
}

throw new PsCheckoutException('Unable to retrieve PayPal Client Token', PsCheckoutException::MISSING_PAYPAL_CLIENT_TOKEN, $exception);
}

return $response['body'];
}
}
111 changes: 0 additions & 111 deletions src/PayPal/Identity/Event/PayPalClientTokenUpdatedEvent.php

This file was deleted.

This file was deleted.

68 changes: 0 additions & 68 deletions src/PayPal/Identity/Query/GetClientTokenPayPalQuery.php

This file was deleted.

Loading

0 comments on commit a7c8e8d

Please sign in to comment.