diff --git a/.gitignore b/.gitignore index 3b9b3c5..055d08b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ test-results/ playwright-report/ hyva/ .idea/ +nohup.out vendor/ .env diff --git a/src/Magewire/Checkout/Payment/AbstractProcessor.php b/src/Magewire/Checkout/Payment/AbstractProcessor.php index a93ddab..6fa8481 100644 --- a/src/Magewire/Checkout/Payment/AbstractProcessor.php +++ b/src/Magewire/Checkout/Payment/AbstractProcessor.php @@ -34,6 +34,12 @@ abstract class AbstractProcessor extends Component /** @var array */ public $parameters = []; + /** @var string */ + public $quoteCurrency = 'GBP'; + + /** @var string */ + public $quoteAmount = '0'; + /** * @param SerializerInterface $serializer * @param Assets $assetsModel @@ -55,9 +61,12 @@ public function __construct( $this->sdkProxy = $sdkProxy; } - public function mount(): void + + public function boot(): void { $this->parameters = $this->serializer->unserialize($this->assetsModel->getRvvupParametersJsObject()); + $this->quoteAmount = $this->checkoutSession->getQuote()->getGrandTotal(); + $this->quoteCurrency = $this->checkoutSession->getQuote()->getQuoteCurrencyCode(); } abstract function getMethodCode(): string; diff --git a/src/Magewire/Checkout/Payment/ApplePayProcessor.php b/src/Magewire/Checkout/Payment/ApplePayProcessor.php index 8a6596f..c4ee0b4 100644 --- a/src/Magewire/Checkout/Payment/ApplePayProcessor.php +++ b/src/Magewire/Checkout/Payment/ApplePayProcessor.php @@ -4,12 +4,69 @@ namespace Rvvup\PaymentsHyvaCheckout\Magewire\Checkout\Payment; +use Magento\Checkout\Model\Session; +use Magento\Framework\Serialize\SerializerInterface; +use Magento\Framework\UrlFactory; +use Rvvup\Payments\Controller\Redirect\In; +use Rvvup\Payments\Model\SdkProxy; +use Rvvup\Payments\Service\PaymentSessionService; +use Rvvup\Payments\ViewModel\Assets; +use Rvvup\PaymentsHyvaCheckout\Service\GetPaymentActions; + class ApplePayProcessor extends AbstractProcessor { + protected $listeners = [ + 'shipping_method_selected' => 'refresh', + 'coupon_code_applied' => 'refresh', + 'coupon_code_revoked' => 'refresh' + ]; + + /** @var PaymentSessionService */ + private $paymentSessionService; + + /** @var UrlFactory */ + private $urlFactory; + + /** @var array */ + public $paymentSessionResult; + + /** + * @param SerializerInterface $serializer + * @param Assets $assetsModel + * @param GetPaymentActions $getPaymentActions + * @param Session $checkoutSession + * @param SdkProxy $sdkProxy + * @param PaymentSessionService $paymentSessionService + * @param UrlFactory $urlFactory + */ + public function __construct( + SerializerInterface $serializer, + Assets $assetsModel, + GetPaymentActions $getPaymentActions, + Session $checkoutSession, + SdkProxy $sdkProxy, + PaymentSessionService $paymentSessionService, + UrlFactory $urlFactory + ) { + parent::__construct($serializer, $assetsModel, $getPaymentActions, $checkoutSession, $sdkProxy); + $this->paymentSessionService = $paymentSessionService; + $this->urlFactory = $urlFactory; + } + + public $hydrated = false; + public function getMethodCode(): string { return 'rvvup_APPLE_PAY'; } + public function boot(): void + { + parent::boot(); + + if ($this->showInline()) { + $this->switchTemplate('Rvvup_PaymentsHyvaCheckout::component/payment/apple-pay-inline-processor.phtml'); + } + } public function placeOrder(): void { @@ -17,4 +74,26 @@ public function placeOrder(): void $redirectUrl = $this->getRedirectUrl(); $this->redirect($redirectUrl); } + + /** + * @return bool + */ + public function showInline(): bool + { + if (isset($this->parameters['settings']['apple_pay']['applePayFlow'])) { + return $this->parameters['settings']['apple_pay']['applePayFlow'] == 'INLINE'; + } + return false; + } + + public function createPaymentSession(string $checkoutId): void + { + $quote = $this->checkoutSession->getQuote(); + + $paymentSession = $this->paymentSessionService->create($quote, $checkoutId); + + $url = $this->urlFactory->create(); + $url->setQueryParam(In::PARAM_RVVUP_ORDER_ID, $paymentSession["id"]); + $this->paymentSessionResult = ["paymentSessionId" => $paymentSession["id"], "redirectUrl" => $url->getUrl('rvvup/redirect/in')]; + } } diff --git a/src/view/frontend/layout/hyva_checkout_index_index.xml b/src/view/frontend/layout/hyva_checkout_index_index.xml index 77d6b9c..9543c86 100644 --- a/src/view/frontend/layout/hyva_checkout_index_index.xml +++ b/src/view/frontend/layout/hyva_checkout_index_index.xml @@ -47,7 +47,7 @@ diff --git a/src/view/frontend/templates/component/payment/apple-pay-hosted-processor.phtml b/src/view/frontend/templates/component/payment/apple-pay-hosted-processor.phtml new file mode 100644 index 0000000..809ef15 --- /dev/null +++ b/src/view/frontend/templates/component/payment/apple-pay-hosted-processor.phtml @@ -0,0 +1,52 @@ + +
+ + +
diff --git a/src/view/frontend/templates/component/payment/apple-pay-inline-processor.phtml b/src/view/frontend/templates/component/payment/apple-pay-inline-processor.phtml new file mode 100644 index 0000000..b581cc0 --- /dev/null +++ b/src/view/frontend/templates/component/payment/apple-pay-inline-processor.phtml @@ -0,0 +1,132 @@ + +
+ + +
diff --git a/src/view/frontend/templates/component/payment/apple-pay-processor.phtml b/src/view/frontend/templates/component/payment/apple-pay-processor.phtml deleted file mode 100644 index 97e8f9e..0000000 --- a/src/view/frontend/templates/component/payment/apple-pay-processor.phtml +++ /dev/null @@ -1,52 +0,0 @@ - -
- - -
diff --git a/src/view/frontend/templates/component/payment/paypal-processor.phtml b/src/view/frontend/templates/component/payment/paypal-processor.phtml index 0a76ee9..f51cea5 100644 --- a/src/view/frontend/templates/component/payment/paypal-processor.phtml +++ b/src/view/frontend/templates/component/payment/paypal-processor.phtml @@ -3,13 +3,18 @@ /** @var \Magento\Framework\Escaper $escaper */ ?>
+