mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Merge pull request #886 from woocommerce/PCP-922-update-order-with-order-note-if-payment-failed-after-billing-agreement-canceled-at-pay-pal
update order with order note if payment failed after billing agreement canceled at PayPal (922)
This commit is contained in:
commit
aa7a7adaf7
4 changed files with 44 additions and 29 deletions
|
@ -119,4 +119,26 @@ class PayPalApiException extends RuntimeException {
|
||||||
public function status_code(): int {
|
public function status_code(): int {
|
||||||
return $this->status_code;
|
return $this->status_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return exception details if exists.
|
||||||
|
*
|
||||||
|
* @param string $error The error to return in case no details found.
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function get_details( string $error ): string {
|
||||||
|
if ( empty( $this->details() ) ) {
|
||||||
|
return $error;
|
||||||
|
}
|
||||||
|
|
||||||
|
$details = '';
|
||||||
|
foreach ( $this->details() as $detail ) {
|
||||||
|
$issue = $detail->issue ?? '';
|
||||||
|
$field = $detail->field ?? '';
|
||||||
|
$description = $detail->description ?? '';
|
||||||
|
$details .= $issue . ' ' . $field . ' ' . $description . '<br>';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $details;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\Subscription;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\PaymentToken;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\PayPalApiException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PayerFactory;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\ShippingPreferenceFactory;
|
||||||
|
@ -141,17 +142,27 @@ class RenewalHandler {
|
||||||
public function renew( \WC_Order $wc_order ) {
|
public function renew( \WC_Order $wc_order ) {
|
||||||
try {
|
try {
|
||||||
$this->process_order( $wc_order );
|
$this->process_order( $wc_order );
|
||||||
} catch ( \Exception $error ) {
|
} catch ( \Exception $exception ) {
|
||||||
$this->logger->error(
|
$error = $exception->getMessage();
|
||||||
sprintf(
|
if ( is_a( $exception, PayPalApiException::class ) ) {
|
||||||
|
$error = $exception->get_details( $error );
|
||||||
|
}
|
||||||
|
|
||||||
|
$wc_order->update_status(
|
||||||
|
'failed',
|
||||||
|
$error
|
||||||
|
);
|
||||||
|
|
||||||
|
$error_message = sprintf(
|
||||||
'An error occurred while trying to renew the subscription for order %1$d: %2$s',
|
'An error occurred while trying to renew the subscription for order %1$d: %2$s',
|
||||||
$wc_order->get_id(),
|
$wc_order->get_id(),
|
||||||
$error->getMessage()
|
$error
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
$this->logger->error( $error_message );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->info(
|
$this->logger->info(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Renewal for order %d is completed.',
|
'Renewal for order %d is completed.',
|
||||||
|
|
|
@ -167,17 +167,8 @@ class OXXOGateway extends WC_Payment_Gateway {
|
||||||
}
|
}
|
||||||
} catch ( RuntimeException $exception ) {
|
} catch ( RuntimeException $exception ) {
|
||||||
$error = $exception->getMessage();
|
$error = $exception->getMessage();
|
||||||
|
if ( is_a( $exception, PayPalApiException::class ) ) {
|
||||||
if ( is_a( $exception, PayPalApiException::class ) && is_array( $exception->details() ) ) {
|
$error = $exception->get_details( $error );
|
||||||
$details = '';
|
|
||||||
foreach ( $exception->details() as $detail ) {
|
|
||||||
$issue = $detail->issue ?? '';
|
|
||||||
$field = $detail->field ?? '';
|
|
||||||
$description = $detail->description ?? '';
|
|
||||||
$details .= $issue . ' ' . $field . ' ' . $description . '<br>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$error = $details;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->error( $error );
|
$this->logger->error( $error );
|
||||||
|
|
|
@ -274,17 +274,8 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
||||||
);
|
);
|
||||||
} catch ( RuntimeException $exception ) {
|
} catch ( RuntimeException $exception ) {
|
||||||
$error = $exception->getMessage();
|
$error = $exception->getMessage();
|
||||||
|
if ( is_a( $exception, PayPalApiException::class ) ) {
|
||||||
if ( is_a( $exception, PayPalApiException::class ) && is_array( $exception->details() ) ) {
|
$error = $exception->get_details( $error );
|
||||||
$details = '';
|
|
||||||
foreach ( $exception->details() as $detail ) {
|
|
||||||
$issue = $detail->issue ?? '';
|
|
||||||
$field = $detail->field ?? '';
|
|
||||||
$description = $detail->description ?? '';
|
|
||||||
$details .= $issue . ' ' . $field . ' ' . $description . '<br>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$error = $details;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->logger->error( $error );
|
$this->logger->error( $error );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue