Add admin edit subscription status handling

This commit is contained in:
Emili Castells Guasch 2023-04-04 12:32:40 +02:00
parent a65ec12294
commit dce0640d38
2 changed files with 86 additions and 0 deletions

View file

@ -165,4 +165,32 @@ class BillingSubscriptions {
);
}
}
public function subscription(string $id) {
$bearer = $this->bearer->bearer();
$url = trailingslashit( $this->host ) . 'v1/billing/subscriptions/' . $id;
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $bearer->token(),
'Content-Type' => 'application/json',
'Prefer' => 'return=representation'
),
);
$response = $this->request( $url, $args );
if ( is_wp_error( $response ) || ! is_array( $response ) ) {
throw new RuntimeException( 'Not able to get subscription.' );
}
$json = json_decode( $response['body'] );
$status_code = (int) wp_remote_retrieve_response_code( $response );
if ( 200 !== $status_code ) {
throw new PayPalApiException(
$json,
$status_code
);
}
return $json;
}
}