mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +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);
|
$response = wp_remote_get($url, $args);
|
||||||
|
$json = json_decode($response['body']);
|
||||||
|
|
||||||
if (is_wp_error($response)) {
|
if (is_wp_error($response)) {
|
||||||
|
$this->handleResponseWpError($url, $args);
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
__(
|
__(
|
||||||
'Could not get authorized payment info.',
|
'Could not get authorized payment info.',
|
||||||
|
@ -52,6 +54,13 @@ class PaymentsEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wp_remote_retrieve_response_code($response) !== 200) {
|
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(
|
throw new RuntimeException(
|
||||||
__(
|
__(
|
||||||
'Could not get authorized payment info.',
|
'Could not get authorized payment info.',
|
||||||
|
@ -60,7 +69,6 @@ class PaymentsEndpoint
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$json = json_decode($response['body']);
|
|
||||||
$authorization = $this->authorizationFactory->fromPayPalRequest($json);
|
$authorization = $this->authorizationFactory->fromPayPalRequest($json);
|
||||||
return $authorization;
|
return $authorization;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +86,10 @@ class PaymentsEndpoint
|
||||||
];
|
];
|
||||||
|
|
||||||
$response = wp_remote_post($url, $args);
|
$response = wp_remote_post($url, $args);
|
||||||
|
$json = json_decode($response['body']);
|
||||||
|
|
||||||
if (is_wp_error($response)) {
|
if (is_wp_error($response)) {
|
||||||
|
$this->handleResponseWpError($url, $args);
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
__(
|
__(
|
||||||
'Could not capture authorized payment.',
|
'Could not capture authorized payment.',
|
||||||
|
@ -89,6 +99,13 @@ class PaymentsEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wp_remote_retrieve_response_code($response) !== 201) {
|
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(
|
throw new RuntimeException(
|
||||||
__(
|
__(
|
||||||
'Could not capture authorized payment.',
|
'Could not capture authorized payment.',
|
||||||
|
@ -97,8 +114,16 @@ class PaymentsEndpoint
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$json = json_decode($response['body']);
|
|
||||||
$authorization = $this->authorizationFactory->fromPayPalRequest($json);
|
$authorization = $this->authorizationFactory->fromPayPalRequest($json);
|
||||||
return $authorization;
|
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