Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
a285fa5
Initial commit
bartoszkaluzny-solteq Jan 27, 2025
f960173
SQNETS-32: create Adobe Commerce module
bartoszkaluzny-solteq Jan 27, 2025
f283d75
SQNETS-32: update README.md
bartoszkaluzny-solteq Jan 27, 2025
577589d
SQNETS-32: initial module commit
bartoszkaluzny-solteq Jan 27, 2025
b5db912
SQNETS-32: add registration.php
bartoszkaluzny-solteq Jan 27, 2025
a5af015
SQNETS-40: Fix config virtual type
konrad-konieczny Jan 27, 2025
3da9a9c
Merge pull request #1 from Solteq/SQNETS-40
konrad-konieczny Jan 28, 2025
7894b26
SQNETS-40: remove unused methods
konrad-konieczny Jan 30, 2025
8dbc2df
SQNETS-32: improve admin configuration
bartoszkaluzny-solteq Jan 30, 2025
033ab52
SQNETS-32: improve constructor
bartoszkaluzny-solteq Jan 30, 2025
d789bd7
SQNETS: add code-validation.yml
bartoszkaluzny-solteq Jan 30, 2025
efb1819
Merge branch 'main' into SQNETS-32
bartoszkaluzny-solteq Jan 30, 2025
311b960
SQNETS-32: simplify FQN
bartoszkaluzny-solteq Jan 30, 2025
57f58a9
Merge remote-tracking branch 'refs/remotes/origin/SQNETS-32' into SQN…
konrad-konieczny Jan 30, 2025
1ed1eb7
SQNETS-32/test-button: add test button
konrad-konieczny Jan 30, 2025
4ebedb5
SQNETS-32/test-button: remove type config
konrad-konieczny Jan 30, 2025
26d2d1e
SQNETS-32-test-button: remove comments
konrad-konieczny Jan 30, 2025
90092a0
SQNETS: add phpunit
bartoszkaluzny-solteq Jan 31, 2025
d63cbe6
SQNETS-32: add PHPDocs
bartoszkaluzny-solteq Jan 31, 2025
8c733ac
SQNETS-32: improve logs
bartoszkaluzny-solteq Jan 31, 2025
eb1e2df
SQNETS: add magento-enterprise-edition for github actions
bartoszkaluzny-solteq Jan 31, 2025
aa4ef66
Merge branch 'SQNETS-32' into SQNETS-32-test-button
bartoszkaluzny-solteq Jan 31, 2025
b8661bc
Merge pull request #3 from Solteq/SQNETS-32-test-button
bartoszkaluzny-solteq Jan 31, 2025
df7ca88
SQNETS-32: improve gatewayConfig
bartoszkaluzny-solteq Jan 31, 2025
15e7f09
Merge pull request #2 from Solteq/SQNETS-32
bartoszkaluzny-solteq Jan 31, 2025
d6bfc25
SQNETS-32: add nexi as methodCode
bartoszkaluzny-solteq Jan 31, 2025
dfa9196
SQNETS-32: fix code-validation comments
bartoszkaluzny-solteq Jan 31, 2025
bc57165
SQNETS-32: fix comments
bartoszkaluzny-solteq Jan 31, 2025
19f6913
SQNETS-32: update client token
bartoszkaluzny-solteq Jan 31, 2025
29d959b
SQNETS-32: fix code-validation comments
bartoszkaluzny-solteq Jan 31, 2025
504ae88
Merge pull request #4 from Solteq/SQNETS-32
konrad-konieczny Feb 4, 2025
4c3636a
SQNETS-49: add AuthorizeRequestBuilder
konrad-konieczny Feb 4, 2025
eb1a1fb
Merge remote-tracking branch 'origin/main' into SQNETS-49
konrad-konieczny Feb 4, 2025
924eb72
Merge branch 'refs/heads/main' into SQNETS-49
konrad-konieczny Feb 4, 2025
726118f
SQNETS-49: fix di const, add error handling, fix request builder
konrad-konieczny Feb 5, 2025
66b55b8
SQNETS-49: fix test connection
konrad-konieczny Feb 5, 2025
7924421
SQNETS-49: add hpp payment and webhook handling
konrad-konieczny Feb 10, 2025
82cf32d
SQNETS-49: add hpp payment and webhook handling
konrad-konieczny Feb 10, 2025
6729794
SQNETS-49: add hpp payment and webhook handling
konrad-konieczny Feb 10, 2025
974db95
SQNETS-49: add transaction and invoice creation
konrad-konieczny Feb 11, 2025
a9c5fe7
SQNETS-49: remove error
konrad-konieczny Feb 11, 2025
ca686c9
SQNETS-49: add consumer
konrad-konieczny Feb 11, 2025
1e30f38
Merge pull request #5 from Solteq/SQNETS-49
konrad-konieczny Feb 11, 2025
d69b652
SQNETS-49: remove redirect and debug changes
konrad-konieczny Feb 14, 2025
0a38a5c
Merge pull request #6
konrad-konieczny Feb 14, 2025
665a65a
SQNETS-49: fix test connection
konrad-konieczny Feb 14, 2025
3541ba7
Merge pull request #7
konrad-konieczny Feb 14, 2025
97c06fb
main: fix test connection field mapping
konrad-konieczny Feb 14, 2025
c8d73fb
SQNETS-49: add cancel action logic
konrad-konieczny Feb 17, 2025
9e97258
SQNETS-49: add conditions and error handling for return action
konrad-konieczny Feb 17, 2025
b797736
SQNETS-49: send consumer informations to nexi
konrad-konieczny Feb 17, 2025
4d9a377
SQNETS-49: handle logged in customers api call
konrad-konieczny Feb 18, 2025
c76471d
SQNETS-49: fix tests
konrad-konieczny Feb 18, 2025
94c6e49
SQNETS-49: fix namespace
konrad-konieczny Feb 18, 2025
1689da6
SQNETS-49: remove logger class
konrad-konieczny Feb 19, 2025
2bcf8e5
SQNETS-49: fix di
konrad-konieczny Feb 19, 2025
bbc600f
SQNETS-49: add api factory di
konrad-konieczny Feb 19, 2025
ac1b4cf
SQNETS-49: fix static code validation comments
konrad-konieczny Feb 20, 2025
bbd9bfc
SQNETS-49: fix static code validation comments
konrad-konieczny Feb 20, 2025
9181804
SQNETS-49: fix static code validation comments
konrad-konieczny Feb 20, 2025
27dcc06
Merge pull request #8 from Solteq/SQNETS-49
konrad-konieczny Feb 20, 2025
3a4c0ff
SQNETS-49: add comments
konrad-konieczny Feb 20, 2025
f6c6fd9
SQNETS-49: add comments
konrad-konieczny Feb 20, 2025
3faf050
SQNETS-49: add comments
konrad-konieczny Feb 20, 2025
8f9b965
SQNETS-49: add comments
konrad-konieczny Feb 20, 2025
e471a46
Merge pull request #9 from Solteq/SQNETS-49
konrad-konieczny Feb 21, 2025
1c1c995
SQNETS-49: reformat
konrad-konieczny Feb 21, 2025
f291cf7
Merge pull request #10
konrad-konieczny Feb 21, 2025
b805bf9
SQNETS-49: cleanup di file
konrad-konieczny Feb 21, 2025
db592ee
Merge pull request #11 from Solteq/SQNETS-49
konrad-konieczny Feb 21, 2025
6624531
SQNETS-47: handle capture command
konrad-konieczny Feb 21, 2025
8de0236
SQNETS-47: remove unused imports
konrad-konieczny Feb 21, 2025
17d654a
SQNETS-47: reformat
konrad-konieczny Feb 24, 2025
641b68f
SQNETS-34: webhooks configuration
bartoszkaluzny-solteq Feb 24, 2025
9ba32a2
Merge pull request #12 from Solteq/SQNETS-47
konrad-konieczny Feb 24, 2025
fc9c372
SQNETS-34: change class name
bartoszkaluzny-solteq Feb 25, 2025
01297ae
SQNETS-34: improve webhook handler
bartoszkaluzny-solteq Feb 25, 2025
2cdf15b
SQNETS-47: change config, reformat request builder
konrad-konieczny Feb 25, 2025
1f5ec57
Merge pull request #14
konrad-konieczny Feb 25, 2025
d1dea32
module draft with HPP integration
konrad-konieczny Feb 25, 2025
93fe256
SQNETS-34: add more webhooks in DI
bartoszkaluzny-solteq Feb 27, 2025
a973e06
SQNETS-34: create service for 'payment.reservation.created.v2'
bartoszkaluzny-solteq Feb 27, 2025
bfb9d1e
SQNETS-34: create service class for 'payment.created' event
bartoszkaluzny-solteq Feb 27, 2025
6b0ecc6
SQNETS-34: improve PaymentCreated service
bartoszkaluzny-solteq Feb 27, 2025
c2bced8
SQNETS-34: improve handler & controller
bartoszkaluzny-solteq Feb 27, 2025
e893647
SQNETS-34: update PaymentCreated service
bartoszkaluzny-solteq Feb 27, 2025
f0a4049
SQNETS-34: create service for 'payment.charge.created.v2'
bartoszkaluzny-solteq Feb 27, 2025
1744e5d
SQNETS-34: create data loader
bartoszkaluzny-solteq Feb 27, 2025
be00250
SQNETS-34: push empty webhooks
bartoszkaluzny-solteq Mar 3, 2025
c3680e6
SQNETS-34: add refund webhook
bartoszkaluzny-solteq Mar 3, 2025
bec5550
fixes regarding to pr comments
konrad-konieczny Mar 17, 2025
e4f93e7
Merge pull request #56 from konrad-konieczny/hpp-pr-comments
konrad-konieczny Mar 17, 2025
b4dea16
use hosted payment method
konrad-konieczny Mar 17, 2025
e683d80
Merge pull request #57 from konrad-konieczny/hpp-pr-comments
konrad-konieczny Mar 17, 2025
e31b99d
SQNETS-34: improve webhook controller
bartoszkaluzny-solteq Mar 27, 2025
0a39b56
SQNETS-34: improve webhook handler
bartoszkaluzny-solteq Mar 27, 2025
71f2329
SQNETS-34: update webhooks models
bartoszkaluzny-solteq Mar 27, 2025
6af9eac
Refactor payment cancellation logic and improve error handling
konrad-konieczny Mar 31, 2025
400f27b
SQNETS-59: make terms and condition fields required
bartoszkaluzny-solteq Mar 31, 2025
e2f2b44
Improve logging in ReturnAction for better debugging
konrad-konieczny Mar 31, 2025
1aa4c10
Add a blank line for improved readability in TestConnection.php
konrad-konieczny Mar 31, 2025
05eee67
Refactor payment initialization to use constants for status and impro…
konrad-konieczny Mar 31, 2025
fb5ae31
Fix condition check for payment authorization action in ReturnAction
konrad-konieczny Apr 1, 2025
d2b146f
Enhance logging in ReturnAction to include payment and order IDs for …
konrad-konieczny Apr 1, 2025
23f0853
Fix conditional structure in ReturnAction for payment status check
konrad-konieczny Apr 1, 2025
65f0abc
Fix formatting in ReturnAction for charge transaction ID assignment
konrad-konieczny Apr 1, 2025
159f6b0
Merge pull request #20 from Solteq/SQNETS-59
bartoszkaluzny-solteq Apr 1, 2025
af8e01d
Implement payment creation and termination in TestConnection, enhanci…
konrad-konieczny Apr 1, 2025
eaf3a85
Fix type casting for payment amount in CreatePaymentRequestBuilder to…
konrad-konieczny Apr 1, 2025
582f498
Update URLs in TestConnection and CreatePaymentRequestBuilder for suc…
konrad-konieczny Apr 1, 2025
6598697
Fix type casting for payment amount in CreatePaymentRequestBuilder to…
konrad-konieczny Apr 1, 2025
e866717
SQNETS-34: remove unnecessary arguments
bartoszkaluzny-solteq Apr 1, 2025
100ba1b
Merge pull request #19 from Solteq/develop-2.0.0
konrad-konieczny Apr 1, 2025
78e2257
SQNETS-34: simplify transaction loading by removing try-catch block
konrad-konieczny Apr 1, 2025
9920805
SQNETS-34: refactor transaction loading by removing try-catch block
konrad-konieczny Apr 1, 2025
d92d495
refactor WebhookDataLoader constructor for improved readability
konrad-konieczny Apr 1, 2025
eb76b8e
Merge branch 'develop-2.0.0' into SQNETS-34
konrad-konieczny Apr 1, 2025
e8adc35
Enhance webhook logging and refactor webhook handler argument naming
konrad-konieczny Apr 1, 2025
76d8d9f
Refactor webhook handling and enhance error logging; add serializer f…
konrad-konieczny Apr 2, 2025
2256393
Fix tax rate calculation to handle division by zero in SalesDocumentI…
konrad-konieczny Apr 2, 2025
b0ad646
Refactor webhook handling: update namespaces, improve transaction loa…
konrad-konieczny Apr 2, 2025
e466bd2
Add transaction builder parameter to PaymentReservationCreated constr…
konrad-konieczny Apr 2, 2025
786b5bd
Remove unused processOrder method and related code from PaymentReserv…
konrad-konieczny Apr 2, 2025
9653a08
Fix typo in processWebhook parameter name and update references
konrad-konieczny Apr 2, 2025
1aa6b9d
Add OrderRepositoryInterface to PaymentRefundCompleted for order saving
konrad-konieczny Apr 2, 2025
4015f6e
Add TODO comments for refund completed event handling in PaymentRefun…
konrad-konieczny Apr 2, 2025
de8c001
Refactor PaymentRefundCompleted constructor to use readonly propertie…
konrad-konieczny Apr 2, 2025
6403d34
Implement WebhookProcessorInterface in PaymentRefundCompleted and upd…
konrad-konieczny Apr 2, 2025
2f9bd65
Add check for existing transaction in processWebhook method of Paymen…
konrad-konieczny Apr 2, 2025
21861c1
remove github actions
konrad-konieczny Apr 3, 2025
0c0fec2
Merge pull request #13 from Solteq/SQNETS-34
konrad-konieczny Apr 3, 2025
5dd514f
Merge remote-tracking branch 'refs/remotes/origin/main' into develop-…
konrad-konieczny Apr 3, 2025
bfaa5fb
Refactor PaymentRefundCompleted to handle full refunds and add credit…
konrad-konieczny Apr 3, 2025
b85b248
Refactor WebhookHandler to use WebhookProcessorInterface and update p…
konrad-konieczny Apr 4, 2025
7b6b11c
Enhance Webhook class with improved constructor documentation and CSR…
konrad-konieczny Apr 4, 2025
16f1106
Enhance CreatePaymentRequestBuilder with additional method documentat…
konrad-konieczny Apr 4, 2025
4d2891d
Merge remote-tracking branch 'origin/SQNETS-34' into SQNETS-34
konrad-konieczny Apr 4, 2025
af4ebcf
Enhance CreatePaymentRequestBuilder with type hinting for buildOrder …
konrad-konieczny Apr 4, 2025
45c700f
Enhance PaymentRefundCompleted with constructor parameter documentati…
konrad-konieczny Apr 4, 2025
a10cf36
Enhance PaymentRefundCompleted and CreatePaymentRequestBuilder with t…
konrad-konieczny Apr 4, 2025
1acf413
Enhance WebhookHandler with constructor documentation and type hintin…
konrad-konieczny Apr 4, 2025
6f817f0
Merge pull request #21 from Solteq/SQNETS-34
konrad-konieczny Apr 4, 2025
4bdc7f4
Merge branch 'main' into develop-2.0.0
konrad-konieczny Apr 4, 2025
9d241d7
Add test API keys to configuration and update key retrieval logic
konrad-konieczny Apr 7, 2025
4301ffc
Add support for test API key and enhance payment processing logic
konrad-konieczny Apr 14, 2025
74d1299
Add method to retrieve test API key and update payment API connection…
konrad-konieczny Apr 14, 2025
4a658c5
Rename API key references to secret key in configuration and update r…
konrad-konieczny Apr 14, 2025
808ce30
Add auto capture option to payment configuration
konrad-konieczny Apr 14, 2025
102208c
Add webhook secret generation functionality and update module version
konrad-konieczny Apr 14, 2025
33e8001
SQNETS-72: add validation for config fields
bartoszkaluzny-solteq May 7, 2025
95b374f
Add GitHub Actions workflow for PHP code validation and unit testing
konrad-konieczny May 9, 2025
bf2cdae
Add GitHub Actions workflow for PHP code validation and unit testing
konrad-konieczny May 9, 2025
50b5c05
Merge pull request #24 from Solteq/SQNETS-72
bartoszkaluzny-solteq May 9, 2025
29e7b10
Update payment order reference and require specific version of paymen…
konrad-konieczny May 9, 2025
9998782
Refactor code for improved readability and maintainability; add stric…
konrad-konieczny May 12, 2025
fcb4f03
Merge remote-tracking branch 'origin/develop-2.0.0' into develop-2.0.0
konrad-konieczny May 12, 2025
e876125
Implement authorization check in Webhook and update webhook processor…
konrad-konieczny May 12, 2025
8f1a5ab
remove merchant_handles_consumer_data configuration and related metho…
konrad-konieczny May 12, 2025
3d027d3
Remove merchant_handles_consumer_data from config and set merchantHan…
konrad-konieczny May 13, 2025
6a39086
Add StringSanitizer for input sanitization in SalesDocumentItemsBuild…
konrad-konieczny May 13, 2025
afff8d9
Add StringSanitizer dependency to CreatePaymentRequestBuilder constru…
konrad-konieczny May 13, 2025
c1258e3
Remove unnecessary comments and whitespace in StringSanitizer and Pay…
konrad-konieczny May 13, 2025
75aebe3
add phone number parser
konrad-konieczny May 13, 2025
479f48b
Add phone number parsing functionality to CreatePaymentRequestBuilder
konrad-konieczny May 13, 2025
3b6fba3
Add StringSanitizer dependency and improve escaping in testconnection…
konrad-konieczny May 13, 2025
25f9061
Merge remote-tracking branch 'origin-solteq/develop-2.0.0' into devel…
konrad-konieczny May 15, 2025
19ca7af
Refactor PhoneNumber return type in getNumber method
konrad-konieczny May 20, 2025
f29f610
Update copyright holder in LICENSE file
konrad-konieczny May 20, 2025
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
84 changes: 84 additions & 0 deletions .github/workflows/code-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Run code validation checks
on:
pull_request:
jobs:
changed-files:
runs-on: ubuntu-latest
name: Gather Changelist
strategy:
matrix:
fetch-depth:
- 2
base-branch:
- "master"
outputs:
all: ${{ steps.changes.outputs.all }}
php: ${{ steps.changes.outputs.php }}
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: ${{ matrix.fetch-depth }}
- name: Get changed files
id: changes
run: |
BASE_SHA="${{ github.event.before }}"
if [ "$BASE_SHA" = "0000000000000000000000000000000000000000" ]; then
BASE_SHA="${{ matrix.base-branch }}"
fi
if [[ ! -z "${{ github.event.pull_request.base.sha }}" ]]; then
BASE_SHA="${{ github.event.pull_request.base.sha }}"
fi
echo "all=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA ${{ github.sha }} | xargs)" >> $GITHUB_OUTPUT
echo "php=$(git diff --name-only --diff-filter=ACMRT $BASE_SHA ${{ github.sha }} | grep -E '.ph(p|tml)$' | xargs)" >> $GITHUB_OUTPUT
validate-php:
runs-on: ubuntu-latest
name: Run php code validation and Unit tests
needs: changed-files
if: ${{needs.changed-files.outputs.php}}
strategy:
matrix:
node-version:
- 20
php-version: ["8.1", "8.2", "8.3"]
dependencies:
- "highest"
composer-options:
- "--no-plugins --no-progress"
steps:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node_version }}
- name: Check out code
uses: actions/checkout@v4
- name: Setup Php
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
ini-file: development
tools: composer:2.2, cs2pr
env:
COMPOSER_AUTH_JSON: |
{
"http-basic": {
"repo.magento.com": {
"username": "${{ secrets.REPO_MAGENTO_USER }}",
"password": "${{ secrets.REPO_MAGENTO_PASSWORD }}"
}
}
}
- name: Validate Composer Files
run: composer validate
- name: Run Composer install
uses: "ramsey/composer-install@v1"
with:
dependency-versions: "${{ matrix.dependencies }}"
composer-options: "${{ matrix.composer-options }}"
- name: Detect PhpCs violations
run: |
vendor/bin/phpcs --config-set installed_paths ../../magento/magento-coding-standard/,../../phpcompatibility/php-compatibility,../../magento/php-compatibility-fork
vendor/bin/phpcs --standard=Magento2 -q --report=checkstyle ${{needs.changed-files.outputs.php}} | cs2pr --graceful-warnings
- name: Run Unit test
run: |
vendor/bin/phpunit Test/Unit/
99 changes: 99 additions & 0 deletions Block/Adminhtml/System/Config/TestConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

declare(strict_types=1);

namespace Nexi\Checkout\Block\Adminhtml\System\Config;

use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Config\Model\Config\Structure;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Framework\View\Helper\SecureHtmlRenderer;

class TestConnection extends Field
{
/**
* @param Context $context
* @param Structure $configStructure
* @param array $data
* @param SecureHtmlRenderer|null $secureRenderer
*/
public function __construct(
Context $context,
private readonly Structure $configStructure,
array $data = [],
?SecureHtmlRenderer $secureRenderer = null
) {
parent::__construct($context, $data, $secureRenderer);
}

/**
* Unset some non-related element parameters
*
* @param AbstractElement $element
*
* @return string
* @since 100.1.0
*/
public function render(AbstractElement $element)
{
$element = clone $element;
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();

return parent::render($element);
}

/**
* Set template to itself
*
* @return $this
* @since 100.1.0
*/
protected function _prepareLayout()
{
parent::_prepareLayout();
$this->setTemplate('Nexi_Checkout::system/config/testconnection.phtml');

return $this;
}

/**
* Get HTML for the element
*
* @param AbstractElement $element
*
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
$originalData = $element->getOriginalData();
$this->addData(
[
'button_label' => __($originalData['button_label']),
'html_id' => $element->getHtmlId(),
'ajax_url' => $this->_urlBuilder->getUrl('nexi/system_config/testconnection'),
'field_mapping' => str_replace('"', '\\"', json_encode($this->getFieldMapping()))
]
);

return $this->_toHtml();
}

/**
* Get configuration field mapping
*
* @return string[]
*/
private function getFieldMapping(): array
{
$apiKeyPath = $this->configStructure->getElementByConfigPath('payment/nexi/secret_key');
$testApiKeyPath = $this->configStructure->getElementByConfigPath('payment/nexi/test_secret_key');
$environmentPath = $this->configStructure->getElementByConfigPath('payment/nexi/environment');

return [
'environment' => str_replace('/', '_', $environmentPath->getPath()),
'secret_key' => str_replace('/', '_', $apiKeyPath->getPath()),
'test_secret_key' => str_replace('/', '_', $testApiKeyPath->getPath())
];
}
}
117 changes: 117 additions & 0 deletions Controller/Adminhtml/System/Config/TestConnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

