Skip to content

Commit

Permalink
Merge branch 'release/v6.0.0' into 'master'
Browse files Browse the repository at this point in the history
CHECMAG2003-206: check if current currency is allowed on paypal option and...

See merge request agence-dnd/marketplace/magento-2/external/module-checkout-magento2-plugin!198
  • Loading branch information
DnD-Behou committed Apr 2, 2024
2 parents 0c8cf9c + f3fb02f commit d0ae2d8
Show file tree
Hide file tree
Showing 47 changed files with 3,208 additions and 353 deletions.
10 changes: 9 additions & 1 deletion Block/Cart/ApplePay.php → Block/Cart/CheckoutConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\View\Element\Template\Context;

class ApplePay extends Onepage
class CheckoutConfig extends Onepage
{
private Cart $cart;
private ConfigProvider $checkoutComConfigProvider;
private SerializerInterface $serializer;
private Config $checkoutComConfig;

public function __construct(
Cart $cart,
Expand All @@ -62,6 +63,7 @@ public function __construct(
);
$this->cart = $cart;
$this->checkoutComConfigProvider = $checkoutComConfigProvider;
$this->checkoutComConfig = $checkoutComConfig;
$this->serializer = $serializerInterface ?: ObjectManager::getInstance()
->get(JsonHexTag::class);
}
Expand All @@ -86,4 +88,10 @@ public function getSerializedCheckoutComConfig(): string

return $this->serializer->serialize($config);
}

public function isPaypalOrApplePayEnabled(): bool
{
return $this->checkoutComConfig->getValue('active', 'checkoutcom_apple_pay')
|| $this->checkoutComConfig->getValue('active', 'checkoutcom_paypal');
}
}
51 changes: 51 additions & 0 deletions Block/Paypal/Review/PaymentMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

/**
* Checkout.com
* Authorized and regulated as an electronic money institution
* by the UK Financial Conduct Authority (FCA) under number 900816.
*
* PHP version 7
*
* @category Magento2
* @package Checkout.com
* @author Platforms Development Team <[email protected]>
* @copyright 2010-present Checkout.com
* @license https://opensource.org/licenses/mit-license.html MIT License
* @link https://docs.checkout.com/
*/
namespace CheckoutCom\Magento2\Block\Paypal\Review;

use CheckoutCom\Magento2\Model\Methods\PaypalMethod;
use Magento\Checkout\Model\Session;
use Magento\Framework\View\Element\Template;
use \Magento\Framework\View\Element\Template\Context as TemplateContext;

class PaymentMethod extends Template
{
protected Session $checkoutSession;
protected PaypalMethod $paypalMethod;

public function __construct(
TemplateContext $context,
Session $checkoutSession,
PaypalMethod $paypalMethod,
array $data = []
) {
parent::__construct($context, $data);
$this->checkoutSession = $checkoutSession;
$this->paypalMethod = $paypalMethod;
}

public function getEmail(): string
{
return (string)$this->checkoutSession->getQuote()->getCustomerEmail();
}

public function getPaymentMethod(): string
{
return (string)$this->paypalMethod->getTitle();
}
}
66 changes: 66 additions & 0 deletions Block/Paypal/Review/PlaceOrderButton.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

/**
* Checkout.com
* Authorized and regulated as an electronic money institution
* by the UK Financial Conduct Authority (FCA) under number 900816.
*
* PHP version 7
*
* @category Magento2
* @package Checkout.com
* @author Platforms Development Team <[email protected]>
* @copyright 2010-present Checkout.com
* @license https://opensource.org/licenses/mit-license.html MIT License
* @link https://docs.checkout.com/
*/
namespace CheckoutCom\Magento2\Block\Paypal\Review;

use CheckoutCom\Magento2\Controller\Paypal\Review;
use CheckoutCom\Magento2\Model\Methods\PaypalMethod;
use Magento\Checkout\Model\Session;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Element\Template;
use \Magento\Framework\View\Element\Template\Context as TemplateContext;

class PlaceOrderButton extends Template
{
protected Session $checkoutSession;
protected RequestInterface $request;
protected PaypalMethod $paypalMethod;

public function __construct(
TemplateContext $context,
Session $checkoutSession,
RequestInterface $request,
PaypalMethod $paypalMethod,
array $data = []
) {
parent::__construct($context, $data);
$this->checkoutSession = $checkoutSession;
$this->request = $request;
$this->paypalMethod = $paypalMethod;
}

public function getEmail(): string
{
return (string)$this->checkoutSession->getQuote()->getCustomerEmail();
}

public function canPlaceOrder(): bool
{
return (bool)$this->checkoutSession->getQuote()->getShippingAddress()->getShippingMethod();
}

public function getPaymentMethod(): string
{
return (string)$this->paypalMethod->getCode();
}

public function getContextId(): string
{
return (string)$this->request->getParam(Review::PAYMENT_CONTEXT_ID_PARAMETER);
}
}
163 changes: 163 additions & 0 deletions Block/Paypal/Review/ShippingAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
<?php

