From d2f257a81238161824bb86bf719f6abb893efe1d Mon Sep 17 00:00:00 2001 From: dinamiko Date: Mon, 31 Jan 2022 11:02:51 +0100 Subject: [PATCH] Add PayPal transaction id to order note --- .../src/Exception/PayPalApiException.php | 5 +++++ .../src/Gateway/ProcessPaymentTrait.php | 10 +++++----- .../ppcp-wc-gateway/src/Processor/OrderProcessor.php | 2 +- .../src/Processor/TransactionIdHandlingTrait.php | 9 +++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-api-client/src/Exception/PayPalApiException.php b/modules/ppcp-api-client/src/Exception/PayPalApiException.php index fca6f08c3..699bb2423 100644 --- a/modules/ppcp-api-client/src/Exception/PayPalApiException.php +++ b/modules/ppcp-api-client/src/Exception/PayPalApiException.php @@ -111,6 +111,11 @@ class PayPalApiException extends RuntimeException { return false; } + /** + * Returns response issues. + * + * @return array + */ public function issues(): array { return $this->response->issues ?? array(); } diff --git a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php index c8f88461f..a563be1e7 100644 --- a/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php +++ b/modules/ppcp-wc-gateway/src/Gateway/ProcessPaymentTrait.php @@ -277,7 +277,7 @@ trait ProcessPaymentTrait { if ( $error->has_detail( 'INSTRUMENT_DECLINED' ) ) { $wc_order->update_status( '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(); @@ -299,10 +299,10 @@ trait ProcessPaymentTrait { } $error_message = $error->getMessage(); - if($error->issues()) { + if ( $error->issues() ) { $error_message = $error->issues()[0]->issue . ' ' . $error->issues()[0]->description; } - wc_add_notice($error_message, 'error'); + wc_add_notice( $error_message, 'error' ); $this->session_handler->destroy_session_data(); } catch ( RuntimeException $error ) { @@ -317,7 +317,7 @@ trait ProcessPaymentTrait { $wc_order->update_status( '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; @@ -362,7 +362,7 @@ trait ProcessPaymentTrait { $wc_order->update_status( '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(); diff --git a/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php b/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php index af83f195c..5b56d0bc2 100644 --- a/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php +++ b/modules/ppcp-wc-gateway/src/Processor/OrderProcessor.php @@ -141,7 +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'); + $this->last_error = __( 'No PayPal order found in the current WooCommerce session.', 'woocommerce-paypal-payments' ); return false; } diff --git a/modules/ppcp-wc-gateway/src/Processor/TransactionIdHandlingTrait.php b/modules/ppcp-wc-gateway/src/Processor/TransactionIdHandlingTrait.php index 76c16a977..c6e666176 100644 --- a/modules/ppcp-wc-gateway/src/Processor/TransactionIdHandlingTrait.php +++ b/modules/ppcp-wc-gateway/src/Processor/TransactionIdHandlingTrait.php @@ -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 ) {