We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit e7013c54 authored by Rik ter Beek's avatar Rik ter Beek Committed by Ángel Campos

[PW-2024] Add merchantApplication into API calls (#635)

* [PW-2024] Add merchantApplication into API calls

* [PW-2024] Add to body request as config methods are not implemented in the library version we use. Cleanup some code and formatting. Tested Card payments, vault payment that will include this value.
parent 41f694de
......@@ -24,9 +24,10 @@
namespace Adyen\Payment\Gateway\Http\Client;
use Magento\Payment\Gateway\Http\ClientInterface;
use Adyen\Payment\Model\ApplicationInfo;
/**
* Class TransactionSale
* Class TransactionAuthorization
*/
class TransactionAuthorization implements ClientInterface
{
......@@ -34,37 +35,31 @@ class TransactionAuthorization implements ClientInterface
/**
* @var \Adyen\Client
*/
protected $_client;
protected $client;
/**
* PaymentRequest constructor.
*
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Encryption\EncryptorInterface $encryptor
* @var ApplicationInfo
*/
private $applicationInfo;
/**
* TransactionAuthorization constructor.
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param \Adyen\Payment\Model\RecurringType $recurringType
* @param array $data
* @param ApplicationInfo $applicationInfo
* @throws \Adyen\AdyenException
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Encryption\EncryptorInterface $encryptor,
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\RecurringType $recurringType,
array $data = []
\Adyen\Payment\Model\ApplicationInfo $applicationInfo
) {
$this->_encryptor = $encryptor;
$this->_adyenHelper = $adyenHelper;
$this->_recurringType = $recurringType;
$this->_appState = $context->getAppState();
$this->_client = $this->_adyenHelper->initializeAdyenClient();
$this->applicationInfo = $applicationInfo;
$this->client = $adyenHelper->initializeAdyenClient();
}
/**
* @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
* @return mixed
* @throws ClientException
* @return array|mixed
* @throws \Adyen\AdyenException
*/
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{
......@@ -76,14 +71,16 @@ class TransactionAuthorization implements ClientInterface
if (!empty($headers['idempotencyKey'])) {
$requestOptions['idempotencyKey'] = $headers['idempotencyKey'];
}
// call lib
$service = new \Adyen\Service\Payment($this->_client);
$service = new \Adyen\Service\Payment($this->client);
$request = $this->applicationInfo->addMerchantApplicationIntoRequest($request);
try {
$response = $service->authorise($request, $requestOptions);
} catch (\Adyen\AdyenException $e) {
$response['error'] = $e->getMessage();
$response['error'] = $e->getMessage();
}
return $response;
}
......
......@@ -24,9 +24,10 @@
namespace Adyen\Payment\Gateway\Http\Client;
use Magento\Payment\Gateway\Http\ClientInterface;
use Adyen\Payment\Model\ApplicationInfo;
/**
* Class TransactionSale
* Class TransactionPayment
*/
class TransactionPayment implements ClientInterface
{
......@@ -36,21 +37,28 @@ class TransactionPayment implements ClientInterface
*/
private $adyenHelper;
/**
* @var ApplicationInfo
*/
private $applicationInfo;
/**
* TransactionPayment constructor.
* @param \Adyen\Payment\Helper\Data $adyenHelper
* @param ApplicationInfo $applicationInfo
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
\Adyen\Payment\Helper\Data $adyenHelper,
\Adyen\Payment\Model\ApplicationInfo $applicationInfo
) {
$this->adyenHelper = $adyenHelper;
$this->applicationInfo = $applicationInfo;
}
/**
* @param \Magento\Payment\Gateway\Http\TransferInterface $transferObject
* @return mixed
* @throws ClientException
* @return array|mixed|string
* @throws \Adyen\AdyenException
*/
public function placeRequest(\Magento\Payment\Gateway\Http\TransferInterface $transferObject)
{
......@@ -73,6 +81,8 @@ class TransactionPayment implements ClientInterface
$requestOptions['idempotencyKey'] = $headers['idempotencyKey'];
}
$request = $this->applicationInfo->addMerchantApplicationIntoRequest($request);
try {
$response = $service->payments($request, $requestOptions);
} catch (\Adyen\AdyenException $e) {
......
......@@ -24,6 +24,7 @@
namespace Adyen\Payment\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Adyen\Payment\Model\ApplicationInfo;
/**
* @SuppressWarnings(PHPMD.LongVariable)
......@@ -881,7 +882,8 @@ class Data extends AbstractHelper
*/
public function getModuleVersion()
{
$moduleDir = $this->componentRegistrar->getPath(\Magento\Framework\Component\ComponentRegistrar::MODULE, 'Adyen_Payment');
$moduleDir = $this->componentRegistrar->getPath(\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Adyen_Payment');
$composerJson = file_get_contents($moduleDir . '/composer.json');
$composerJson = json_decode($composerJson, true);
......@@ -1470,11 +1472,10 @@ class Data extends AbstractHelper
$client = $this->createAdyenClient();
$client->setApplicationName("Magento 2 plugin");
$client->setXApiKey($apiKey);
$moduleVersion = $this->getModuleVersion();
$client->setAdyenPaymentSource($this->getModuleName(), $this->getModuleVersion());
$client->setAdyenPaymentSource($this->getModuleName(), $moduleVersion);
$client->setExternalPlatform($this->productMetadata->getName(), $this->productMetadata->getVersion());
if ($this->isDemoMode($storeId)) {
$client->setEnvironment(\Adyen\Environment::TEST);
} else {
......@@ -1514,7 +1515,7 @@ class Data extends AbstractHelper
$state = $objectManager->get('Magento\Framework\App\State');
$baseUrl = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB);
if ('adminhtml' === $state->getAreaCode()) {
$baseUrl = $this->helperBackend->getHomePageUrl();
$baseUrl = $this->helperBackend->getHomePageUrl();
}
$parsed = parse_url($baseUrl);
$origin = $parsed['scheme'] . "://" . $parsed['host'];
......@@ -1671,9 +1672,9 @@ class Data extends AbstractHelper
$order->addRelatedObject($billingAgreement);
} else {
$message = __('Failed to create billing agreement for this order. Reason(s): ') . join(
', ',
$billingAgreementErrors
);
', ',
$billingAgreementErrors
);
throw new \Exception($message);
}
......@@ -1761,6 +1762,7 @@ class Data extends AbstractHelper
return in_array(strtolower($country), $countryList);
}
/**
* Check if 3DS2.0 is enabled for credit cards
*
......@@ -1815,7 +1817,7 @@ class Data extends AbstractHelper
$response = ['threeDS2' => false];
if (!empty($type)) {
$response['type'] = $type;
$response['type'] = $type;
}
if ($type && $token) {
......
......@@ -26,7 +26,6 @@ namespace Adyen\Payment\Model;
use Adyen\Payment\Api\AdyenInitiateTerminalApiInterface;
use Adyen\Payment\Model\Ui\AdyenPosCloudConfigProvider;
use Adyen\Util\Util;
use Magento\Quote\Model\Quote;
class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
......@@ -263,10 +262,10 @@ class AdyenInitiateTerminalApi implements AdyenInitiateTerminalApiInterface
}
}
$saleToAcquirerData['applicationInfo']['merchantApplication']['version'] = $this->adyenHelper->getModuleVersion();
$saleToAcquirerData['applicationInfo']['merchantApplication']['name'] = $this->adyenHelper->getModuleName();
$saleToAcquirerData['applicationInfo']['externalPlatform']['version'] = $this->productMetadata->getVersion();
$saleToAcquirerData['applicationInfo']['externalPlatform']['name'] = $this->productMetadata->getName();
$saleToAcquirerData[ApplicationInfo::APPLICATION_INFO][ApplicationInfo::MERCHANT_APPLICATION][ApplicationInfo::VERSION] = $this->adyenHelper->getModuleVersion();
$saleToAcquirerData[ApplicationInfo::APPLICATION_INFO][ApplicationInfo::MERCHANT_APPLICATION][ApplicationInfo::NAME] = $this->adyenHelper->getModuleName();
$saleToAcquirerData[ApplicationInfo::APPLICATION_INFO][ApplicationInfo::EXTERNAL_PLATFORM][ApplicationInfo::VERSION] = $this->productMetadata->getVersion();
$saleToAcquirerData[ApplicationInfo::APPLICATION_INFO][ApplicationInfo::EXTERNAL_PLATFORM][ApplicationInfo::NAME] = $this->productMetadata->getName();
$saleToAcquirerDataBase64 = base64_encode(json_encode($saleToAcquirerData));
$request['SaleToPOIRequest']['PaymentRequest']['SaleData']['SaleToAcquirerData'] = $saleToAcquirerDataBase64;
return $request;
......
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2020 Adyen BV (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <magento@adyen.com>
*/
namespace Adyen\Payment\Model;
class ApplicationInfo
{
const APPLICATION_INFO = 'applicationInfo';
const MERCHANT_APPLICATION = 'merchantApplication';
const EXTERNAL_PLATFORM = 'externalPlatform';
const NAME = 'name';
const VERSION = 'version';
/**
* @var \Adyen\Payment\Helper\Data
*/
private $adyenHelper;
/**
* ApplicationInfo constructor.
* @param \Adyen\Payment\Helper\Data $adyenHelper
*/
public function __construct(
\Adyen\Payment\Helper\Data $adyenHelper
) {
$this->adyenHelper = $adyenHelper;
}
/**
* Add this application into request as we are missing the client function in the current library version
* when we upgrade to latest version we can use the client method instead
*
* @param $request
* @return mixed
*/
public function addMerchantApplicationIntoRequest($request)
{
// add applicationInfo into request
$request[self::APPLICATION_INFO][self::MERCHANT_APPLICATION][self::NAME] = $this->adyenHelper->getModuleName();
$request[self::APPLICATION_INFO][self::MERCHANT_APPLICATION][self::VERSION] = $this->adyenHelper->getModuleVersion();
return $request;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment