Skip to content

Enhanced order decline reason detection via processor response object integration (6061)#4314

Merged
Dinamiko merged 3 commits into
dev/developfrom
PCP-6061-enhanced-order-decline-reason-detection-via-processor-response-object-integration
May 4, 2026
Merged

Enhanced order decline reason detection via processor response object integration (6061)#4314
Dinamiko merged 3 commits into
dev/developfrom
PCP-6061-enhanced-order-decline-reason-detection-via-processor-response-object-integration

Conversation

@mmaymo

@mmaymo mmaymo commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

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 # .

@mmaymo mmaymo changed the title Pcp 6061 enhanced order decline reason detection via processor response object integration Enhanced order decline reason detection via processor response object integration (6061) Apr 29, 2026
Comment on lines +352 to +358
$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' );

Copy link
Copy Markdown
Collaborator

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.

Comment on lines 92 to 103
$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' )
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.', '' )
);

Comment on lines +177 to +185
$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']
);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Dinamiko
Dinamiko merged commit 9bcf822 into dev/develop May 4, 2026
11 checks passed
@Dinamiko
Dinamiko deleted the PCP-6061-enhanced-order-decline-reason-detection-via-processor-response-object-integration branch May 4, 2026 12:21
@InpsydeNiklas InpsydeNiklas added this to the 4.1.0 milestone May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants