Update renewal order status to failed when renew subscription fails (WIP)

This commit is contained in:
dinamiko 2022-10-04 17:43:58 +02:00
parent 783377cddd
commit b946386eaf

View file

@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\Subscription;
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
@ -142,16 +143,32 @@ class RenewalHandler {
try {
$this->process_order( $wc_order );
} catch ( \Exception $error ) {
$this->logger->error(
sprintf(
'An error occurred while trying to renew the subscription for order %1$d: %2$s',
$wc_order->get_id(),
$error->getMessage()
)
$error_details = $error->getMessage();
if ( is_a( $error, PayPalApiException::class ) ) {
$details = '';
foreach ( $error->details() as $detail ) {
$details .= $detail->issue . ' ' . $detail->description;
}
if ( $details ) {
$error_details = $details;
}
}
$error_message = sprintf(
'An error occurred while trying to renew the subscription for order %1$d: %2$s',
$wc_order->get_id(),
$error_details
);
$wc_order->update_status(
'failed',
$error_details
);
$this->logger->error( $error_message );
return;
}
$this->logger->info(
sprintf(
'Renewal for order %d is completed.',