Skip to content

Commit

Permalink
Implement Saferpay's transaction log show page
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed May 30, 2023
1 parent 1852ef9 commit cee8e17
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 8 deletions.
12 changes: 10 additions & 2 deletions config/admin_routing.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
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'

commerce_weavers_sylius_saferpay_order_payment_refund:
path: /orders/{orderId}/payments/{id}/refund-saferpay
Expand Down
12 changes: 11 additions & 1 deletion config/packages/sylius_grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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 +47,13 @@
'label' => 'commerce_weavers_saferpay.ui.occurred_at',
],
],
'actions' => [
'item' => [
'show' => [
'type' => 'show',
],
],
],
],
],
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,15 @@ 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: Seeing the transaction logs element in the menu
When I am on the administration dashboard
Then I should see "Saferpay Transaction Logs" in the menu

@ui
Scenario: Checking details of a given transaction log
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
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 %}
28 changes: 27 additions & 1 deletion tests/Behat/Context/Ui/Admin/ManagingTransactionLogsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

Expand All @@ -30,6 +30,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 +56,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() !== '');
}
}
2 changes: 0 additions & 2 deletions tests/Behat/Context/Ui/Shop/PaymentContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function iFinalizeSuccessfullyThePaymentOnTheSaferpaysPage(): void

/**
* @Given I have failed to complete the payment on the Saferpay's page
*
* @When I fail to complete the payment on the Saferpay's page
*/
public function iFailToCompleteThePaymentOnTheSaferpaysPage(): void
Expand All @@ -41,7 +40,6 @@ public function iFailToCompleteThePaymentOnTheSaferpaysPage(): void

/**
* @Given I have cancelled the payment on the Saferpay's page
*
* @When I cancel the payment on the Saferpay's page
*/
public function iCancelThePaymentOnTheSaferpaysPage(): void
Expand Down
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>
7 changes: 7 additions & 0 deletions translations/messages.en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +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'

0 comments on commit cee8e17

Please sign in to comment.