mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Throw user friendly error message if it exist in the response
This commit is contained in:
parent
95d8ee9fff
commit
150d29c0b4
1 changed files with 11 additions and 4 deletions
|
@ -97,8 +97,15 @@ class Orders {
|
||||||
|
|
||||||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||||
if ( ! in_array( $status_code, array( 200, 201 ), true ) ) {
|
if ( ! in_array( $status_code, array( 200, 201 ), true ) ) {
|
||||||
|
$body = json_decode( $response['body'] );
|
||||||
|
|
||||||
|
$message = $body->details[0]->description ?? '';
|
||||||
|
if ( $message ) {
|
||||||
|
throw new RuntimeException( $message );
|
||||||
|
}
|
||||||
|
|
||||||
throw new PayPalApiException(
|
throw new PayPalApiException(
|
||||||
json_decode( $response['body'] ),
|
$body,
|
||||||
$status_code
|
$status_code
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -111,15 +118,15 @@ class Orders {
|
||||||
*
|
*
|
||||||
* @link https://developer.paypal.com/docs/api/orders/v2/#orders_confirm
|
* @link https://developer.paypal.com/docs/api/orders/v2/#orders_confirm
|
||||||
*
|
*
|
||||||
* @param array $request_body The request body.
|
* @param array $request_body The request body.
|
||||||
* @param string $id PayPal order ID.
|
* @param string $id PayPal order ID.
|
||||||
* @return array
|
* @return array
|
||||||
* @throws RuntimeException If something went wrong with the request.
|
* @throws RuntimeException If something went wrong with the request.
|
||||||
* @throws PayPalApiException If something went wrong with the PayPal API request.
|
* @throws PayPalApiException If something went wrong with the PayPal API request.
|
||||||
*/
|
*/
|
||||||
public function confirm_payment_source(array $request_body, string $id): array {
|
public function confirm_payment_source( array $request_body, string $id ): array {
|
||||||
$bearer = $this->bearer->bearer();
|
$bearer = $this->bearer->bearer();
|
||||||
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id .'/confirm-payment-source';
|
$url = trailingslashit( $this->host ) . 'v2/checkout/orders/' . $id . '/confirm-payment-source';
|
||||||
|
|
||||||
$args = array(
|
$args = array(
|
||||||
'method' => 'POST',
|
'method' => 'POST',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue