Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saferpay's Transaction Logs in Admin Panel #46

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 10 additions & 2 deletions config/admin_routing.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
commerce_weavers_sylius_saferpay_admin_transaction_log_index:
commerce_weavers_saferpay_transaction_log:
resource: |
alias: commerce_weavers_saferpay.transaction_log
section: admin
templates: "@SyliusAdmin\\Crud"
only: ['index']
only: ['index', 'show']
redirect: update
grid: commerce_weavers_saferpay_transaction_log
vars:
index:
icon: 'th list'
type: sylius.resource
prefix: saferpay

commerce_weavers_saferpay_admin_transaction_log_show:
path: /saferpay/transaction-logs/{id}
methods: [ GET ]
defaults:
_controller: commerce_weavers_saferpay.controller.transaction_log::showAction
_sylius:
template: '@CommerceWeaversSyliusSaferpayPlugin/Admin/TransactionLogs/show.html.twig'
15 changes: 14 additions & 1 deletion config/packages/sylius_grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
'class' => '%commerce_weavers_saferpay.model.transaction_log.class%',
],
],
'sorting' => [
'occurredAt' => 'desc',
],
'fields' => [
'occurredAt' => [
'type' => 'datetime',
Expand All @@ -34,8 +37,11 @@
'label' => 'sylius.ui.description',
],
'type' => [
'type' => 'string',
'type' => 'twig',
'label' => 'sylius.ui.type',
'options' => [
'template' => '@CommerceWeaversSyliusSaferpayPlugin/Admin/TransactionLogs/Grid/Field/_type.html.twig',
],
]
],
'filters' => [
Expand All @@ -44,6 +50,13 @@
'label' => 'commerce_weavers_saferpay.ui.occurred_at',
],
],
'actions' => [
'item' => [
'show' => [
'type' => 'show',
],
],
],
],
],
]);
Expand Down
18 changes: 18 additions & 0 deletions config/services/menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

use CommerceWeavers\SyliusSaferpayPlugin\TransactionLog\Menu\AdminMenuListener;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator) {
$services = $containerConfigurator->services();

$services
->set(AdminMenuListener::class)
->tag('kernel.event_listener', [
'event' => 'sylius.menu.admin.main',
'method' => 'addAdminMenuItems',
])
;
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,12 @@ Feature: Logging communication with Saferpay
When I check the Saferpay's transaction logs
Then I should see 1 transaction log in the list
And I should see the error transaction log for order "#00000022", described as "Payment assertion"

@ui
Scenario: Checking details of a given transaction log
Given the payment method's debug mode is enabled
And the order has been paid successfully with Saferpay payment method
When I check the Saferpay's transaction logs
And I open details of the "Payment authorization succeeded" log for order "#00000022"
Then I should see details of the log with "Payment authorization succeeded" description and "Informational" type
And I should see the context information about communication with Saferpay
27 changes: 27 additions & 0 deletions src/TransactionLog/Menu/AdminMenuListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace CommerceWeavers\SyliusSaferpayPlugin\TransactionLog\Menu;

use Sylius\Bundle\UiBundle\Menu\Event\MenuBuilderEvent;

final class AdminMenuListener
{
public function addAdminMenuItems(MenuBuilderEvent $event): void
{
$menu = $event->getMenu();

$newSubmenu = $menu
->addChild('commerce_weavers_sylius_saferpay_plugin')
->setLabel('commerce_weavers_saferpay.ui.plugin_name')
;

$newSubmenu
->addChild('commerce_weavers_sylius_saferpay_plugin_transaction_log', [
'route' => 'commerce_weavers_saferpay_admin_transaction_log_index',
])
->setLabel('commerce_weavers_saferpay.ui.transaction_logs')
;
}
}
1 change: 1 addition & 0 deletions templates/Admin/TransactionLogs/Grid/Field/_type.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{ ('commerce_weavers_saferpay.ui.type_' ~ _context.data)|trans }}
50 changes: 50 additions & 0 deletions templates/Admin/TransactionLogs/show.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends '@SyliusAdmin/layout.html.twig' %}

{% block title %}{{ 'commerce_weavers_saferpay.ui.transaction_logs'|trans }} {{ parent() }}{% endblock %}

