Skip to content

Commit

Permalink
Merge pull request #334 from reepay/pre-1.7.6
Browse files Browse the repository at this point in the history
Fix function for php unit test
  • Loading branch information
ponddeja authored Jul 16, 2024
2 parents 1a20b6c + 533fff3 commit dcbc7bb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
27 changes: 17 additions & 10 deletions includes/OrderFlow/InstantSettle.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,10 @@ public function process_instant_settle( WC_Order $order ) {

self::$order_capture->settle_items( $order, $items_data, $total_all, $settle_items );

/**
* Recheck the invoice before adding the order meta data _is_instant_settled.
*
* @param WC_Order $order order to get items.
*/
$invoice = reepay()->api( $order )->get_invoice_data( $order );
if ( isset( $invoice['state'] ) && 'settled' === $invoice['state'] ) {
$order->add_meta_data( '_is_instant_settled', '1' );
$order->save_meta_data();
}
$order->add_meta_data( '_is_instant_settled', '1' );
$order->save_meta_data();

$this->check_order_settled( $order );
}
}

Expand Down Expand Up @@ -282,4 +276,17 @@ public static function get_settled_items( WC_Order $order ): array {

return $settled;
}

/**
* Recheck the invoice before adding the order meta data _is_instant_settled.
*
* @param WC_Order $order order to get items.
*/
public function check_order_settled( WC_Order $order ) {
$invoice = reepay()->api( $order )->get_invoice_data( $order );
if ( isset( $invoice['state'] ) && 'settled' !== $invoice['state'] ) {
$order->delete_meta_data( '_is_instant_settled', '1' );
$order->save_meta_data();
}
}
}
6 changes: 2 additions & 4 deletions tests/unit/orderFlow/InstantSettleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public function test_maybe_settle_instantly_with_reepay_payment_method() {

self::$instant_settle_instance->maybe_settle_instantly( $this->order_generator->order() );

// Disable because live call error 2024-07-02
// $this->assertSame( '1', $this->order_generator->get_meta( '_is_instant_settled' ) );
$this->assertSame( '1', $this->order_generator->get_meta( '_is_instant_settled' ) );
}

/**
Expand Down Expand Up @@ -100,11 +99,10 @@ public function test_process_instant_settle_already_settled() {

self::$instant_settle_instance->process_instant_settle( $this->order_generator->order() );

/* Disable because live call error 2024-07-02
$this->assertFalse(
WC_Order_Factory::get_order_item( $order_item_id )->meta_exists( 'settled' )
);
*/

}

/**
Expand Down

0 comments on commit dcbc7bb

Please sign in to comment.