declare(strict_types=1);

namespace Nexi\Checkout\Controller\Adminhtml\System\Config;

use JsonException;
use Magento\Backend\App\Action;
use Magento\Backend\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Controller\Result\Json;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Filter\StripTags;
use Magento\Framework\Url;
use Magento\Store\Model\ScopeInterface;
use Nexi\Checkout\Gateway\Config\Config;
use Nexi\Checkout\Model\Config\Source\Environment;
use NexiCheckout\Api\Exception\PaymentApiException;
use NexiCheckout\Factory\PaymentApiFactory;
use NexiCheckout\Model\Request\Item;
use NexiCheckout\Model\Request\Payment;
use NexiCheckout\Model\Request\Shared\Order;

class TestConnection extends Action implements HttpPostActionInterface
{
/**
* Authorization level of a basic admin session.
*
* @see _isAllowed()
*/
public const ADMIN_RESOURCE = 'Magento_Catalog::config_catalog';

/**
* @param Context $context
* @param JsonFactory $resultJsonFactory
* @param StripTags $tagFilter
* @param PaymentApiFactory $paymentApiFactory
* @param Config $config
* @param Url $url
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
Context $context,
private readonly JsonFactory $resultJsonFactory,
private readonly StripTags $tagFilter,
private readonly PaymentApiFactory $paymentApiFactory,
private readonly Config $config,
private readonly Url $url,
private readonly ScopeConfigInterface $scopeConfig
) {
parent::__construct($context);
}

/**
* Check for connection to server
*
* @return Json
* @throws JsonException
*/
public function execute()
{
$result = [
'success' => true,
'errorMessage' => '',
];
$options = $this->getRequest()->getParams();
$isLiveMode = $options['environment'] == Environment::LIVE;

$apiKey = $isLiveMode ? $options['secret_key'] : $options['test_secret_key'];

if ($apiKey == '******') {
$apiKey = $isLiveMode ? $this->config->getApiKey() : $this->config->getTestApiKey();
}

try {
$api = $this->paymentApiFactory->create(
secretKey : $apiKey,
isLiveMode: $isLiveMode
);
$currency = $this->scopeConfig->getValue(
'currency/options/default',
ScopeInterface::SCOPE_STORE
);

$payment = $api->createEmbeddedPayment(
new Payment(
new Order(
[
new Item('test', 1, 'pcs', 1, 1, 1, 'test')
],
$currency,
1
),
new Payment\EmbeddedCheckout(
$this->url->getUrl('checkout/onepage/success'),
'terms_url'
)
)
);

if ($payment->getPaymentId()) {
$api->terminate($payment->getPaymentId());
}

} catch (PaymentApiException $e) {
$message = $e->getMessage();
$result['success'] = false;
$result['errorMessage'] = $this->tagFilter->filter($message) . ' '
. __('Please check your API key and environment.');
}

$resultJson = $this->resultJsonFactory->create();

return $resultJson->setData($result);
}
}
42 changes: 42 additions & 0 deletions Controller/Hpp/CancelAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace Nexi\Checkout\Controller\Hpp;

use Magento\Checkout\Model\Session;
use Magento\Framework\App\ActionInterface;
use Magento\Framework\Controller\Result\RedirectFactory;
use Magento\Framework\Controller\ResultInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\UrlInterface;

class CancelAction implements ActionInterface
{
/**
* @param RedirectFactory $resultRedirectFactory
* @param UrlInterface $url
* @param Session $checkoutSession
* @param ManagerInterface $messageManager
*/
public function __construct(
private readonly RedirectFactory $resultRedirectFactory,
private readonly UrlInterface $url,
private readonly Session $checkoutSession,
private readonly ManagerInterface $messageManager
) {
}

/**
* Execute action based on request and return result
*
* @return ResultInterface
*/
public function execute(): ResultInterface
{
$this->checkoutSession->restoreQuote();
$this->messageManager->addNoticeMessage(__('The payment has been canceled.'));

return $this->resultRedirectFactory->create()->setUrl(
$this->url->getUrl('checkout/cart/index', ['_secure' => true])
);
}
}
Loading
Loading