Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
extends: './vendor/magento/magento-coding-standard/eslint/.eslintrc',
ignorePatterns: ['view/frontend/web/js/checkout'],
root: true
};
76 changes: 76 additions & 0 deletions Plugin/CustomerData/AddAdyenExpressMethods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);

namespace BlueFinch\CheckoutAdyen\Plugin\CustomerData;

use Adyen\Payment\Api\AdyenPaymentMethodManagementInterface;
use Magento\Checkout\CustomerData\Cart as Subject;
use Magento\Checkout\Model\Session;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

class AddAdyenExpressMethods
{
public const PAYMENT_METHODS_KEY = 'bluefinch_adyen_payment_methods';

/**
* @var AdyenPaymentMethodManagementInterface
*/
private $adyenPaymentMethodManagement;

/**
* @var Session
*/
private $checkoutSession;

/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
* Cart constructor
*
* @param AdyenPaymentMethodManagementInterface $adyenPaymentMethodManagement
* @param Session $checkoutSession
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
AdyenPaymentMethodManagementInterface $adyenPaymentMethodManagement,
Session $checkoutSession,
ScopeConfigInterface $scopeConfig
) {
$this->adyenPaymentMethodManagement = $adyenPaymentMethodManagement;
$this->checkoutSession = $checkoutSession;
$this->scopeConfig = $scopeConfig;
}

/**
* Intercept getSectionData and Adyen Payment methods.
*
* @param Subject $subject
* @param array $result
* @return array
*/
public function afterGetSectionData(
Subject $subject,
array $result
): array {
$googlePayExpressEnabled = $this->scopeConfig->getValue('payment/adyen_googlepay/express_show_on', ScopeInterface::SCOPE_STORE);
$applePayExpressEnabled = $this->scopeConfig->getValue('payment/adyen_applepay/express_show_on', ScopeInterface::SCOPE_STORE);
$payPalExpressEnabled = $this->scopeConfig->getValue('payment/adyen_paypal_express/express_show_on', ScopeInterface::SCOPE_STORE);

// Only run if no Adyen Express methods are enabled otherwise we'd be duplicating the Adyen API request.
if (!$googlePayExpressEnabled && !$applePayExpressEnabled && !$payPalExpressEnabled) {
$quoteId = $this->checkoutSession->getQuoteId();
$paymentMethods = $quoteId ?
json_decode(
$this->adyenPaymentMethodManagement->getPaymentMethods($quoteId),
true
) : [];
$result[self::PAYMENT_METHODS_KEY] = $paymentMethods;
}

return $result;
}
}
29 changes: 29 additions & 0 deletions Plugin/CustomerData/Cart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);

namespace BlueFinch\CheckoutAdyen\Plugin\CustomerData;

use BlueFinch\CheckoutAdyen\Plugin\CustomerData\AddAdyenExpressMethods;
use Adyen\ExpressCheckout\Plugin\CustomerData\Cart as Subject;

class Cart
{
/**
* If the Adyen Express has already added the payment methods then we can set use them without having
* to call Adyen's API again.
*
* @param Subject $subject
* @param array $result
* @return array
*/
public function afterAfterGetSectionData(
Subject $subject,
array $result
): array {
if (isset($result[Subject::PAYMENT_METHODS_KEY])) {
$result[AddAdyenExpressMethods::PAYMENT_METHODS_KEY] = $result[Subject::PAYMENT_METHODS_KEY];
}

return $result;
}
}
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@
},
"require": {
"magento/framework": "*",
"bluefinchcommerce/module-checkout": "^1.0"
"bluefinchcommerce/module-checkout": "^1.0",
"adyen/module-payment": ">7.0.0"
},
"require-dev": {
"magento/magento-coding-standard": "*",
"magento/magento-coding-standard": "<=35",
"phpcompatibility/php-compatibility": "*",
"phpunit/phpunit": "*",
"phpstan/phpstan": "^1.9",
"squizlabs/php_codesniffer": "^3.6",
"dealerdirect/phpcodesniffer-composer-installer": "^1.0"
"dealerdirect/phpcodesniffer-composer-installer": "^1.0",
"adyen/adyen-magento2-expresscheckout": "^2.4"
},
"repositories": {
"magento": {
Expand Down
Loading