mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Pass the errors to the ErrorResponse handler
This commit is contained in:
parent
df9a74d551
commit
d989617f69
1 changed files with 27 additions and 2 deletions
|
@ -41,8 +41,10 @@ class PaymentsEndpoint
|
|||
];
|
||||
|
||||
$response = wp_remote_get($url, $args);
|
||||
$json = json_decode($response['body']);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
$this->handleResponseWpError($url, $args);
|
||||
throw new RuntimeException(
|
||||
__(
|
||||
'Could not get authorized payment info.',
|
||||
|
@ -52,6 +54,13 @@ class PaymentsEndpoint
|
|||
}
|
||||
|
||||
if (wp_remote_retrieve_response_code($response) !== 200) {
|
||||
$errors = $this->errorResponseFactory->fromPayPalResponse(
|
||||
$json,
|
||||
(int)wp_remote_retrieve_response_code($response),
|
||||
$url,
|
||||
$args
|
||||
);
|
||||
add_action('woocommerce-paypal-commerce-gateway.error', $errors);
|
||||
throw new RuntimeException(
|
||||
__(
|
||||
'Could not get authorized payment info.',
|
||||
|
@ -60,7 +69,6 @@ class PaymentsEndpoint
|
|||
);
|
||||
}
|
||||
|
||||
$json = json_decode($response['body']);
|
||||
$authorization = $this->authorizationFactory->fromPayPalRequest($json);
|
||||
return $authorization;
|
||||
}
|
||||
|
@ -78,8 +86,10 @@ class PaymentsEndpoint
|
|||
];
|
||||
|
||||
$response = wp_remote_post($url, $args);
|
||||
$json = json_decode($response['body']);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
$this->handleResponseWpError($url, $args);
|
||||
throw new RuntimeException(
|
||||
__(
|
||||
'Could not capture authorized payment.',
|
||||
|
@ -89,6 +99,13 @@ class PaymentsEndpoint
|
|||
}
|
||||
|
||||
if (wp_remote_retrieve_response_code($response) !== 201) {
|
||||
$errors = $this->errorResponseFactory->fromPayPalResponse(
|
||||
$json,
|
||||
(int)wp_remote_retrieve_response_code($response),
|
||||
$url,
|
||||
$args
|
||||
);
|
||||
add_action('woocommerce-paypal-commerce-gateway.error', $errors);
|
||||
throw new RuntimeException(
|
||||
__(
|
||||
'Could not capture authorized payment.',
|
||||
|
@ -97,8 +114,16 @@ class PaymentsEndpoint
|
|||
);
|
||||
}
|
||||
|
||||
$json = json_decode($response['body']);
|
||||
$authorization = $this->authorizationFactory->fromPayPalRequest($json);
|
||||
return $authorization;
|
||||
}
|
||||
|
||||
private function handleResponseWpError(string $url, array $args)
|
||||
{
|
||||
$errors = $this->errorResponseFactory->unknownError(
|
||||
$url,
|
||||
$args
|
||||
);
|
||||
add_action('woocommerce-paypal-commerce-gateway.error', $errors);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue