-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
1,462 additions
and
116 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
31 changes: 31 additions & 0 deletions
31
Api/InstantPurchase/PaymentMethodIntegration/AdyenAvailabilityCheckerInterface.php
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,31 @@ | ||
<?php | ||
/** | ||
* | ||
* Adyen Payment Module | ||
* | ||
* Copyright (c) 2024 Adyen N.V. | ||
* This file is open source and available under the MIT license. | ||
* See the LICENSE file for more info. | ||
* | ||
* Author: Adyen <[email protected]> | ||
*/ | ||
|
||
namespace Adyen\Payment\Api\InstantPurchase\PaymentMethodIntegration; | ||
|
||
use Magento\InstantPurchase\PaymentMethodIntegration\AvailabilityCheckerInterface; | ||
|
||
interface AdyenAvailabilityCheckerInterface extends AvailabilityCheckerInterface | ||
{ | ||
/** | ||
* Checks if Adyen alternative payment method may be used for instant purchase. | ||
* | ||
* This interface extends the default `AvailabilityCheckerInterface` and implements | ||
* a new method with payment method argument. This interface is used in `InstantPurchaseIntegrations` | ||
* plugin to override the `AvailabilityCheckerInterface` which doesn't have payment method argument. | ||
* | ||
* @param string $paymentMethodCode | ||
* | ||
* @return bool | ||
*/ | ||
public function isAvailableAdyenMethod(string $paymentMethodCode): bool; | ||
} |
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
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 |
---|---|---|
|
@@ -9,18 +9,15 @@ | |
* Author: Adyen <[email protected]> | ||
*/ | ||
|
||
namespace Adyen\Payment\Gateway\Request; | ||
namespace Adyen\Payment\Gateway\Request\Header; | ||
|
||
use Adyen\Payment\Helper\Data; | ||
use Magento\Payment\Gateway\Data\PaymentDataObject; | ||
use Magento\Payment\Gateway\Helper\SubjectReader; | ||
use Magento\Payment\Gateway\Request\BuilderInterface; | ||
|
||
class HeaderDataBuilder implements BuilderInterface | ||
class HeaderDataBuilder implements BuilderInterface, HeaderDataBuilderInterface | ||
{ | ||
const FRONTENDTYPE = 'external-platform-frontendtype'; | ||
const FRONTENDTYPE_HEADLESS = 'headless'; | ||
|
||
/** | ||
* @var Data | ||
*/ | ||
|
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,15 @@ | ||
<?php | ||
|
||
namespace Adyen\Payment\Gateway\Request\Header; | ||
|
||
interface HeaderDataBuilderInterface | ||
{ | ||
const EXTERNAL_PLATFORM_NAME = 'external-platform-name'; | ||
const EXTERNAL_PLATFORM_VERSION = 'external-platform-version'; | ||
const EXTERNAL_PLATFORM_EDITION = 'external-platform-edition'; | ||
const EXTERNAL_PLATFORM_FRONTEND_TYPE = 'external-platform-frontendtype'; | ||
const MERCHANT_APPLICATION_NAME = 'merchant-application-name'; | ||
const MERCHANT_APPLICATION_VERSION = 'merchant-application-version'; | ||
|
||
const ADDITIONAL_DATA_FRONTEND_TYPE_KEY = 'frontendType'; | ||
} |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
* | ||
* Adyen Payment module (https://www.adyen.com/) | ||
* | ||
* Copyright (c) 2023 Adyen N.V. (https://www.adyen.com/) | ||
* Copyright (c) 2024 Adyen N.V. (https://www.adyen.com/) | ||
* See LICENSE.txt for license details. | ||
* | ||
* Author: Adyen <[email protected]> | ||
|
@@ -15,75 +15,87 @@ | |
use Adyen\Payment\Helper\StateData; | ||
use Adyen\Payment\Helper\Vault; | ||
use Adyen\Payment\Model\Config\Source\ThreeDSFlow; | ||
use Adyen\Payment\Model\Ui\AdyenCcConfigProvider; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Payment\Gateway\Data\PaymentDataObject; | ||
use Magento\Payment\Gateway\Helper\SubjectReader; | ||
use Magento\Payment\Gateway\Request\BuilderInterface; | ||
use Magento\Vault\Api\Data\PaymentTokenFactoryInterface; | ||
|
||
class RecurringVaultDataBuilder implements BuilderInterface | ||
{ | ||
private StateData $stateData; | ||
private Vault $vaultHelper; | ||
private Config $configHelper; | ||
|
||
/** | ||
* @param StateData $stateData | ||
* @param Vault $vaultHelper | ||
* @param Config $configHelper | ||
*/ | ||
public function __construct( | ||
StateData $stateData, | ||
Vault $vaultHelper, | ||
Config $configHelper | ||
) { | ||
$this->stateData = $stateData; | ||
$this->vaultHelper = $vaultHelper; | ||
$this->configHelper = $configHelper; | ||
} | ||
private readonly StateData $stateData, | ||
private readonly Vault $vaultHelper, | ||
private readonly Config $configHelper | ||
) { } | ||
|
||
/** | ||
* @throws LocalizedException | ||
*/ | ||
public function build(array $buildSubject): array | ||
{ | ||
/** @var PaymentDataObject $paymentDataObject */ | ||
$paymentDataObject = SubjectReader::readPayment($buildSubject); | ||
|
||
$payment = $paymentDataObject->getPayment(); | ||
$paymentMethod = $payment->getMethodInstance(); | ||
|
||
$order = $payment->getOrder(); | ||
$extensionAttributes = $payment->getExtensionAttributes(); | ||
|
||
$paymentToken = $extensionAttributes->getVaultPaymentToken(); | ||
$details = json_decode((string) ($paymentToken->getTokenDetails() ?: '{}'), true); | ||
|
||
// Initialize the request body with the current state data | ||
$requestBody = $this->stateData->getStateData($order->getQuoteId()); | ||
if ($paymentToken->getType() === PaymentTokenFactoryInterface::TOKEN_TYPE_CREDIT_CARD) { | ||
// Build base request for card token payments (including card wallets) | ||
|
||
// For now this will only be used by tokens created trough adyen_hpp payment methods | ||
if (array_key_exists(Vault::TOKEN_TYPE, $details)) { | ||
$requestBody['recurringProcessingModel'] = $details[Vault::TOKEN_TYPE]; | ||
} else { | ||
// If recurringProcessingModel doesn't exist in the token details, use the default value from config. | ||
$requestBody['recurringProcessingModel'] = $this->vaultHelper->getPaymentMethodRecurringProcessingModel( | ||
$paymentMethod->getProviderCode(), | ||
$order->getStoreId() | ||
); | ||
} | ||
$isInstantPurchase = (bool) $payment->getAdditionalInformation('instant-purchase'); | ||
|
||
if ($isInstantPurchase) { | ||
// `Instant Purchase` doesn't have the component and state data. Build the `paymentMethod` object. | ||
$requestBody['paymentMethod']['type'] = 'scheme'; | ||
$requestBody['paymentMethod']['storedPaymentMethodId'] = $paymentToken->getGatewayToken(); | ||
} else { | ||
// Initialize the request body with the current state data if it's not `Instant Purchase`. | ||
$requestBody = $this->stateData->getStateData($order->getQuoteId()); | ||
} | ||
|
||
/* | ||
* allow3DS flag is required to trigger the native 3DS challenge. | ||
* Otherwise, shopper will be redirected to the issuer for challenge. | ||
* Due to new VISA compliance requirements, holderName is added to the payments call | ||
*/ | ||
if ($paymentMethod->getCode() === AdyenCcConfigProvider::CC_VAULT_CODE) { | ||
/* | ||
* `allow3DS: true` flag is required to trigger the native 3DS challenge. | ||
* Otherwise, shopper will be redirected to the issuer for challenge. | ||
*/ | ||
$requestBody['additionalData']['allow3DS2'] = | ||
$this->configHelper->getThreeDSFlow($order->getStoreId()) === ThreeDSFlow::THREEDS_NATIVE; | ||
|
||
// Due to new VISA compliance requirements, holderName is added to the payments call | ||
$requestBody['paymentMethod']['holderName'] = $details['cardHolderName'] ?? null; | ||
} | ||
} else { | ||
// Build base request for alternative payment methods for regular checkout and Instant Purchase | ||
|
||
/** | ||
* Build paymentMethod object for alternative payment methods | ||
*/ | ||
if ($paymentMethod->getCode() !== AdyenCcConfigProvider::CC_VAULT_CODE) { | ||
$requestBody['paymentMethod'] = [ | ||
'type' => $details['type'], | ||
'storedPaymentMethodId' => $paymentToken->getGatewayToken() | ||
]; | ||
} | ||
|
||
$request['body'] = $requestBody; | ||
// Check the `stateData` if `recurringProcessingModel` is added through a headless request. | ||
if (array_key_exists(Vault::TOKEN_TYPE, $details)) { | ||
$requestBody['recurringProcessingModel'] = $details[Vault::TOKEN_TYPE]; | ||
} else { | ||
// If recurringProcessingModel doesn't exist in the token details, use the default value from config. | ||
$requestBody['recurringProcessingModel'] = $this->vaultHelper->getPaymentMethodRecurringProcessingModel( | ||
$paymentMethod->getProviderCode(), | ||
$order->getStoreId() | ||
); | ||
} | ||
|
||
return $request; | ||
return [ | ||
'body' => $requestBody | ||
]; | ||
} | ||
} |
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
Oops, something went wrong.