Bail if json property not set & fix ci PCP-696

This commit is contained in:
carmenmaymo 2023-05-05 11:41:07 +02:00
parent 57620bb0ee
commit cec69d64da
No known key found for this signature in database
GPG key ID: 6023F686B0F3102E

View file

@ -324,7 +324,7 @@ class OrderEndpoint {
$json = json_decode( $response['body'] );
$status_code = (int) wp_remote_retrieve_response_code( $response );
if ( 201 !== $status_code ) {
$json = $this->addImprovedErrorMessage($json);
$json = $this->add_improved_error_message( $json );
$error = new PayPalApiException(
$json,
$status_code
@ -404,6 +404,7 @@ class OrderEndpoint {
if ( false !== strpos( $response['body'], ErrorResponse::ORDER_ALREADY_AUTHORIZED ) ) {
return $this->order( $order->id() );
}
$json = $this->add_improved_error_message( $json );
$error = new PayPalApiException(
$json,
$status_code
@ -622,11 +623,15 @@ class OrderEndpoint {
}
/**
* @param $json
* Adds an improved error message to the response if the error detail is known.
*
* @param Object $json The response.
* @return Object
*/
public function addImprovedErrorMessage($json): Object
{
public function add_improved_error_message( $json ): object {
if ( ! isset( $json->details ) ) {
return $json;
}
$improved_keys_messages = array(
'PAYMENT_DENIED' => __( 'PayPal rejected the payment. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ),
'TRANSACTION_REFUSED' => __( 'The transaction has been refused by the payment processor. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ),