Skip to content

Commit

Permalink
PR review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Zales0123 committed Oct 27, 2016
1 parent 2595f61 commit 907b8a4
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Feature: Refunding order payment
And the customer bought a single "Green Arrow"
And the customer chose "Free" shipping method to "United States" with "Offline" payment
And this order is already paid
And this order has already been shipped
And I am logged in as an administrator
And I am viewing the summary of this order

Expand Down
10 changes: 8 additions & 2 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingOrdersContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,15 +482,21 @@ public function itemTotalShouldBe($itemName, $total)
*/
public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyCompleted()
{
$this->notificationChecker->checkNotification('Payment has been successfully updated.', NotificationType::success());
$this
->notificationChecker
->checkNotification('Payment has been successfully updated.', NotificationType::success())
;
}

/**
* @Then I should be notified that the order's payment has been successfully refunded
*/
public function iShouldBeNotifiedThatTheOrderSPaymentHasBeenSuccessfullyRefunded()
{
$this->notificationChecker->checkNotification('Payment has been successfully refunded.', NotificationType::success());
$this
->notificationChecker
->checkNotification('Payment has been successfully refunded.', NotificationType::success())
;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Component/Core/OrderPaymentStates.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
final class OrderPaymentStates
{
const STATE_CART = 'cart';
const STATE_AWAITING_PAYMENT = 'awaiting_payment';
const STATE_PARTIALLY_PAID = 'partially_paid';
const STATE_CANCELLED = 'cancelled';
const STATE_CART = 'cart';
const STATE_PAID = 'paid';
const STATE_PARTIALLY_PAID = 'partially_paid';
const STATE_REFUNDED = 'refunded';

private function __construct()
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Component/Core/OrderPaymentTransitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ final class OrderPaymentTransitions
{
const GRAPH = 'sylius_order_payment';

const TRANSITION_CANCEL = 'cancel';
const TRANSITION_REQUEST_PAYMENT = 'request_payment';
const TRANSITION_PARTIALLY_PAY = 'partially_pay';
const TRANSITION_CANCEL = 'cancel';
const TRANSITION_PAY = 'pay';
const TRANSITION_REFUND = 'refund';
const TRANSITION_REQUEST_PAYMENT = 'request_payment';

private function __construct()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,14 @@ private function applyTransition(StateMachineInterface $stateMachine, $transitio
*/
private function getTargetTransition(OrderInterface $order)
{
$paymentsCount = $order->getPayments()->count();
$refundedPaymentsCount = $this->getPaymentsWithState($order, PaymentInterface::STATE_REFUNDED)->count();
$refundedPaymentTotal = 0;
$refundedPayments = $this->getPaymentsWithState($order, PaymentInterface::STATE_REFUNDED);

if ($refundedPaymentsCount === $paymentsCount) {
foreach ($refundedPayments as $payment) {
$refundedPaymentTotal += $payment->getAmount();
}

if (0 < $refundedPayments->count() && $refundedPaymentTotal >= $order->getTotal()) {
return OrderPaymentTransitions::TRANSITION_REFUND;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ function it_marks_an_order_as_refunded_if_all_its_payments_are_refunded(
PaymentInterface $firstPayment,
PaymentInterface $secondPayment
) {
$firstPayment->getAmount()->willReturn(6000);
$firstPayment->getState()->willReturn(PaymentInterface::STATE_REFUNDED);
$secondPayment->getAmount()->willReturn(4000);
$secondPayment->getState()->willReturn(PaymentInterface::STATE_REFUNDED);

$order
->getPayments()
->willReturn(new ArrayCollection([$firstPayment->getWrappedObject(), $secondPayment->getWrappedObject()]))
;
$order->getTotal()->willReturn(10000);

$stateMachineFactory->get($order, OrderPaymentTransitions::GRAPH)->willReturn($stateMachine);
$stateMachine->can(OrderPaymentTransitions::TRANSITION_REFUND)->willReturn(true);
Expand Down Expand Up @@ -98,9 +101,10 @@ function it_marks_an_order_as_completed_if_fully_paid_multiple_payments(
$secondPayment->getAmount()->willReturn(4000);
$secondPayment->getState()->willReturn(PaymentInterface::STATE_COMPLETED);

$payments = new ArrayCollection([$firstPayment->getWrappedObject(), $secondPayment->getWrappedObject()]);

$order->getPayments()->willReturn($payments);
$order
->getPayments()
->willReturn(new ArrayCollection([$firstPayment->getWrappedObject(), $secondPayment->getWrappedObject()]))
;
$order->getTotal()->willReturn(10000);

$stateMachineFactory->get($order, OrderPaymentTransitions::GRAPH)->willReturn($stateMachine);
Expand All @@ -122,9 +126,10 @@ function it_marks_an_order_as_partially_paid_if_one_of_the_payment_is_processing
$secondPayment->getAmount()->willReturn(4000);
$secondPayment->getState()->willReturn(PaymentInterface::STATE_COMPLETED);

$payments = new ArrayCollection([$firstPayment->getWrappedObject(), $secondPayment->getWrappedObject()]);

$order->getPayments()->willReturn($payments);
$order
->getPayments()
->willReturn(new ArrayCollection([$firstPayment->getWrappedObject(), $secondPayment->getWrappedObject()]))
;
$order->getTotal()->willReturn(10000);

$stateMachineFactory->get($order, OrderPaymentTransitions::GRAPH)->willReturn($stateMachine);
Expand Down
5 changes: 2 additions & 3 deletions src/Sylius/Component/Order/Model/OrderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@ interface OrderInterface extends
ResourceInterface,
TimestampableInterface
{
const STATE_CANCELLED = 'cancelled';
const STATE_CART = 'cart';
const STATE_FULFILLED = 'fulfilled';
const STATE_NEW = 'new';
const STATE_REFUNDED = 'refunded';
const STATE_CANCELLED = 'cancelled';
const STATE_FULFILLED = 'fulfilled';

/**
* @return \DateTime
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Component/Order/OrderTransitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class OrderTransitions
{
const GRAPH = 'sylius_order';

const TRANSITION_CANCEL = 'cancel';
const TRANSITION_CREATE = 'create';
const TRANSITION_CANCEL = 'cancel';
const TRANSITION_FULFILL = 'fulfill';

private function __construct()
Expand Down

0 comments on commit 907b8a4

Please sign in to comment.