55 return ;
66}
77
8+ use Automattic \WooCommerce \Utilities \OrderUtil ;
9+
810/**
911 * RFW_Payment_Gateway class
1012 */
@@ -312,7 +314,7 @@ public function display_capture_button( $order ) {
312314 * @return void
313315 */
314316 public function process_capture ( $ post_id ) {
315- if ( get_post_type ( $ post_id ) !== ' shop_order ' ) {
317+ if ( ' shop_order ' !== OrderUtil:: get_order_type ( $ post_id ) ) {
316318 return ;
317319 }
318320
@@ -348,7 +350,7 @@ public function process_capture( $post_id ) {
348350 }
349351 }
350352
351- $ this ->send_capture_request ( $ charge_id , $ order );
353+ $ this ->send_capture_request ( $ charge_id , $ order, true );
352354 }
353355
354356
@@ -357,15 +359,18 @@ public function process_capture( $post_id ) {
357359 *
358360 * @param string $charge_id ID of the order in Resolve system, used to capture funds.
359361 * @param WC_Order $order Object of the order in WooCommerce.
362+ * @param bool $manual Is the capture automatically initiated or manually by webshop administrator.
360363 *
361364 * @return void
362365 */
363- private function send_capture_request ( $ charge_id , $ order ) {
366+ private function send_capture_request ( $ charge_id , $ order, $ manual = false ) {
364367 $ url_format = 'https://%s:%s@%s.resolvepay.com/api/charges/%s/capture ' ;
365368
366369 $ merchant_id = RFW_Data::get_settings ( 'webshop-merchant-id ' , true );
367370 $ api_key = RFW_Data::get_settings ( 'webshop-api-key ' , true );
368371
372+ $ captured_order_status = RFW_Data::get_captured_status ();
373+
369374 $ mode = RFW_Data::test_mode () ? 'app-sandbox ' : 'app ' ;
370375 $ url = sprintf ( $ url_format , $ merchant_id , $ api_key , $ mode , $ charge_id );
371376 $ args = [
@@ -394,7 +399,9 @@ private function send_capture_request( $charge_id, $order ) {
394399 } else {
395400 do_action ( 'rfw_order_payment_captured ' , $ order );
396401 // translators: charge ID.
397- $ order ->set_status ( apply_filters ( 'rfw_payment_captured_order_status ' , 'processing ' ), sprintf ( __ ( 'The payment was successfully captured! Resolve ID: %s. ' , 'resolve ' ), '<b> ' . $ body ['number ' ] . '</b> ' ) );
402+ $ order ->set_status ( $ captured_order_status , sprintf ( __ ( 'The payment was successfully captured! Resolve ID: %s. ' , 'resolve ' ), '<b> ' . $ body ['number ' ] . '</b> ' ), $ manual );
403+ // Prevent post status update overriding order status with value submited in form.
404+ $ _POST ['order_status ' ] = 'wc- ' . $ captured_order_status ;
398405
399406 $ order ->payment_complete ( $ body ['number ' ] );
400407 $ order ->add_meta_data ( 'rfw_payment_captured ' , 'yes ' , true );
0 commit comments