Throw error when hosted fields transaction declined and display an error message to the customer

This commit is contained in:
dinamiko 2020-11-20 15:40:01 +01:00
parent bc86c8341f
commit c5a107d02b
3 changed files with 26 additions and 8 deletions

View file

@ -329,7 +329,20 @@ class OrderEndpoint {
);
throw $error;
}
$order = $this->order_factory->from_paypal_response( $json );
$purchase_units_payments_captures_status = $order->purchase_units()[0]->payments()->captures()[0]->status() ?? '';
if ( $purchase_units_payments_captures_status && 'DECLINED' === $purchase_units_payments_captures_status ) {
throw new RuntimeException(
sprintf(
// translators: %s is the current status.
__( 'Purchase units payments captures status %s', 'woocommerce-paypal-payments' ),
$purchase_units_payments_captures_status
)
);
}
return $order;
}