{% block content %}
<div id="header" class="ui stackable two column grid">
<div class="column">
<h1 class="ui header">
<i class="circular cube icon"></i>
<div class="content">
<span>{{ 'commerce_weavers_saferpay.ui.transaction_log'|trans }}</span>
<div class="sub header">{{ transaction_log.id }}</div>
</div>
</h1>
{% import '@SyliusAdmin/Macro/breadcrumb.html.twig' as breadcrumb %}

{% set breadcrumbs = [
{ label: 'sylius.ui.administration'|trans, url: path('sylius_admin_dashboard') },
{ label: 'commerce_weavers_saferpay.ui.transaction_logs'|trans, url: path('commerce_weavers_saferpay_admin_transaction_log_index') },
{ label: resource.name|default(resource.id) }
] %}

{{ breadcrumb.crumble(breadcrumbs) }}
</div>
</div>

<div class="ui stackable grid">
<div class="eight wide column">
<div class="ui segment">
<h4 class="ui dividing header">{{ 'commerce_weavers_saferpay.ui.type'|trans }}</h4>
<p {{ sylius_test_html_attribute('log-type') }}>{{ ('commerce_weavers_saferpay.ui.type_' ~ transaction_log.type)|trans }}</p>

<h4 class="ui dividing header">{{ 'commerce_weavers_saferpay.ui.occurred_at'|trans }}</h4>
<p>{{ transaction_log.occurredAt|date('Y-m-d H:i:s') }}</p>

<h4 class="ui dividing header">{{ 'commerce_weavers_saferpay.ui.description'|trans }}</h4>
<p {{ sylius_test_html_attribute('description') }}>{{ transaction_log.description }}</p>

<h4 class="ui dividing header">{{ 'commerce_weavers_saferpay.ui.payment_id'|trans }}</h4>
<p>{{ transaction_log.payment.id }} ({{ 'sylius.ui.order'|trans }}: #{{ transaction_log.payment.order.number }})</p>
</div>
</div>
<div class="eight wide column">
<div class="ui segment">
<h4 class="ui dividing header">{{ 'commerce_weavers_saferpay.ui.context'|trans }}</h4>
<pre {{ sylius_test_html_attribute('context') }}>{{ transaction_log.context|json_encode(constant('JSON_PRETTY_PRINT'))|trim|raw }}</pre>
</div>
</div>
</div>
{% endblock %}
1 change: 1 addition & 0 deletions tests/Behat/Context/Setup/SaferpayPaymentEventContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public function thePaymentFailedOnTheFirstTryAfterTheAuthorizeStep(OrderInterfac

/**
* @Given /^(the order) has been paid successfully with Saferpay payment method on the second try$/
* @Given /^(the order) has been paid successfully with Saferpay payment method$/
*/
public function theSystemHasBeenNotifiedAboutPaymentOnThisOrder(OrderInterface $order): void
{
Expand Down
31 changes: 29 additions & 2 deletions tests/Behat/Context/Ui/Admin/ManagingTransactionLogsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
namespace Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Context\Ui\Admin;

use Behat\Behat\Context\Context;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog\IndexPageInterface;
use Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog\ShowPageInterface;
use Webmozart\Assert\Assert;

final class ManagingTransactionLogsContext implements Context
{
public function __construct(private IndexPageInterface $indexPage)
public function __construct(private IndexPageInterface $indexPage, private ShowPageInterface $showPage)
{
}

Expand All @@ -30,6 +31,15 @@ public function iShouldSeeTransactionLogsInTheList(int $count): void
Assert::same($this->indexPage->countItems(), $count);
}

/**
* @When I open details of the :logDescription log for order :orderNumber
*/
public function iOpenDetailsOfTheLogForOrder(string $logDescription, string $orderNumber): void
{
$this->indexPage->open();
$this->indexPage->openLogDetailsByOrderNumberAndDescription($orderNumber, $logDescription);
}

/**
* @Then I should see the :logType transaction log for order :orderNumber, described as :logDescription
*/
Expand All @@ -47,4 +57,21 @@ public function iShouldSeeTransactionLogWithTypeAndDescriptionForOrderNumber(str
'orderNumber' => $orderNumber,
]);
}

/**
* @Then I should see details of the log with :logDescription description and :logType type
*/
public function iShouldSeeThePaymentAuthorizationSucceededLogDetails(string $logDescription, string $logType): void
{
Assert::same($this->showPage->getDescription(), $logDescription);
Assert::same($this->showPage->getLogType(), $logType);
}

/**
* @Then I should see the context information about communication with Saferpay
*/
public function iShouldSeeTheContextInformationAboutCommunicationWithSaferpay(): void
{
Assert::true($this->showPage->getContext() !== '');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lazy 😄 can we check it in more detail or there is no point we could determine them within the Behat scenario?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it could be better, but not checking the whole context can always be called lazy :D. If I check whether there are only request and response keys, there is still a change they're empty. So, the only "good" way is checking the whole context, which is really long, and it might make only a little bit more sense.

}
}
25 changes: 25 additions & 0 deletions tests/Behat/Page/Admin/TransactionLog/IndexPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog;

use Behat\Mink\Element\NodeElement;
use Sylius\Behat\Page\Admin\Crud\IndexPage as BaseIndexPage;

class IndexPage extends BaseIndexPage implements IndexPageInterface
{
public function openLogDetailsByOrderNumberAndDescription(string $orderNumber, string $description): void
{
$row = $this->getRow($orderNumber, $description);
$row->clickLink('Show');
}

private function getRow(string $orderNumber, string $description): NodeElement
{
$tableAccessor = $this->getTableAccessor();
$table = $this->getElement('table');

return $tableAccessor->getRowWithFields($table, ['orderNumber' => $orderNumber, 'description' => $description]);
}
}
12 changes: 12 additions & 0 deletions tests/Behat/Page/Admin/TransactionLog/IndexPageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog;

use Sylius\Behat\Page\Admin\Crud\IndexPageInterface as BaseIndexPageInterface;

interface IndexPageInterface extends BaseIndexPageInterface
{
public function openLogDetailsByOrderNumberAndDescription(string $orderNumber, string $description): void;
}
39 changes: 39 additions & 0 deletions tests/Behat/Page/Admin/TransactionLog/ShowPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog;

use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage;

class ShowPage extends SymfonyPage implements ShowPageInterface
{
public function getDescription(): string
{
return $this->getElement('description')->getText();
}

public function getLogType(): string
{
return $this->getElement('log-type')->getText();
}

public function getContext(): string
{
return $this->getElement('context')->getText();
}

public function getRouteName(): string
{
return 'commerce_weavers_saferpay_admin_transaction_log_show';
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'context' => '[data-test-context]',
'description' => '[data-test-description]',
'log-type' => '[data-test-log-type]',
]);
}
}
16 changes: 16 additions & 0 deletions tests/Behat/Page/Admin/TransactionLog/ShowPageInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog;

use FriendsOfBehat\PageObjectExtension\Page\SymfonyPageInterface;

interface ShowPageInterface extends SymfonyPageInterface
{
public function getDescription(): string;

public function getLogType(): string;

public function getContext(): string;
}
3 changes: 2 additions & 1 deletion tests/Behat/Resources/config/services/contexts/ui/admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
</service>

<service id="Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Context\Ui\Admin\ManagingTransactionLogsContext">
<argument type="service" id="commerce_weavers.behat.page.admin.transaction_log" />
<argument type="service" id="Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog\IndexPage" />
<argument type="service" id="Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog\ShowPage" />
</service>
</services>
</container>
4 changes: 3 additions & 1 deletion tests/Behat/Resources/config/services/pages/admin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
<argument type="string">sylius_admin_payment_method_create</argument>
</service>

<service id="commerce_weavers.behat.page.admin.transaction_log" parent="sylius.behat.page.admin.crud.index">
<service id="Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog\IndexPage" parent="sylius.behat.page.admin.crud.index">
<argument type="string">commerce_weavers_saferpay_admin_transaction_log_index</argument>
</service>

<service id="Tests\CommerceWeavers\SyliusSaferpayPlugin\Behat\Page\Admin\TransactionLog\ShowPage" parent="sylius.behat.symfony_page" />
</services>
</container>
8 changes: 8 additions & 0 deletions translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ commerce_weavers_saferpay:
ui:
allowed_payment_methods: 'Allowed payment methods'
customer_id: 'Customer Id'
context: 'Context'
debug: 'Debug'
description: 'Description'
occurred_at: 'Occurred At'
payment_id: 'Payment Id'
plugin_name: 'Commerce Weavers – Saferpay'
saferpay: 'Saferpay'
sandbox: 'Sandbox'
terminal_id: 'Terminal Id'
transaction_log: 'Saferpay Transaction Log'
transaction_logs: 'Saferpay Transaction Logs'
type: 'Type'
type_info: 'Informational'
type_error: 'Error'