mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Bail if json property not set & fix ci PCP-696
This commit is contained in:
parent
57620bb0ee
commit
cec69d64da
1 changed files with 22 additions and 17 deletions
|
@ -324,7 +324,7 @@ class OrderEndpoint {
|
||||||
$json = json_decode( $response['body'] );
|
$json = json_decode( $response['body'] );
|
||||||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||||
if ( 201 !== $status_code ) {
|
if ( 201 !== $status_code ) {
|
||||||
$json = $this->addImprovedErrorMessage($json);
|
$json = $this->add_improved_error_message( $json );
|
||||||
$error = new PayPalApiException(
|
$error = new PayPalApiException(
|
||||||
$json,
|
$json,
|
||||||
$status_code
|
$status_code
|
||||||
|
@ -404,6 +404,7 @@ class OrderEndpoint {
|
||||||
if ( false !== strpos( $response['body'], ErrorResponse::ORDER_ALREADY_AUTHORIZED ) ) {
|
if ( false !== strpos( $response['body'], ErrorResponse::ORDER_ALREADY_AUTHORIZED ) ) {
|
||||||
return $this->order( $order->id() );
|
return $this->order( $order->id() );
|
||||||
}
|
}
|
||||||
|
$json = $this->add_improved_error_message( $json );
|
||||||
$error = new PayPalApiException(
|
$error = new PayPalApiException(
|
||||||
$json,
|
$json,
|
||||||
$status_code
|
$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
|
* @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(
|
$improved_keys_messages = array(
|
||||||
'PAYMENT_DENIED' => __( 'PayPal rejected the payment. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ),
|
'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' ),
|
'TRANSACTION_REFUSED' => __( 'The transaction has been refused by the payment processor. Please reach out to the PayPal support for more information.', 'woocommerce-paypal-payments' ),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue