Merge pull request #458 from woocommerce/PCP-488-extend-event-error-logging-order

Improve error display
This commit is contained in:
Emili Castells 2022-02-02 12:33:03 +01:00 committed by GitHub
commit 2f87393d4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 4 deletions

View file

@ -110,4 +110,13 @@ class PayPalApiException extends RuntimeException {
}
return false;
}
/**
* Returns response issues.
*
* @return array
*/
public function issues(): array {
return $this->response->issues ?? array();
}
}

View file

@ -48,7 +48,12 @@ class CheckoutActionHandler {
.querySelector('ul')
);
} else {
errorHandler.message(data.data.message, true);
errorHandler.clear();
if (data.data.details.length > 0) {
errorHandler.message(data.data.details.map(d => `${d.issue} ${d.description}`).join('<br/>'), true);
} else {
errorHandler.message(data.data.message, true);
}
}
return;

View file

@ -277,7 +277,7 @@ trait ProcessPaymentTrait {
if ( $error->has_detail( 'INSTRUMENT_DECLINED' ) ) {
$wc_order->update_status(
'failed',
__( 'Instrument declined.', 'woocommerce-paypal-payments' )
__( 'Instrument declined. ', 'woocommerce-paypal-payments' ) . $error->details()[0]->description ?? ''
);
$this->session_handler->increment_insufficient_funding_tries();
@ -298,6 +298,19 @@ trait ProcessPaymentTrait {
);
}
$error_message = $error->getMessage();
if ( $error->issues() ) {
$error_message = implode(
array_map(
function( $issue ) {
return $issue->issue . ' ' . $issue->description . '<br/>';
},
$error->issues()
)
);
}
wc_add_notice( $error_message, 'error' );
$this->session_handler->destroy_session_data();
} catch ( RuntimeException $error ) {
$this->handle_failure( $wc_order, $error );
@ -308,9 +321,10 @@ trait ProcessPaymentTrait {
$this->order_processor->last_error(),
'error'
);
$wc_order->update_status(
'failed',
__( 'Could not process order.', 'woocommerce-paypal-payments' )
__( 'Could not process order. ', 'woocommerce-paypal-payments' ) . $this->order_processor->last_error()
);
return $failure_data;
@ -355,7 +369,7 @@ trait ProcessPaymentTrait {
$wc_order->update_status(
'failed',
__( 'Could not process order.', 'woocommerce-paypal-payments' )
__( 'Could not process order. ', 'woocommerce-paypal-payments' ) . $error->getMessage()
);
$this->session_handler->destroy_session_data();

View file

@ -141,6 +141,7 @@ class OrderProcessor {
public function process( \WC_Order $wc_order ): bool {
$order = $this->session_handler->order();
if ( ! $order ) {
$this->last_error = __( 'No PayPal order found in the current WooCommerce session.', 'woocommerce-paypal-payments' );
return false;
}

View file

@ -36,6 +36,15 @@ trait TransactionIdHandlingTrait {
try {
$wc_order->set_transaction_id( $transaction_id );
$wc_order->save();
$wc_order->add_order_note(
sprintf(
/* translators: %s is the PayPal transaction ID */
__( 'PayPal transaction ID: %s', 'woocommerce-paypal-payments' ),
$transaction_id
)
);
return true;
} catch ( Exception $exception ) {
if ( $logger ) {

View file

@ -189,6 +189,7 @@ class WcGatewayTest extends TestCase
->andReturnFalse();
$this->orderProcessor
->expects('last_error')
->twice()
->andReturn($lastError);
$this->subscriptionHelper->shouldReceive('has_subscription')->with($orderId)->andReturn(true);
$this->subscriptionHelper->shouldReceive('is_subscription_change_payment')->andReturn(true);