Skip to content

Commit

Permalink
Fix original payment method on refund page
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Jun 18, 2021
1 parent ec8e508 commit d667bb4
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@refunds
Feature: Seeing a original payment method from succeed payment on refund page
In order to choose proper payment method while refunding
As an Administrator
I want to see original payment method of succeed payment

Background:
Given the store operates on a single green channel in "United States"
And the store has a product "Mr. Meeseeks T-Shirt" priced at "$10.00"
And the store has a product "Angel T-Shirt" priced at "$5.00"
And the store allows shipping with "Galaxy Post"
And the store allows paying with "Space money"
And the store also allows paying with "Mars money"
And there is a customer "[email protected]" that placed an order "#00000023"
And the customer bought 2 "Mr. Meeseeks T-Shirt" products
And the customer chose "Galaxy Post" shipping method to "United States" with "Space money" payment
And the payment of order "#00000023" failed
And the customer chose "Mars money" payment method
And and this payment has been paid
And I am logged in as an administrator

@ui
Scenario: Seeing original payment method of succeed payment
When I want to refund some units of order "#00000023"
Then I should see original payment method "Mars money"
4 changes: 2 additions & 2 deletions src/Resources/views/_paymentMethod.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if order.payments.first() %}
{% set original_payment_method = order.payments.first().method %}
{% set original_payment_method = order.lastPayment(constant('Sylius\\Component\\Core\\Model\\PaymentInterface::STATE_COMPLETED')).method %}

<div class="ui hidden divider"></div>

Expand All @@ -15,7 +15,7 @@
</option>
{% endfor %}
</select>
<small>{{ 'sylius.ui.original_payment_method'|trans }}: <strong>{{ original_payment_method }}</strong></small>
<small id="original-payment-method">{{ 'sylius.ui.original_payment_method'|trans }}: <strong>{{ original_payment_method }}</strong></small>
</div>
</div>
<div class="ui form column">
Expand Down
71 changes: 71 additions & 0 deletions tests/Behat/Context/Setup/PaymentContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Tests\Sylius\RefundPlugin\Behat\Context\Setup;

use Behat\Behat\Context\Context;
use Payum\Core\Model\PaymentInterface;
use SM\Factory\FactoryInterface as StateMachineFactoryInterface;
use Sylius\Behat\Service\SharedStorage;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\PaymentMethodInterface;
use Sylius\Component\Payment\PaymentTransitions;

final class PaymentContext implements Context
{
/** @var StateMachineFactoryInterface */
private $stateMachineFactory;

/** @var SharedStorage */
private $sharedStorage;

public function __construct(StateMachineFactoryInterface $stateMachineFactory, SharedStorage $sharedStorage)
{
$this->stateMachineFactory = $stateMachineFactory;
$this->sharedStorage = $sharedStorage;
}

/**
* @Given the payment of order :order failed
*/
public function paymentOfOrderFailed(OrderInterface $order): void
{
$payment = $order->getLastPayment();
$this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH)->apply(PaymentTransitions::TRANSITION_FAIL);
}

/**
* @Given /^the customer chose ("[^"]+" payment) method$/
*/
public function theCustomerChosePaymentMethod(PaymentMethodInterface $paymentMethod): void
{
/** @var OrderInterface $order */
$order = $this->sharedStorage->get('order');

$lastPayment = $order->getLastPayment();
$lastPayment->setMethod($paymentMethod);

$this->sharedStorage->set('last_payment', $lastPayment);
}

/**
* @Given and this payment has been paid
*/
public function andThisPaymentHasBeenPaid(): void
{
/** @var PaymentInterface $lastPayment */
$lastPayment = $this->sharedStorage->get('last_payment');

$this->stateMachineFactory->get($lastPayment, PaymentTransitions::GRAPH)->apply(PaymentTransitions::TRANSITION_COMPLETE);
}
}
8 changes: 8 additions & 0 deletions tests/Behat/Context/Ui/RefundingContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ public function emailToWithCreditMemoShouldNotBeSent(string $email): void
}
}

/**
* @Then I should see original payment method :paymentMethod
*/
public function iShouldSeeOriginalPaymentMethod(string $paymentMethod): void
{
Assert::same($this->orderRefundsPage->getOriginalPaymentMethod(), sprintf('Original Payment Method: %s', $paymentMethod));
}

private function provideLongComment(): string
{
return 'Tu ne quaesieris scire nefas, quem mihi quem tibi finem di dederint, Leuconoe, nec Babylonios temptaris numeros. Ut melius quidquid erit pati. Seu plures hiemes sue tribuit Iuppiter ultimam. Qae nunc oppositis debilitat pumicibus mare Tyrrenum: sapias vina liques et spatio brevi. Spem longam resecens. Dum loquimur fugerit invida Aetas: CARPE DIEM, quam minimum credula postero.';
Expand Down
6 changes: 6 additions & 0 deletions tests/Behat/Page/Admin/OrderRefundsPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,17 @@ public function isPaymentMethodSelected(string $paymentMethodName): bool
return true;
}

public function getOriginalPaymentMethod(): string
{
return $this->getTextFromElement($this->getElement('original_payment_method'));
}

protected function getDefinedElements(): array
{
return [
'payment_methods' => '#payment-methods',
'refunded_total' => '#refunded-total',
'original_payment_method' => '#original-payment-method'
];
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/OrderRefundsPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ public function hasBackButton(): bool;
public function canChoosePaymentMethod(): bool;

public function isPaymentMethodVisible(string $paymentMethodName): bool;

public function getOriginalPaymentMethod(): string;
}
5 changes: 5 additions & 0 deletions tests/Behat/Resources/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@
<argument type="service" id="doctrine.orm.entity_manager" />
</service>

<service id="Tests\Sylius\RefundPlugin\Behat\Context\Setup\PaymentContext">
<argument type="service" id="SM\Factory\Factory" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>

<service id="Tests\Sylius\RefundPlugin\Behat\Context\Transform\OrderContext">
<argument type="service" id="sylius.repository.order" />
</service>
Expand Down
1 change: 1 addition & 0 deletions tests/Behat/Resources/suites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ default:
- sylius.behat.context.ui.admin.managing_orders

- Tests\Sylius\RefundPlugin\Behat\Context\Application\EmailsContext
- Tests\Sylius\RefundPlugin\Behat\Context\Setup\PaymentContext
- Tests\Sylius\RefundPlugin\Behat\Context\Ui\CreditMemoContext
- Tests\Sylius\RefundPlugin\Behat\Context\Ui\ManagingOrdersContext
- Tests\Sylius\RefundPlugin\Behat\Context\Ui\RefundingContext
Expand Down

0 comments on commit d667bb4

Please sign in to comment.