Add PayPal transaction id to order note

This commit is contained in:
dinamiko 2022-01-31 11:02:51 +01:00
parent f454c60292
commit d2f257a812
4 changed files with 20 additions and 6 deletions

View file

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

View file

@ -277,7 +277,7 @@ trait ProcessPaymentTrait {
if ( $error->has_detail( 'INSTRUMENT_DECLINED' ) ) { if ( $error->has_detail( 'INSTRUMENT_DECLINED' ) ) {
$wc_order->update_status( $wc_order->update_status(
'failed', 'failed',
__( 'Instrument declined. ' . $error->details()[0]->description ?? '', 'woocommerce-paypal-payments' ) __( 'Instrument declined. ', 'woocommerce-paypal-payments' ) . $error->details()[0]->description ?? ''
); );
$this->session_handler->increment_insufficient_funding_tries(); $this->session_handler->increment_insufficient_funding_tries();
@ -317,7 +317,7 @@ trait ProcessPaymentTrait {
$wc_order->update_status( $wc_order->update_status(
'failed', 'failed',
__( 'Could not process order. ' . $this->order_processor->last_error() , 'woocommerce-paypal-payments' ) __( 'Could not process order. ', 'woocommerce-paypal-payments' ) . $this->order_processor->last_error()
); );
return $failure_data; return $failure_data;
@ -362,7 +362,7 @@ trait ProcessPaymentTrait {
$wc_order->update_status( $wc_order->update_status(
'failed', 'failed',
__( 'Could not process order. ' . $error->getMessage(), 'woocommerce-paypal-payments' ) __( 'Could not process order. ', 'woocommerce-paypal-payments' ) . $error->getMessage()
); );
$this->session_handler->destroy_session_data(); $this->session_handler->destroy_session_data();

View file

@ -36,6 +36,15 @@ trait TransactionIdHandlingTrait {
try { try {
$wc_order->set_transaction_id( $transaction_id ); $wc_order->set_transaction_id( $transaction_id );
$wc_order->save(); $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; return true;
} catch ( Exception $exception ) { } catch ( Exception $exception ) {
if ( $logger ) { if ( $logger ) {