Enhanced order decline reason detection via processor response object integration (6061)#4314
Conversation
| $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' ); |
There was a problem hiding this comment.
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.
| $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' ) | ||
| ); |
There was a problem hiding this comment.
This code calls add_order_note and then update_status which also writes a status-change note, consider passing the $note argument of update_status() instead, e.g.:
$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.', '…' )
);| $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'] | ||
| ); |
There was a problem hiding this comment.
Here it instantiates a full FraudProcessorResponse from stored meta only to call get_response_code_message() below. The avs/cvv args are not used for output here, consider reusing FraudProcessorResponseFactory::from_paypal_response( (object) $fraud_result ) instead.
Issue: #
Ticket:
Slack Thread:
Description
Adds response_code support to FraudProcessorResponse, parsing it from PayPal's capture response and mapping it
to human-readable descriptions. When a capture is declined, the processor response code is now
surfaced in the customer-facing exception message, the WC order note —
replacing the previous generic "payment declined" message wherever a specific code is available.
Steps to Test
Pay with creditcard failed transaction test numbers
Observe message in checkout indicating failure reason
Observe order note indicating failure reason
Changelog Entry
Added - enhanced order decline reason detection via processor response object integration
Closes # .