Skip to content

Commit

Permalink
Don't update canceled order to on-hold in the dispute created event (#…
Browse files Browse the repository at this point in the history
…3672)

* Don't update canceled order to on-hold in the dispute created event

* Changelog and readme entries

* Specific unit test
  • Loading branch information
wjrosa authored Dec 20, 2024
1 parent 9691ad8 commit 9cd5240
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 9.1.0 - xxxx-xx-xx =
* Fix - Don't update canceled order status to on-hold when a dispute is opened.
* Fix - Correctly sets the dispute opened note when a dispute does not require any further action.
* Add - Display Multibanco payment instruction details in Order Received page and Order Confirmation email.
* Tweak - Add the transaction limit information to the Afterpay/Clearpay method when listing payment methods.
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-stripe-webhook-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function process_webhook_dispute( $notification ) {
$message = __( 'A dispute was created for this order.', 'woocommerce-gateway-stripe' );
}

if ( ! $order->get_meta( '_stripe_status_final', false ) ) {
if ( ! $order->has_status( 'cancelled' ) && ! $order->get_meta( '_stripe_status_final', false ) ) {
$order->update_status( 'on-hold', $message );
} else {
$order->add_order_note( $message );
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 9.1.0 - xxxx-xx-xx =
* Fix - Don't update canceled order status to on-hold when a dispute is opened.
* Fix - Correctly sets the dispute opened note when a dispute does not require any further action.
* Add - Display Multibanco payment instruction details in Order Received page and Order Confirmation email.
* Tweak - Add the transaction limit information to the Afterpay/Clearpay method when listing payment methods.
Expand Down
14 changes: 12 additions & 2 deletions tests/phpunit/test-wc-stripe-webhook-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,11 @@ public function provide_test_process_webhook_charge_failed() {
* @return void
* @dataProvider provide_test_process_webhook_dispute
*/
public function test_process_webhook_dispute( $order_status_final, $dispute_status, $expected_status, $expected_note ) {
public function test_process_webhook_dispute( $order_status, $order_status_final, $dispute_status, $expected_status, $expected_note ) {
$charge_id = 'ch_fQpkNKxmUrZ8t4CT7EHGS3Rg';

$order = WC_Helper_Order::create_order();
$order->set_status( 'processing' );
$order->set_status( $order_status );
$order->set_transaction_id( $charge_id );
if ( $order_status_final ) {
$order->update_meta_data( '_stripe_status_final', true );
Expand Down Expand Up @@ -351,18 +351,28 @@ public function test_process_webhook_dispute( $order_status_final, $dispute_stat
public function provide_test_process_webhook_dispute() {
return [
'response needed, order status not final' => [
'order status' => 'processing',
'order status final' => false,
'dispute status' => 'needs_response',
'expected status' => 'on-hold',
'expected note' => '/A dispute was created for this order. Response is needed./',
],
'response needed, order status not final, status is cancelled' => [
'order status' => 'cancelled',
'order status final' => false,
'dispute status' => 'needs_response',
'expected status' => 'cancelled',
'expected note' => '/A dispute was created for this order. Response is needed./',
],
'response needed, order status final' => [
'order status' => 'processing',
'order status final' => true,
'dispute status' => 'needs_response',
'expected status' => 'processing',
'expected note' => '/A dispute was created for this order. Response is needed./',
],
'response not needed, order status not final' => [
'order status' => 'processing',
'order status final' => false,
'dispute status' => 'lost',
'expected status' => 'on-hold',
Expand Down

0 comments on commit 9cd5240

Please sign in to comment.