diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 8331abca6..968ede2ad 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -1,17 +1,16 @@ name: Magento 2 E2E Pipeline run-name: Adyen Magento 2 Payment Plugin E2E tests -on: +on: pull_request: - types: [opened, synchronize] + types: [opened, synchronize, ready_for_review] + pull_request_target: + types: [opened, synchronize, ready_for_review] jobs: build: - if: | - ${{ - github.event.pull_request.draft == false && - (github.actor != 'renovate[bot]' || github.actor != 'lgtm-com[bot]') - }} + if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) + environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }} runs-on: group: larger-runners labels: ubuntu-latest-8-cores @@ -43,7 +42,7 @@ jobs: - name: Install plugin run: docker exec -u www-data magento2-container make plugin - + - name: Kill Cron Jobs run: docker exec magento2-container /etc/init.d/cron stop @@ -51,7 +50,7 @@ jobs: uses: actions/checkout@v3 with: repository: Adyen/adyen-magento2-dev - ref: 'main' + ref: "main" token: ${{ secrets.ADYEN_AUTOMATION_BOT_TEST_ACCESS_TOKEN }} path: Developer diff --git a/.github/workflows/graphql-test.yml b/.github/workflows/graphql-test.yml index 0486e3e4d..ef1627349 100644 --- a/.github/workflows/graphql-test.yml +++ b/.github/workflows/graphql-test.yml @@ -1,8 +1,10 @@ name: GraphQL Tests -on: [pull_request] +on: [pull_request, pull_request_target] jobs: build: + if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) + environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }} strategy: matrix: php-version: ["8.1"] diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a844d5a96..272f8b25c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,47 +1,49 @@ name: Main CI workflow -on: [pull_request] +on: [pull_request, pull_request_target] jobs: build: + if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) + environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }} runs-on: ubuntu-latest - + strategy: matrix: php-version: [8.1] - + steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Use PHP ${{ matrix.php-version }} - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - tools: composer:v1 - - - name: Test plugin installation - run: | - echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json - composer install --prefer-dist - env: - CI: true - MAGENTO_USERNAME: ${{ secrets.MAGENTO_USERNAME }} - MAGENTO_PASSWORD: ${{ secrets.MAGENTO_PASSWORD }} - - - name: Code Sniffer - run: vendor/bin/phpcs --extensions=php,phtml --error-severity=10 --ignore-annotations - - - name: Run PHPUnit - run: vendor/bin/phpunit --coverage-clover=build/clover.xml --log-junit=build/tests-log.xml -c Test/phpunit.xml Test/Unit - - - name: Fix code coverage paths - run: sed -i "s;`pwd`/;;g" build/*.xml - - - name: SonarCloud Scan - if: ${{ env.SONAR_TOKEN }} - uses: SonarSource/sonarcloud-github-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Use PHP ${{ matrix.php-version }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer:v1 + + - name: Test plugin installation + run: | + echo "{\"http-basic\":{\"repo.magento.com\":{\"username\":\"${MAGENTO_USERNAME}\",\"password\":\"${MAGENTO_PASSWORD}\"}}}" > auth.json + composer install --prefer-dist + env: + CI: true + MAGENTO_USERNAME: ${{ secrets.MAGENTO_USERNAME }} + MAGENTO_PASSWORD: ${{ secrets.MAGENTO_PASSWORD }} + + - name: Code Sniffer + run: vendor/bin/phpcs --extensions=php,phtml --error-severity=10 --ignore-annotations + + - name: Run PHPUnit + run: vendor/bin/phpunit --coverage-clover=build/clover.xml --log-junit=build/tests-log.xml -c Test/phpunit.xml Test/Unit + + - name: Fix code coverage paths + run: sed -i "s;`pwd`/;;g" build/*.xml + + - name: SonarCloud Scan + if: ${{ env.SONAR_TOKEN }} + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} diff --git a/.github/workflows/restapi-test.yml b/.github/workflows/restapi-test.yml index d7227b9b9..ba4607099 100644 --- a/.github/workflows/restapi-test.yml +++ b/.github/workflows/restapi-test.yml @@ -1,8 +1,10 @@ name: REST API Tests -on: [pull_request] +on: [pull_request, pull_request_target] jobs: build: + if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) + environment: ${{ (github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository) && 'external' || 'internal' }} strategy: matrix: php-version: ["8.1"] diff --git a/Block/Checkout/Multishipping/Success.php b/Block/Checkout/Multishipping/Success.php index f718a7ff2..f647976a6 100644 --- a/Block/Checkout/Multishipping/Success.php +++ b/Block/Checkout/Multishipping/Success.php @@ -28,12 +28,12 @@ class Success extends \Magento\Multishipping\Block\Checkout\Success { - const FINAL_RESULT_CODES = array( - PaymentResponseHandler::AUTHORISED, - PaymentResponseHandler::PENDING, - PaymentResponseHandler::REFUSED, - PaymentResponseHandler::PRESENT_TO_SHOPPER - ); + const ACTION_REQUIRED_STATUSES = [ + PaymentResponseHandler::REDIRECT_SHOPPER, + PaymentResponseHandler::IDENTIFY_SHOPPER, + PaymentResponseHandler::CHALLENGE_SHOPPER, + PaymentResponseHandler::PENDING + ]; /** * @var bool @@ -122,7 +122,7 @@ public function __construct( public function renderAction() { foreach ($this->paymentResponseEntities as $paymentResponseEntity) { - if (!in_array($paymentResponseEntity['result_code'], self::FINAL_RESULT_CODES)) { + if (in_array($paymentResponseEntity['result_code'], self::ACTION_REQUIRED_STATUSES)) { return true; } } @@ -189,7 +189,7 @@ private function setOrderInfo($orderIds) public function getIsPaymentCompleted(int $orderId) { // TODO check for all completed responses, not only Authorised, Refused, Pending or PresentToShopper - return in_array($this->ordersInfo[$orderId]['resultCode'], self::FINAL_RESULT_CODES); + return !in_array($this->ordersInfo[$orderId]['resultCode'], self::ACTION_REQUIRED_STATUSES); } public function getPaymentButtonLabel(int $orderId) diff --git a/Gateway/Response/PaymentPosCloudHandler.php b/Gateway/Response/PaymentPosCloudHandler.php index b8a1ae215..b697b7b3c 100644 --- a/Gateway/Response/PaymentPosCloudHandler.php +++ b/Gateway/Response/PaymentPosCloudHandler.php @@ -57,6 +57,10 @@ public function handle(array $handlingSubject, array $response) ); $payment->setAdditionalInformation('additionalData', $paymentResponseDecoded['additionalData']); + if (isset($paymentResponseDecoded['additionalData']['pspReference'])) { + $payment->setAdditionalInformation('pspReference', $paymentResponseDecoded['additionalData']['pspReference']); + } + $this->vaultHelper->handlePaymentResponseRecurringDetails( $payment->getOrder()->getPayment(), $paymentResponseDecoded diff --git a/Model/Api/PaymentRequest.php b/Model/Api/PaymentRequest.php index 8abecb4fd..63c27f2df 100755 --- a/Model/Api/PaymentRequest.php +++ b/Model/Api/PaymentRequest.php @@ -12,7 +12,7 @@ namespace Adyen\Payment\Model\Api; use Adyen\AdyenException; -use Adyen\Config; +use Adyen\Payment\Helper\Config; use Adyen\Payment\Helper\Data; use Adyen\Payment\Logger\AdyenLogger; use Adyen\Payment\Model\RecurringType; @@ -101,8 +101,8 @@ public function authorise3d(Payment $payment): mixed ]; try { - $client = $this->configHelper->initializeAdyenClient($storeId); - $service = $this->configHelper->createAdyenCheckoutService($client); + $client = $this->adyenHelper->initializeAdyenClient($storeId); + $service = $this->adyenHelper->createAdyenCheckoutService($client); $result = $service->paymentsDetails($request); } catch (AdyenException $e) { throw new LocalizedException(__('3D secure failed')); @@ -173,13 +173,13 @@ public function listRecurringContractByType(string $shopperReference, int $store $contract = ['contract' => $recurringType]; $request = [ "merchantAccount" => $this->configHelper->getAdyenAbstractConfigData('merchant_account', $storeId), - "shopperReference" => $this->configHelper->padShopperReference($shopperReference), + "shopperReference" => $this->adyenHelper->padShopperReference($shopperReference), "recurring" => $contract, ]; // call lib - $client = $this->configHelper->initializeAdyenClient($storeId); - $service = $this->configHelper->createAdyenRecurringService($client); + $client = $this->adyenHelper->initializeAdyenClient($storeId); + $service = $this->adyenHelper->createAdyenRecurringService($client); $result = $service->listRecurringDetails($request); return $result; @@ -200,7 +200,7 @@ public function disableRecurringContract( int $storeId ): bool { $merchantAccount = $this->configHelper->getAdyenAbstractConfigData("merchant_account", $storeId); - $shopperReference = $this->configHelper->padShopperReference($shopperReference); + $shopperReference = $this->adyenHelper->padShopperReference($shopperReference); $request = [ "merchantAccount" => $merchantAccount, "shopperReference" => $shopperReference, @@ -208,8 +208,8 @@ public function disableRecurringContract( ]; // call lib - $client = $this->configHelper->initializeAdyenClient($storeId); - $service = $this->configHelper->createAdyenRecurringService($client); + $client = $this->adyenHelper->initializeAdyenClient($storeId); + $service = $this->adyenHelper->createAdyenRecurringService($client); try { $result = $service->disable($request); diff --git a/Model/Config/Backend/WebhookCredentials.php b/Model/Config/Backend/WebhookCredentials.php index 5f4f8853c..77f0d9e95 100644 --- a/Model/Config/Backend/WebhookCredentials.php +++ b/Model/Config/Backend/WebhookCredentials.php @@ -62,7 +62,7 @@ public function beforeSave() $username = $this->getValue(); $password = $this->getFieldsetDataValue('notification_password'); - $webhookUrl = $this->url->getBaseUrl() . 'adyen/process/json'; + $webhookUrl = $this->url->getBaseUrl() . 'adyen/webhook'; $isDemoMode = (int)$this->getFieldsetDataValue('demo_mode'); $environment = $isDemoMode ? 'test' : 'live'; diff --git a/view/frontend/templates/checkout/multishipping/success.phtml b/view/frontend/templates/checkout/multishipping/success.phtml index 373325898..7216b59b1 100644 --- a/view/frontend/templates/checkout/multishipping/success.phtml +++ b/view/frontend/templates/checkout/multishipping/success.phtml @@ -187,9 +187,7 @@ $paymentResponseEntities = $block->getPaymentResponseEntities(); try { let response = $(this).data('adyen-response'); - // Only show the modal for some result codes - const modalResponseCodes = ['IdentifyShopper']; - if (modalResponseCodes.includes(response.resultCode)) { + if (response.resultCode !== 'RedirectShopper') { showModal(); }