declare(strict_types=1);

/**
* Checkout.com
* Authorized and regulated as an electronic money institution
* by the UK Financial Conduct Authority (FCA) under number 900816.
*
* PHP version 7
*
* @category Magento2
* @package Checkout.com
* @author Platforms Development Team <[email protected]>
* @copyright 2010-present Checkout.com
* @license https://opensource.org/licenses/mit-license.html MIT License
* @link https://docs.checkout.com/
*/

namespace CheckoutCom\Magento2\Block\Paypal\Review;

use CheckoutCom\Magento2\Controller\Paypal\Review;
use Magento\Checkout\Model\Session as CheckoutSession;
use Magento\Customer\Api\AddressMetadataInterface;
use Magento\Customer\Api\AddressRepositoryInterface;
use Magento\Customer\Api\Data\AddressInterfaceFactory;
use Magento\Customer\Api\Data\CustomerInterface;
use Magento\Customer\Api\Data\CustomerInterfaceFactory;
use Magento\Customer\Block\Address\Edit as CustomerAddressEdit;
use Magento\Customer\Helper\Address;
use Magento\Customer\Helper\Session\CurrentCustomer;
use Magento\Customer\Model\Address\Config as AddressConfig;
use Magento\Customer\Model\Session;
use Magento\Directory\Helper\Data;
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory as CountryCollectionFactory;
use Magento\Directory\Model\ResourceModel\Region\CollectionFactory;
use Magento\Framework\Api\DataObjectHelper;
use Magento\Framework\App\Cache\Type\Config;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Json\EncoderInterface;
use Magento\Framework\Phrase;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Element\Template\Context;
use Magento\Quote\Model\Quote\Address as QuoteAddress;

class ShippingAddress extends CustomerAddressEdit
{
protected CheckoutSession $checkoutSession;
protected AddressConfig $addressConfig;
protected CustomerInterfaceFactory $customerInterfaceFactory;
protected UrlInterface $url;
protected RequestInterface $request;

public function __construct(
Context $context,
Data $directoryHelper,
EncoderInterface $jsonEncoder,
Config $configCacheType,
CollectionFactory $regionCollectionFactory,
CountryCollectionFactory $countryCollectionFactory,
Session $customerSession,
AddressRepositoryInterface $addressRepository,
AddressInterfaceFactory $addressDataFactory,
CurrentCustomer $currentCustomer,
DataObjectHelper $dataObjectHelper,
CheckoutSession $checkoutSession,
AddressConfig $addressConfig,
CustomerInterfaceFactory $customerInterfaceFactory,
UrlInterface $url,
RequestInterface $request,
array $data = [],
AddressMetadataInterface $addressMetadata = null,
Address $addressHelper = null
) {
parent::__construct(
$context,
$directoryHelper,
$jsonEncoder,
$configCacheType,
$regionCollectionFactory,
$countryCollectionFactory,
$customerSession,
$addressRepository,
$addressDataFactory,
$currentCustomer,
$dataObjectHelper,
$data,
$addressMetadata,
$addressHelper
);

$this->addressConfig = $addressConfig;
$this->checkoutSession = $checkoutSession;
$this->customerInterfaceFactory = $customerInterfaceFactory;
$this->url = $url;
$this->request = $request;

$this->_address = $this->checkoutSession->getQuote()->getShippingAddress();
}

/**
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function getAddress(): ?QuoteAddress
{
return $this->checkoutSession->getQuote()->getShippingAddress();
}

public function getCustomer(): CustomerInterface
{
return $this->customerInterfaceFactory->create();
}

public function isDefaultBilling(): bool
{
return false;
}

public function isDefaultShipping(): bool
{
return false;
}

public function canSetAsDefaultBilling(): bool
{
return false;
}

public function canSetAsDefaultShipping(): bool
{
return false;
}

public function getCustomerAddressCount(): int
{
return 1;
}

public function getRegion(): string
{
return (string)$this->getAddress()->getRegion();
}

public function getRegionId()
{
return $this->getAddress()->getRegionId() ?? 0;
}

public function getTitle(): Phrase
{
return __('Review Order');
}

public function getSaveUrl(): string
{
return $this->url->getUrl('checkoutcom/paypal/saveExpressShippingAddress', [
Review::PAYMENT_CONTEXT_ID_PARAMETER => $this->request->getParam(Review::PAYMENT_CONTEXT_ID_PARAMETER)
]);
}
}
Loading

0 comments on commit d0ae2d8

Please sign in to comment.