custom/plugins/SwagAmazonPay/src/Components/Button/Pay/Hydrator/AmazonPayButtonPayloadHydrator.php line 64

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * (c) shopware AG <info@shopware.com>
  5.  * For the full copyright and license information, please view the LICENSE
  6.  * file that was distributed with this source code.
  7.  */
  8. namespace Swag\AmazonPay\Components\Button\Pay\Hydrator;
  9. use Psr\Log\LoggerInterface;
  10. use Shopware\Core\Framework\Context;
  11. use Swag\AmazonPay\Components\Button\Pay\AddressRestriction\AddressRestrictionServiceInterface;
  12. use Swag\AmazonPay\Components\Button\Pay\Struct\AmazonPayButtonPayloadStruct;
  13. use Swag\AmazonPay\Components\Config\ConfigServiceInterface;
  14. use Swag\AmazonPay\Components\Config\Validation\Exception\ConfigValidationException;
  15. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  16. use Symfony\Component\Routing\RouterInterface;
  17. class AmazonPayButtonPayloadHydrator implements AmazonPayButtonPayloadHydratorInterfaceAmazonPayButtonPayloadHydratorInterfaceV2
  18. {
  19.     /**
  20.      * @var ConfigServiceInterface
  21.      */
  22.     private $configService;
  23.     /**
  24.      * @var RouterInterface
  25.      */
  26.     private $router;
  27.     /**
  28.      * @var LoggerInterface
  29.      */
  30.     private $logger;
  31.     /**
  32.      * @var AddressRestrictionServiceInterface
  33.      */
  34.     private $addressRestrictionService;
  35.     public function __construct(
  36.         ConfigServiceInterface $configService,
  37.         RouterInterface $router,
  38.         LoggerInterface $logger,
  39.         AddressRestrictionServiceInterface $addressRestrictionService
  40.     ) {
  41.         $this->configService $configService;
  42.         $this->router $router;
  43.         $this->logger $logger;
  44.         $this->addressRestrictionService $addressRestrictionService;
  45.     }
  46.     public function hydrate(string $salesChannelIdbool $oneClickCheckout true): string
  47.     {
  48.         $this->logger->warning('You are using the deprecated \Swag\AmazonPay\Components\Button\Pay\Hydrator\AmazonPayButtonPayloadHydrator::hydrate function use \Swag\AmazonPay\Components\Button\Pay\Hydrator\AmazonPayButtonPayloadHydrator::hydratePayload instead.');
  49.         $payload $this->hydratePayload($salesChannelIdContext::createDefaultContext(), $oneClickCheckout);
  50.         return (string) \json_encode($payload\JSON_UNESCAPED_SLASHES \JSON_FORCE_OBJECT);
  51.     }
  52.     public function hydratePayload(string $salesChannelIdContext $contextbool $oneClickCheckout true): ?AmazonPayButtonPayloadStruct
  53.     {
  54.         try {
  55.             $pluginConfig $this->configService->getPluginConfig($salesChannelId);
  56.         } catch (ConfigValidationException $e) {
  57.             $this->logger->error('Could not generate Amazon login button payload', ['Exception' => $e->getMessage()]);
  58.             return null;
  59.         }
  60.         $payload = new AmazonPayButtonPayloadStruct();
  61.         $payload->setCheckoutReviewReturnUrl($this->router->generate('payment.swag_amazon_pay.review', ['oneClickCheckout' => $oneClickCheckout], UrlGeneratorInterface::ABSOLUTE_URL));
  62.         $payload->setStoreId($pluginConfig->getClientId());
  63.         $payload->setAddressRestrictions($this->addressRestrictionService->getAddressRestrictions($salesChannelId$context));
  64.         return $payload;
  65.     }
  66. }