always return array from the process_payment()

This commit is contained in:
Kirill Braslavsky 2021-03-15 16:43:39 +02:00
parent 9bdd2631dd
commit edb0c9551c

View file

@ -21,13 +21,19 @@ trait ProcessPaymentTrait {
* *
* @param int $order_id The WooCommerce order id. * @param int $order_id The WooCommerce order id.
* *
* @return array|null * @return array
*/ */
public function process_payment( $order_id ) { public function process_payment( $order_id ) {
global $woocommerce; global $woocommerce;
$failure_data = array(
'result' => 'failure',
'redirect' => wc_get_checkout_url(),
);
$wc_order = wc_get_order( $order_id ); $wc_order = wc_get_order( $order_id );
if ( ! is_a( $wc_order, \WC_Order::class ) ) { if ( ! is_a( $wc_order, \WC_Order::class ) ) {
return null; return $failure_data;
} }
/** /**
@ -63,7 +69,7 @@ trait ProcessPaymentTrait {
__( 'Please use a different payment method.', 'woocommerce-paypal-payments' ), __( 'Please use a different payment method.', 'woocommerce-paypal-payments' ),
'error' 'error'
); );
return null; return $failure_data;
} }
return array( return array(
'result' => 'success', 'result' => 'success',
@ -75,7 +81,7 @@ trait ProcessPaymentTrait {
} catch ( RuntimeException $error ) { } catch ( RuntimeException $error ) {
$this->session_handler->destroy_session_data(); $this->session_handler->destroy_session_data();
wc_add_notice( $error->getMessage(), 'error' ); wc_add_notice( $error->getMessage(), 'error' );
return null; return $failure_data;
} }
wc_add_notice( wc_add_notice(
@ -83,6 +89,6 @@ trait ProcessPaymentTrait {
'error' 'error'
); );
return null; return $failure_data;
} }
} }