app/Plugin/PayPalCheckout42/Controller/ShortcutPaypalCheckout/ShortcutPayPalCheckoutController.php line 115

Open in your IDE?
  1. <?php
  2. namespace Plugin\PayPalCheckout42\Controller\ShortcutPaypalCheckout;
  3. use Eccube\Entity\Customer;
  4. use Eccube\Entity\Order;
  5. use Eccube\Entity\Payment;
  6. use Eccube\Repository\Master\PrefRepository;
  7. use Eccube\Repository\OrderRepository;
  8. use Eccube\Repository\PaymentRepository;
  9. use Eccube\Service\CartService;
  10. use Eccube\Service\MailService;
  11. use Eccube\Service\OrderHelper;
  12. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  13. use Exception;
  14. use Plugin\PayPalCheckout42\Controller\OrderManagement\InitializeOrderController;
  15. use Plugin\PayPalCheckout42\Exception\NotFoundCartException;
  16. use Plugin\PayPalCheckout42\Exception\OrderInitializationException;
  17. use Plugin\PayPalCheckout42\Service\LoggerService;
  18. use Plugin\PayPalCheckout42\Service\Method\CreditCard;
  19. use Plugin\PayPalCheckout42\Service\PayPalService;
  20. /**
  21.  * Class ShortcutPayPalCheckoutController
  22.  * @package Plugin\PayPalCheckout42\Controller\ShortcutPaypalCheckout
  23.  */
  24. class ShortcutPayPalCheckoutController extends InitializeOrderController
  25. {
  26.     /**
  27.      * @var PurchaseFlow
  28.      */
  29.     protected $cartPurchaseFlow;
  30.     /**
  31.      * @var PayPalService
  32.      */
  33.     protected $paypal;
  34.     /**
  35.      * @var Logger
  36.      */
  37.     protected $logger;
  38.     /**
  39.      * @var PaymentRepository
  40.      */
  41.     protected $paymentRepository;
  42.     /**
  43.      * @var PrefRepository
  44.      */
  45.     protected $prefRepository;
  46.     /**
  47.      * CreateShortcutOrderController constructor.
  48.      * @param CartService $cartService
  49.      * @param MailService $mailService
  50.      * @param OrderHelper $orderHelper
  51.      * @param PurchaseFlow $cartPurchaseFlow
  52.      * @param PayPalService $paypal
  53.      * @param LoggerService $loggerService
  54.      * @param OrderRepository $orderRepository
  55.      * @param PaymentRepository $paymentRepository
  56.      * @param PrefRepository $prefRepository
  57.      */
  58.     public function __construct(
  59.         CartService $cartService,
  60.         MailService $mailService,
  61.         OrderHelper $orderHelper,
  62.         PurchaseFlow $cartPurchaseFlow,
  63.         PayPalService $paypal,
  64.         LoggerService $loggerService,
  65.         OrderRepository $orderRepository,
  66.         PaymentRepository $paymentRepository,
  67.         PrefRepository $prefRepository
  68.     ) {
  69.         parent::__construct($cartService$mailService$orderRepository$orderHelper);
  70.         $this->paypal $paypal;
  71.         $this->logger $loggerService;
  72.         $this->cartPurchaseFlow $cartPurchaseFlow;
  73.         $this->paymentRepository $paymentRepository;
  74.         $this->prefRepository $prefRepository;
  75.     }
  76.     /**
  77.      * @param $cart_key
  78.      * @throws NotFoundCartException
  79.      */
  80.     protected function lockCart($cart_key): void
  81.     {
  82.         $Carts $this->cartService->getCart();
  83.         if (!is_object($Carts)) {
  84.             throw new NotFoundCartException();
  85.         }
  86.         $this->cartService->setPrimary($cart_key);
  87.         $this->cartService->save();
  88.     }
  89.     /**
  90.      * @param PurchaseFlow $cartPurchaseFlow
  91.      * @return void
  92.      * @throws OrderInitializationException
  93.      */
  94.     protected function initializeOrder(PurchaseFlow $cartPurchaseFlow): void
  95.     {
  96.         try {
  97.             parent::eccubeShoppingControllerIndex($cartPurchaseFlow, function (Order $Order): void {
  98.                 /** @var Payment $Payment */
  99.                 $Payment $this->paymentRepository->findOneBy([
  100.                     'method_class' => CreditCard::class
  101.                 ]);
  102.                 $Order->setPayment($Payment);
  103.                 $Order->setPaymentMethod($Payment->getMethod());
  104.                 $this->entityManager->persist($Order);
  105.             });
  106.         } catch (Exception $e) {
  107.             throw new OrderInitializationException($e->getMessage(), $e->getCode(), $e);
  108.         }
  109.     }
  110.     /**
  111.      * @param Customer $customer
  112.      */
  113.     protected function initializeCustomer(Customer $customer): void
  114.     {
  115.         $this->session->set(OrderHelper::SESSION_NON_MEMBER$customer);
  116.         $this->session->set(OrderHelper::SESSION_NON_MEMBER_ADDRESSESserialize([]));
  117.     }
  118. }