Skip to content

Commit

Permalink
[ECP-8715] Update to model based PHP Library (#2456)
Browse files Browse the repository at this point in the history
* [ECP-8715] Update to model based PHP Library

* Update adyen/php-api-library to ^17.0.0

* fix: Notification model `getUpdatedAt` method uses `created_at` date instead of `updated_at` (#2417)

Co-authored-by: Peter Ojo <[email protected]>

* Fix 301 Return value while running command console (#2396)

* [FIX] Fix 301 Return value while running command console

* Add Magento\Framework\Console\Cli constants since deprecated Symfony\Component\Console\Command\Command

---------

Co-authored-by: Rok Popov Ledinski <[email protected]>
Co-authored-by: Can Demiralp <[email protected]>
Co-authored-by: hossam-adyen <[email protected]>

* Update dependency squizlabs/php_codesniffer to ~3.8.0 (#2426)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: hossam-adyen <[email protected]>

* [ECP-8893] Allow usage of storedPaymentMethodId on headless payment requests (#2431)

* [ECP-8893] Allow usage of storedPaymentMethodId in the request

* [ECP-8893] Write unit tests

* [ECP-8825] Enable pipeline runs for external contributions (#2451)

* Add e2e flow for external contributors

* Add dispatch for debugging

* Tweak workflow name

* Tweak workflow

* Debug

* Remove draft pipeline

* Update e2e test pipeline

* Update GraphQL test pipeline

* Update Main CI workflow

* Update RestAPI test workflow

* DEBUG - Add test pipeline

* Add authorization step

* DEBUG - Test auth step

* Define an internal environment

* DEBUG - Try removing auth step and switch to conditional

* Remove trial pipeline

* Add designated worklfow for debugging

* Embed authorize step in build and add conditional

* Remove debug pipeline

* [ECP-8890] Update class references (#2441)

* [ECP-8878] Add pspReference to additional_information (#2443)

* [ECP-8787] Handle Pending resultCode on multishipping (#2448)

* [ECP-8822] Update management webhook endpoint (#2440)

* Support model based for gitcards payments and refactor

* Support model based for TransactionCancel and refactor

* Support model based for TransactionRefund and refactor

* Support model based for TransactionCapture

* Support model based for TransactionDonate

* Support model based for TransactionPaymentLinks

* Support model based for PaymentRequest

* Update Return controller

* Update OrdersApi

* Update PaymentsDetails helper

* Remove createAdyenCheckoutService and deprecated checkout service

* Use UtilityApi

* Use model based for diffrent places

* Use Adyen\Service\Management APIs

* Fix unit tests

* Fix unit tests

* Fix conflict getMerchantAccountsAndClientKey

* Fix all unit tests

* entirely parse models to array

* Fix TypeError: Adyen\Service\Checkout\OrdersApi::getBalanceOfGiftCard(): Argument #1 ($balanceCheckRequest) must be of type Adyen\Model\Checkout\BalanceCheckRequest, array given

* use query params to pass page size and pagenumber

* Fix new unit tests

* Add AdyenPaymentMethodsBalanceTest

* update DataTest new tests

* Sonarcloud check fixes

* Add MerchantAccountsTest

* Add more tests for ManagementHelperTest

* update TransactionPaymentTest

* Add TransactionCaptureTest

* Add TransactionCancelTest

* Update DataTest

* Add WebhookTestTest && AutoConfigurationTest

* Add more code coverage

* Add more code coverage in DataTest.php

* mark createAdyenRecurringService & createAdyenCheckoutService as deprecated

* Update ManagementHelper.php

* Small refactor

* unit test fixes

* CS

* Update PaymentDetailsTest.php

* [ECP-8715] Fix PaymentsDetails class after merge conflict

* [ECP-8715] Fix unit tests after merge conflict

* [ECP-8715] Fix unit tests after merge conflict

* [ECP-8715] Fix redundant line

* FixPaymentDetails

* [ECP-8715] Add type declarations

* [ECP-8715] Fix test webhook url builder

* [ECP-8715] Add type declarations

* [ECP-8715] Formatting

* [ECP-8715] Format the response array

* [ECP-8715] Format the response array and add type declarations

* [ECP-8715] Fix amount issue on second partial payment and declare types

* [ECP-8715] Add type declarations and use toArray() method

* [ECP-8715] Add type declarations and use toArray() method

* [ECP-8715] Formatting

* [ECP-8715] Use toArray() method

* [ECP-8715] Use toArray() method and add type declarations

* [ECP-8715] Use toArray() method and add type declarations remove unused exception

* [ECP-8715] Use toArray() method and add type declarations

* [ECP-8715] Use toArray() method and add type declarations

* [ECP-8715] Fx return value, use toArray() method and add type declarations

* [ECP-8715] Use toArray() method and add type declarations

* [ECP-8715] Use toArray() method and add type declarations

* [ECP-8715] Add type declarations

* [ECP-8715] Use toArray() method and add type declarations

* [ECP-8715] Fix Capture unit tests

* [ECP-8715] Fix mixed unit tests

* [ECP-8715] Fix Data helper unit tests

---------

Co-authored-by: Paweł Ledwig <[email protected]>
Co-authored-by: Peter Ojo <[email protected]>
Co-authored-by: Tuyen Nguyen <[email protected]>
Co-authored-by: Rok Popov Ledinski <[email protected]>
Co-authored-by: Can Demiralp <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Cenk Kucukiravul <[email protected]>
Co-authored-by: Can Demiralp <[email protected]>
  • Loading branch information
9 people authored Jul 24, 2024
1 parent da20986 commit 8f096fa
Show file tree
Hide file tree
Showing 33 changed files with 1,950 additions and 432 deletions.
47 changes: 23 additions & 24 deletions Controller/Adminhtml/Configuration/MerchantAccounts.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
<?php
/**
* ######
* ######
* ############ ####( ###### #####. ###### ############ ############
* ############# #####( ###### #####. ###### ############# #############
* ###### #####( ###### #####. ###### ##### ###### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ##### ######
* ###### ###### #####( ###### #####. ###### ##### ##### ######
* ############# ############# ############# ############# ##### ######
* ############ ############ ############# ############ ##### ######
* ######
* #############
* ############
*
* Adyen Payment Module
* Adyen Payment module (https://www.adyen.com/)
*
* Copyright (c) 2022 Adyen N.V.
* This file is open source and available under the MIT license.
* See the LICENSE file for more info.
* Copyright (c) 2022 Adyen N.V. (https://www.adyen.com/)
* See LICENSE.txt for license details.
*
* Author: Adyen <[email protected]>
*/
Expand All @@ -28,21 +15,28 @@
use Adyen\ConnectionException;
use Adyen\Payment\Helper\ManagementHelper;
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Backend\App\Action\Context;
use Magento\Framework\Exception\NoSuchEntityException;

class MerchantAccounts extends Action
{
/**
* @var ManagementHelper
*/
protected $managementHelper;
protected ManagementHelper $managementHelper;

/**
* @var JsonFactory
*/
protected $resultJsonFactory;
protected JsonFactory $resultJsonFactory;

/**
* @param Context $context
* @param ManagementHelper $managementHelper
* @param JsonFactory $resultJsonFactory
*/
public function __construct(
Context $context,
ManagementHelper $managementHelper,
Expand All @@ -54,21 +48,27 @@ public function __construct(
}

/**
* @return \Magento\Framework\Controller\Result\Json
* @return Json
* @throws NoSuchEntityException
*/
public function execute()
public function execute(): Json
{
$resultJson = $this->resultJsonFactory->create();
try {
$apiKey = $this->getRequest()->getParam('apiKey', '');
$demoMode = (int) $this->getRequest()->getParam('demoMode');
//Use the stored xapi key if the return value is encrypted chars only or it is empty,
// Use the stored xapi key if the return value is encrypted chars only or it is empty,
if (!empty($apiKey) && preg_match('/^\*+$/', (string) $apiKey)) {
$apiKey = '';
}

$managementApiService = $this->managementHelper->getManagementApiService($apiKey, $demoMode);
$response = $this->managementHelper->getMerchantAccountsAndClientKey($managementApiService);
$client = $this->managementHelper->getAdyenApiClient($apiKey, $demoMode);
$accountMerchantLevelApi = $this->managementHelper->getAccountMerchantLevelApi($client);
$myAPICredentialApi = $this->managementHelper->getMyAPICredentialApi($client);
$response = $this->managementHelper->getMerchantAccountsAndClientKey(
$accountMerchantLevelApi,
$myAPICredentialApi
);

$resultJson->setData($response);
return $resultJson;
Expand All @@ -83,4 +83,3 @@ public function execute()
return $resultJson;
}
}

26 changes: 12 additions & 14 deletions Controller/Adminhtml/Configuration/WebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
use Adyen\Payment\Helper\ManagementHelper;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\ResponseInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Store\Model\StoreManager;

Expand All @@ -28,27 +26,27 @@ class WebhookTest extends Action
/**
* @var ManagementHelper
*/
private $managementApiHelper;
private ManagementHelper $managementApiHelper;

/**
* @var Config
*/
protected $configHelper;
protected Config $configHelper;

/**
* @var JsonFactory
*/
protected $resultJsonFactory;
protected JsonFactory $resultJsonFactory;

/**
* @var Context
*/
protected $context;
protected Context $context;

/**
* @var StoreManager
*/
protected $storeManager;
protected StoreManager $storeManager;

/**
* @param Context $context
Expand All @@ -73,11 +71,11 @@ public function __construct(
}

/**
* @return ResponseInterface|Json|ResultInterface
* @return Json
* @throws AdyenException
* @throws NoSuchEntityException
*/
public function execute()
public function execute(): Json
{
$storeId = $this->storeManager->getStore()->getId();

Expand All @@ -87,11 +85,11 @@ public function execute()
$environment = $isDemoMode ? 'test' : 'live';
$apiKey = $this->configHelper->getApiKey($environment, $storeId);

$managementApiService = $this->managementApiHelper->getManagementApiService($apiKey, $isDemoMode);
$response = $this->managementApiHelper->webhookTest($merchantAccount, $webhookId, $managementApiService);

$success = isset($response['data']) &&
in_array('success', array_column($response['data'], 'status'), true);
$client = $this->managementApiHelper->getAdyenApiClient($apiKey, $isDemoMode);
$service =$this->managementApiHelper->getWebhooksMerchantLevelApi($client);
$response = $this->managementApiHelper->webhookTest($merchantAccount, $webhookId, $service);
$success = isset($response) &&
in_array('success', array_column($response->getData(), 'status'), true);

$resultJson = $this->resultJsonFactory->create();
$resultJson->setData([
Expand Down
51 changes: 38 additions & 13 deletions Gateway/Http/Client/TransactionCancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,29 @@

use Adyen\AdyenException;
use Adyen\Client;
use Adyen\Model\Checkout\PaymentCancelRequest;
use Adyen\Payment\Helper\Data;
use Adyen\Payment\Helper\Idempotency;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Payment\Gateway\Http\ClientInterface;
use Magento\Payment\Gateway\Http\TransferInterface;

class TransactionCancel implements ClientInterface
{
/**
* @var Data
*/
private Data $adyenHelper;

/**
* @var Idempotency
*/
private Idempotency $idempotencyHelper;

/**
* @param Data $adyenHelper
* @param Idempotency $idempotencyHelper
*/
public function __construct(
Data $adyenHelper,
Idempotency $idempotencyHelper
Expand All @@ -31,34 +44,46 @@ public function __construct(
$this->idempotencyHelper = $idempotencyHelper;
}

/**
* @param TransferInterface $transferObject
* @return array
* @throws AdyenException
* @throws NoSuchEntityException
*/
public function placeRequest(TransferInterface $transferObject): array
{
$request = $transferObject->getBody();
$requests = $transferObject->getBody();
$headers = $transferObject->getHeaders();
$clientConfig = $transferObject->getClientConfig();

$client = $this->adyenHelper->initializeAdyenClientWithClientConfig($clientConfig);
$service = $this->adyenHelper->createAdyenCheckoutService($client);
$response = [];
$service = $this->adyenHelper->initializeModificationsApi($client);
$responseData = [];

foreach ($request as $requests) {
foreach ($requests as $request) {
$idempotencyKey = $this->idempotencyHelper->generateIdempotencyKey(
$requests,
$request,
$headers['idempotencyExtraData'] ?? null
);
$requestOptions['idempotencyKey'] = $idempotencyKey;
$requestOptions['headers'] = $this->adyenHelper->buildRequestHeaders();
$this->adyenHelper->logRequest($requests, Client::API_CHECKOUT_VERSION, '/cancels');
$this->adyenHelper->logRequest($request, Client::API_CHECKOUT_VERSION, '/cancels');
$paymentCancelRequest = new PaymentCancelRequest($request);

try {
$responses = $service->cancels($requests, $requestOptions);
$response = $service->cancelAuthorisedPaymentByPspReference(
$request['paymentPspReference'],
$paymentCancelRequest,
$requestOptions
);
$responseData = $response->toArray();
$this->adyenHelper->logResponse($responseData);
} catch (AdyenException $e) {
$response['error'] = $e->getMessage();
$responseData['error'] = $e->getMessage();
$this->adyenHelper->logAdyenException($e);
}
$this->adyenHelper->logResponse($responses);

$response = $responses;
}

return $response;
return $responseData;
}

}
Loading

0 comments on commit 8f096fa

Please sign in to comment.