Skip to content

Commit

Permalink
Use the real behaviour of canceling a payment
Browse files Browse the repository at this point in the history
  • Loading branch information
Prometee committed Jun 11, 2024
1 parent b6de74c commit a862c77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
6 changes: 3 additions & 3 deletions features/admin/cancel_order.feature
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature: Canceling an order
And I am logged in as an administrator

@ui
Scenario: Initializing the Stripe refund
Scenario: Cancelling the order when a checkout session is still available
Given I am viewing the summary of this order
And I am prepared to expire the checkout session on this order
When I cancel this order
Expand All @@ -25,8 +25,8 @@ Feature: Canceling an order
And it should have payment state cancelled

@ui
Scenario: Cancelling the order after the customer go back during the payment
Given this order has a Stripe payment cancelled
Scenario: Cancelling the order after the customer canceled the payment
Given this order payment has been canceled
And I am viewing the summary of this order
And I am prepared to cancel this order
When I cancel this order
Expand Down
17 changes: 5 additions & 12 deletions tests/Behat/Context/Ui/Admin/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,24 +104,17 @@ public function thisOrderIsNotYetPaid(OrderInterface $order, string $stripeCheck
}

/**
* @Given /^(this order) has a Stripe payment cancelled$/
* @Given /^(this order) payment has been canceled$/
*/
public function thisOrderHasStripePaymentCancelled(OrderInterface $order): void
public function thisOrderPaymentHasBeenCancelled(OrderInterface $order): void
{
/** @var PaymentInterface $payment */
$payment = $order->getPayments()->first();
$payment->setState(PaymentInterface::STATE_CANCELLED);

Assert::notNull($payment->getAmount());
Assert::notNull($payment->getCurrencyCode());

$paymentReplaced = new Payment();
$paymentReplaced->setMethod($payment->getMethod());
$paymentReplaced->setAmount($payment->getAmount());
$paymentReplaced->setCurrencyCode($payment->getCurrencyCode());
$order->addPayment($paymentReplaced);
/** @var StateMachineInterface $stateMachine */
$stateMachine = $this->stateMachineFactory->get($payment, PaymentTransitions::GRAPH);
$stateMachine->apply(PaymentTransitions::TRANSITION_CANCEL);

$this->objectManager->persist($order);
$this->objectManager->flush();
}

Expand Down

0 comments on commit a862c77

Please sign in to comment.