Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Payment] when payment is authorized or paid, order get's confirmed #2628

Open
wants to merge 2 commits into
base: 4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 }