Skip to content

Commit

Permalink
Only set order status to pending payment if order still needs payment…
Browse files Browse the repository at this point in the history
… and order status is not already pending.
  • Loading branch information
remcotolsma committed Sep 15, 2023
1 parent 20f4f6f commit 7892e23
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,15 @@ public static function status_update( Payment $payment ) {
}

/**
* Pending payment.
* For new WooCommerce orders, the order status is 'pending' by
* default. It is possible that a first payment attempt fails and the
* order status is set to 'failed'. If a new payment attempt is made,
* we will reset the order status to pending payment.
*
* @link https://github.com/woocommerce/woocommerce/blob/7897a61a1040ca6ed3310cb537ce22211058256c/plugins/woocommerce/includes/abstracts/abstract-wc-order.php#L402-L403
* @link https://github.com/pronamic/wp-pronamic-pay-woocommerce/issues/48
*/
if ( PaymentStatus::OPEN === $payment->get_status() ) {
if ( PaymentStatus::OPEN === $payment->get_status() && $order->needs_payment() && 'pending' !== $order->get_status() ) {

Check failure on line 705 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Cannot call method get_status() on WC_Order|WC_Order_Refund|true.

Check failure on line 705 in src/Extension.php

View workflow job for this annotation

GitHub Actions / phpstan / phpstan

Cannot call method needs_payment() on WC_Order|WC_Order_Refund|true.
$new_status = WooCommerce::ORDER_STATUS_PENDING;
}

Expand Down
23 changes: 11 additions & 12 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,18 +450,17 @@ public function process_payment( $order_id ) {
// Reload order for actual status (could be paid already; i.e. through recurring credit card payment).
$order = \wc_get_order( $order );

// Order note and status.
$new_status_slug = WooCommerce::ORDER_STATUS_PENDING;

$note = __( 'Awaiting payment.', 'pronamic_ideal' );

$order_status = WooCommerce::order_get_status( $order );

// Only add order note if status is already pending or if WooCommerce Deposits is activated.
if ( $new_status_slug === $order_status || isset( $order->wc_deposits_remaining ) ) {
$order->add_order_note( $note );
} elseif ( PaymentStatus::SUCCESS !== $payment->get_status() ) {
$order->update_status( $new_status_slug, $note );
/**
* For new WooCommerce orders, the order status is 'pending' by
* default. It is possible that a first payment attempt fails and the
* order status is set to 'failed'. If a new payment attempt is made,
* we will reset the order status to pending payment.
*
* @link https://github.com/woocommerce/woocommerce/blob/7897a61a1040ca6ed3310cb537ce22211058256c/plugins/woocommerce/includes/abstracts/abstract-wc-order.php#L402-L403
* @link https://github.com/pronamic/wp-pronamic-pay-woocommerce/issues/48
*/
if ( $order->needs_payment() && 'pending' !== $order->get_status() ) {
$order->update_status( 'pending', \__( 'Awaiting payment.', 'pronamic_ideal' ) );
}

// Return results array.
Expand Down

0 comments on commit 7892e23

Please sign in to comment.