mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Skip already handled refunds in webhook
When we add a refund from WC, we still receive a webhook with it. And for some partial refunds the duplicated refund can be added in WC.
This commit is contained in:
parent
13e04b009c
commit
35f058870a
5 changed files with 74 additions and 10 deletions
|
@ -198,11 +198,11 @@ class PaymentsEndpoint {
|
|||
*
|
||||
* @param Refund $refund The refund to be processed.
|
||||
*
|
||||
* @return void
|
||||
* @return string Refund ID.
|
||||
* @throws RuntimeException If the request fails.
|
||||
* @throws PayPalApiException If the request fails.
|
||||
*/
|
||||
public function refund( Refund $refund ) : void {
|
||||
public function refund( Refund $refund ) : string {
|
||||
$bearer = $this->bearer->bearer();
|
||||
$url = trailingslashit( $this->host ) . 'v2/payments/captures/' . $refund->for_capture()->id() . '/refund';
|
||||
$args = array(
|
||||
|
@ -223,12 +223,15 @@ class PaymentsEndpoint {
|
|||
}
|
||||
|
||||
$status_code = (int) wp_remote_retrieve_response_code( $response );
|
||||
if ( 201 !== $status_code ) {
|
||||
$json = json_decode( $response['body'] );
|
||||
if ( 201 !== $status_code || ! is_object( $json ) ) {
|
||||
throw new PayPalApiException(
|
||||
$json,
|
||||
$status_code
|
||||
);
|
||||
}
|
||||
|
||||
return $json->id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue