Skip to content

Commit

Permalink
Merge pull request #2628 from dpfaffenbauer/issue/2615
Browse files Browse the repository at this point in the history
[Payment] when payment is authorized or paid, order get's confirmed
  • Loading branch information
dpfaffenbauer authored Sep 9, 2024
2 parents 5a69781 + 9211a2b commit ef464e0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 119 deletions.
6 changes: 6 additions & 0 deletions features/domain/order/order_payment.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,34 @@ Feature: Create a new order and add a payment
Given I create a payment for my order with payment provider "Bankwire" and amount 1800
And I apply payment transition "fail" to latest order payment
Then the order payment state should be "awaiting_payment"
And the order state should be "new"

Scenario: Create cancelled payment
Given I create a payment for my order with payment provider "Bankwire" and amount 1800
And I apply payment transition "cancel" to latest order payment
Then the order payment state should be "awaiting_payment"
And the order state should be "new"

Scenario: Create fully paid payment
Given I create a payment for my order with payment provider "Bankwire" and amount 2400
And I apply payment transition "complete" to latest order payment
Then the order payment state should be "paid"
And the order state should be "confirmed"

Scenario: Create partially paid payment
Given I create a payment for my order with payment provider "Bankwire" and amount 1800
And I apply payment transition "complete" to latest order payment
Then the order payment state should be "partially_paid"
And the order state should be "confirmed"

Scenario: Create fully authorized payment
Given I create a payment for my order with payment provider "Bankwire" and amount 2400
And I apply payment transition "authorize" to latest order payment
Then the order payment state should be "authorized"
And the order state should be "confirmed"

Scenario: Create partially authorized payment
Given I create a payment for my order with payment provider "Bankwire" and amount 1800
And I apply payment transition "authorize" to latest order payment
Then the order payment state should be "partially_authorized"
And the order state should be "confirmed"
4 changes: 1 addition & 3 deletions features/domain/order/order_workflow.feature
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,15 @@ Feature: Create a new order and add a invoice
Scenario: Create order with payment and shipment which still is new
Given I create an order from my cart
And I create a payment for my order with payment provider "Bankwire" and amount 2400
And I apply payment transition "complete" to latest order payment
And I create a shipment for my order
And I apply order shipment transition "request_shipment" to my order
And I apply shipment transition "ship" to latest order shipment
Then the order shipping state should be "shipped"
And the order payment state should be "paid"
And the order payment state should be "awaiting_payment"
And the order state should be "new"

Scenario: Create order with payment and shipment which still is completed
Given I create an order from my cart
And I apply transition "confirm" to my order
And I create a payment for my order with payment provider "Bankwire" and amount 2400
And I apply payment transition "complete" to latest order payment
And I create a shipment for my order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ core_shop_workflow:
callbacks:
after:
resolve_state:
on: ['pay']
on: ['partially_authorize', 'authorize', 'partially_pay', 'pay']
do: ['@CoreShop\Bundle\OrderBundle\StateResolver\OrderStateResolver', 'resolve']
args: ['object']
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,26 @@ public function __construct(
public function resolve(OrderInterface $order): void
{
$stateMachine = $this->stateMachineManager->get($order, 'coreshop_order');

if ($this->canOrderBeConfirmed($order) && $stateMachine->can($order, OrderTransitions::TRANSITION_CONFIRM)) {
$stateMachine->apply($order, OrderTransitions::TRANSITION_CONFIRM);
}

if ($this->canOrderBeComplete($order) && $stateMachine->can($order, OrderTransitions::TRANSITION_COMPLETE)) {
$stateMachine->apply($order, OrderTransitions::TRANSITION_COMPLETE);
}
}

private function canOrderBeConfirmed(OrderInterface $order): bool
{
return in_array($order->getPaymentState(), [
OrderPaymentStates::STATE_PAID,
OrderPaymentStates::STATE_PARTIALLY_PAID,
OrderPaymentStates::STATE_AUTHORIZED,
OrderPaymentStates::STATE_PARTIALLY_AUTHORIZED,
], true);
}

private function canOrderBeComplete(OrderInterface $order): bool
{
$coreStates = OrderPaymentStates::STATE_PAID === $order->getPaymentState() &&
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,3 @@ services:
tags:
- { name: payum.extension, all: true, prepend: true }

CoreShop\Bundle\PayumBundle\Extension\UpdateOrderStateExtension:
arguments:
- '@CoreShop\Bundle\WorkflowBundle\Manager\StateMachineManagerInterface'
tags:
- { name: payum.extension, all: true, prepend: true }

0 comments on commit ef464e0

Please sign in to comment.