mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 12:25:15 +08:00
Don't throw an error if the order was already authorized
This commit is contained in:
parent
c6c931dc5c
commit
d94cb24393
1 changed files with 28 additions and 5 deletions
|
@ -122,7 +122,8 @@ class OrderEndpoint
|
|||
return $order;
|
||||
}
|
||||
|
||||
public function authorize(Order $order) : Order {
|
||||
public function authorize(Order $order): Order
|
||||
{
|
||||
$bearer = $this->bearer->bearer();
|
||||
$url = trailingslashit($this->host) . 'v2/checkout/orders/' . $order->id() . '/authorize';
|
||||
$args = [
|
||||
|
@ -135,12 +136,34 @@ class OrderEndpoint
|
|||
$response = wp_remote_post($url, $args);
|
||||
|
||||
if (is_wp_error($response)) {
|
||||
throw new RuntimeException(__('Could not authorize order.', 'woocommerce-paypal-commerce-gateway'));
|
||||
}
|
||||
if (wp_remote_retrieve_response_code($response) !== 201) {
|
||||
throw new RuntimeException(__('Could not authorize order.', 'woocommerce-paypal-commerce-gateway'));
|
||||
$this->handleResponseWpError($url, $args);
|
||||
throw new RuntimeException(
|
||||
__(
|
||||
'Could not authorize order.',
|
||||
'woocommerce-paypal-commerce-gateway'
|
||||
)
|
||||
);
|
||||
}
|
||||
$json = json_decode($response['body']);
|
||||
if (wp_remote_retrieve_response_code($response) !== 201) {
|
||||
$errors = $this->errorResponseFactory->fromPayPalResponse(
|
||||
$json,
|
||||
(int)wp_remote_retrieve_response_code($response),
|
||||
$url,
|
||||
$args
|
||||
);
|
||||
|
||||
if ($errors->hasErrorCode(ErrorResponse::ORDER_ALREADY_AUTHORIZED)) {
|
||||
return $this->order($order->id());
|
||||
}
|
||||
add_action('woocommerce-paypal-commerce-gateway.error', $errors);
|
||||
throw new RuntimeException(
|
||||
__(
|
||||
'Could not authorize order.',
|
||||
'woocommerce-paypal-commerce-gateway'
|
||||
)
|
||||
);
|
||||
}
|
||||
$order = $this->orderFactory->fromPayPalResponse($json);
|
||||
return $order;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue