-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #550 from mollie/release/2.15.0
Release/2.15.0
- Loading branch information
Showing
21 changed files
with
732 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace Mollie\Payment\Block\Applepay\Shortcut; | ||
|
||
use Magento\Catalog\Block\ShortcutInterface; | ||
use Magento\Checkout\Model\Session; | ||
use Magento\Framework\View\Element\Template; | ||
use Magento\Store\Model\ScopeInterface; | ||
use Mollie\Payment\Config; | ||
|
||
class Button extends Template implements ShortcutInterface | ||
{ | ||
protected $_template = 'Mollie_Payment::applepay/minicart/applepay-button.phtml'; | ||
|
||
/** | ||
* @var Session | ||
*/ | ||
private $checkoutSession; | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
public function __construct( | ||
Template\Context $context, | ||
Session $checkoutSession, | ||
Config $config, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->checkoutSession = $checkoutSession; | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAlias(): string | ||
{ | ||
return 'mollie.applepay.mini-cart'; | ||
} | ||
|
||
/** | ||
* @return float|null | ||
*/ | ||
public function getBaseGrandTotal(): ?float | ||
{ | ||
return $this->checkoutSession->getQuote()->getBaseGrandTotal(); | ||
} | ||
|
||
/** | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
* @return string | ||
*/ | ||
public function getStoreName(): string | ||
{ | ||
return $this->_storeManager->getStore()->getName(); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getStoreCountry(): string | ||
{ | ||
return $this->_scopeConfig->getValue('general/country/default', ScopeInterface::SCOPE_STORE); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getStoreCurrency(): string | ||
{ | ||
return $this->_storeManager->getStore()->getCurrentCurrencyCode(); | ||
} | ||
|
||
public function getButtonClasses(): string | ||
{ | ||
$classes = []; | ||
$classes[] = 'mollie-applepay-minicart-button'; | ||
$classes[] = 'apple-pay-button'; | ||
$classes[] = 'apple-pay-button-color-' . $this->config->applePayMinicartColor(); | ||
|
||
if ($this->config->applePayMinicartText()) { | ||
$classes[] = 'apple-pay-button-text-' . $this->config->applePayMinicartText(); | ||
} | ||
|
||
return implode(' ', $classes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,8 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Mollie\Payment\Controller\ApplePay; | ||
|
||
use Magento\Checkout\Model\Session; | ||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\Action\Context; | ||
use Magento\Framework\Controller\ResultFactory; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Api\Data\AddressInterface; | ||
use Magento\Quote\Api\GuestCartRepositoryInterface; | ||
use Magento\Quote\Model\QuoteManagement; | ||
use Magento\Sales\Api\OrderRepositoryInterface; | ||
use Mollie\Payment\Api\Webapi\PaymentTokenRequestInterface; | ||
use Mollie\Payment\Service\PaymentToken\Generate; | ||
|
||
class BuyNowPlaceOrder extends Action | ||
class BuyNowPlaceOrder extends PlaceOrder | ||
{ | ||
/** | ||
* @var GuestCartRepositoryInterface | ||
*/ | ||
private $guestCartRepository; | ||
|
||
/** | ||
* @var CartRepositoryInterface | ||
*/ | ||
private $cartRepository; | ||
|
||
/** | ||
* @var QuoteManagement | ||
*/ | ||
private $quoteManagement; | ||
|
||
/** | ||
* @var Session | ||
*/ | ||
private $checkoutSession; | ||
|
||
/** | ||
* @var PaymentTokenRequestInterface | ||
*/ | ||
private $paymentTokenRequest; | ||
|
||
/** | ||
* @var Generate | ||
*/ | ||
private $paymentToken; | ||
|
||
/** | ||
* @var OrderRepositoryInterface | ||
*/ | ||
private $orderRepository; | ||
|
||
public function __construct( | ||
Context $context, | ||
GuestCartRepositoryInterface $guestCartRepository, | ||
CartRepositoryInterface $cartRepository, | ||
QuoteManagement $quoteManagement, | ||
Session $checkoutSession, | ||
Generate $paymentToken, | ||
OrderRepositoryInterface $orderRepository | ||
) { | ||
parent::__construct($context); | ||
|
||
$this->guestCartRepository = $guestCartRepository; | ||
$this->cartRepository = $cartRepository; | ||
$this->quoteManagement = $quoteManagement; | ||
$this->checkoutSession = $checkoutSession; | ||
$this->paymentToken = $paymentToken; | ||
$this->orderRepository = $orderRepository; | ||
} | ||
|
||
public function execute() | ||
{ | ||
$cart = $this->guestCartRepository->get($this->getRequest()->getParam('cartId')); | ||
|
||
$shippingAddress = $cart->getShippingAddress(); | ||
$this->updateAddress($shippingAddress, $this->getRequest()->getParam('shippingAddress')); | ||
$this->updateAddress($cart->getBillingAddress(), $this->getRequest()->getParam('billingAddress')); | ||
|
||
$cart->setCustomerEmail($this->getRequest()->getParam('shippingAddress')['emailAddress']); | ||
|
||
$shippingAddress->setShippingMethod($this->getRequest()->getParam('shippingMethod')['identifier']); | ||
|
||
$cart->setPaymentMethod('mollie_methods_applepay'); | ||
$cart->setCustomerIsGuest(true); | ||
|
||
$cart->collectTotals(); | ||
$this->cartRepository->save($cart); | ||
$cart->getPayment()->addData(['method' => 'mollie_methods_applepay']); | ||
|
||
$order = $this->quoteManagement->submit($cart); | ||
$order->getPayment()->setAdditionalInformation( | ||
'applepay_payment_token', | ||
$this->getRequest()->getParam('applePayPaymentToken') | ||
); | ||
|
||
$this->orderRepository->save($order); | ||
|
||
$paymentToken = $this->paymentToken->forOrder($order); | ||
|
||
$url = $this->_url->getUrl('mollie/checkout/redirect', ['paymentToken' => $paymentToken->getToken()]); | ||
|
||
$this->checkoutSession->clearHelperData(); | ||
$this->checkoutSession | ||
->setLastQuoteId($cart->getId()) | ||
->setLastSuccessQuoteId($cart->getId()) | ||
->setLastOrderId($order->getId()); | ||
|
||
$response = $this->resultFactory->create(ResultFactory::TYPE_JSON); | ||
return $response->setData(['url' => $url]); | ||
} | ||
|
||
private function updateAddress(AddressInterface $address, array $input) | ||
{ | ||
$address->addData([ | ||
AddressInterface::KEY_STREET => implode(PHP_EOL, $input['addressLines']), | ||
AddressInterface::KEY_COUNTRY_ID => $input['countryCode'], | ||
AddressInterface::KEY_LASTNAME => $input['familyName'], | ||
AddressInterface::KEY_FIRSTNAME => $input['givenName'], | ||
AddressInterface::KEY_CITY => $input['locality'], | ||
AddressInterface::KEY_POSTCODE => $input['postalCode'], | ||
]); | ||
|
||
if (isset($input['phoneNumber'])) { | ||
$address->setTelephone($input['phoneNumber']); | ||
} | ||
|
||
if ($address->getAddressType() == \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_BILLING) { | ||
$input = $this->getRequest()->getParam('shippingAddress'); | ||
$address->setTelephone($input['phoneNumber']); | ||
} | ||
} | ||
} |
Oops, something went wrong.