-
Notifications
You must be signed in to change notification settings - Fork 70
Enhanced order decline reason detection via processor response object integration (6061) #4314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,11 +87,28 @@ protected function handle_capture_status( | |
| // It is checked in the capture endpoint already, but there are other ways to capture, | ||
| // such as when paid via saved card. | ||
| case CaptureStatus::DECLINED: | ||
| $fraud = $capture->fraud_processor_response(); | ||
| if ( $fraud && $fraud->response_code() ) { | ||
| $wc_order->add_order_note( | ||
| sprintf( | ||
| /* translators: %s - processor response code and description */ | ||
| __( 'PayPal payment declined. Processor response: %s', 'woocommerce-paypal-payments' ), | ||
| $fraud->get_response_code_message() | ||
| ) | ||
| ); | ||
| } | ||
| $wc_order->update_status( | ||
| 'failed', | ||
| __( 'Could not capture the payment.', 'woocommerce-paypal-payments' ) | ||
| ); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code calls $wc_order->update_status(
'failed',
$fraud && $fraud->response_code()
? sprintf( __( 'Could not capture the payment. Processor response: %s', '…' ), $fraud->get_response_code_message() )
: __( 'Could not capture the payment.', '…' )
); |
||
| throw new RuntimeException( __( 'Payment provider declined the payment, please use a different payment method.', 'woocommerce-paypal-payments' ) ); | ||
| $decline_message = ( $fraud && $fraud->response_code() ) | ||
| ? sprintf( | ||
| /* translators: %s - processor response code and description */ | ||
| __( 'Payment declined by card processor: %s. Please use a different payment method or contact your bank.', 'woocommerce-paypal-payments' ), | ||
| $fraud->get_response_code_message() | ||
| ) | ||
| : __( 'Payment provider declined the payment, please use a different payment method.', 'woocommerce-paypal-payments' ); | ||
| throw new RuntimeException( $decline_message ); | ||
| case CaptureStatus::PENDING: | ||
| case CaptureStatus::FAILED: | ||
| $wc_order->update_status( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |
| use WooCommerce\PayPalCommerce\AdminNotices\Repository\Repository; | ||
| use WooCommerce\PayPalCommerce\ApiClient\Entity\Authorization; | ||
| use WooCommerce\PayPalCommerce\ApiClient\Entity\Capture; | ||
| use WooCommerce\PayPalCommerce\ApiClient\Entity\FraudProcessorResponse; | ||
| use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus; | ||
| use WooCommerce\PayPalCommerce\ApiClient\Helper\ReferenceTransactionStatus; | ||
| use WooCommerce\PayPalCommerce\ApiClient\Helper\Cache; | ||
|
|
@@ -166,6 +167,30 @@ function ( int $order_id ) use ( $fees_renderer ) { | |
| } | ||
| ); | ||
|
|
||
| add_action( | ||
| 'woocommerce_admin_order_totals_after_total', | ||
| function ( int $order_id ) { | ||
| $wc_order = wc_get_order( $order_id ); | ||
| if ( ! $wc_order instanceof WC_Order ) { | ||
| return; | ||
| } | ||
| $fraud_result = $wc_order->get_meta( PayPalGateway::FRAUD_RESULT_META_KEY ); | ||
| if ( empty( $fraud_result['response_code'] ) ) { | ||
| return; | ||
| } | ||
| $fraud = new FraudProcessorResponse( | ||
| $fraud_result['avs_code'] ?? null, | ||
| $fraud_result['cvv2_code'] ?? null, | ||
| $fraud_result['response_code'] | ||
| ); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here it instantiates a full |
||
| printf( | ||
| '<tr><td class="label">%s:</td><td width="1%%"></td><td class="total">%s</td></tr>', | ||
| esc_html__( 'Processor Response', 'woocommerce-paypal-payments' ), | ||
| esc_html( $fraud->get_response_code_message() ) | ||
| ); | ||
| } | ||
| ); | ||
|
|
||
| add_action( | ||
| 'admin_enqueue_scripts', | ||
| function () use ( $c ) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exact message is duplicated in PaymentsStatusHandlingTrait.php, consider adding a helper on the entity (e.g.
FraudProcessorResponse::get_customer_decline_message(): string) so in the future requires touching only one place.