Fix PayflowPro response resolver notifying a payment failure for a cart with no Payflow payment - #41253
Open
TuVanDev wants to merge 1 commit into
Open
Conversation
…rt with no Payflow payment Magento\PaypalGraphQl\Model\Resolver\PayflowProResponse loads the cart from the caller-supplied masked cart_id and, on any validation failure of the paypal_payload, calls PaymentFailuresInterface::handle(), which sends the merchant "Payment Transaction Failed" notification. It does this without confirming the cart ever entered a Payflow payment flow, so a well-formed request for a cart that has no Payflow method selected reaches the notification even though no genuine payment was attempted. Require a Payflow payment method (payflowpro or payflowpro_cc_vault) on the cart before the resolver proceeds. The legitimate Payflow Pro flow selects the method with setPaymentMethodOnCart before this resolver runs, so a genuine decline still carries a Payflow method and still notifies; a cart with no such method is refused with the existing "Transaction has been declined." error and no notification is sent. The module had no unit tests; this adds coverage for all three cases: a cart without a Payflow method is refused without notifying, a genuine Payflow decline still notifies, and a valid response returns the cart.
|
Hi @TuVanDev. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description (*)
Magento\PaypalGraphQl\Model\Resolver\PayflowProResponse::resolve()loads the cart from the caller-supplied maskedcart_idand, on any validation failure ofpaypal_payload, callsPaymentFailuresInterface::handle(), which sends the merchant "Payment Transaction Failed" notification email:Nothing between loading the cart and this point confirms the cart ever entered a Payflow payment flow. A well-formed request for a cart that simply has no Payflow method selected still fails validation and still reaches
handle(), so the store sends itself the merchant payment-failure notification even though no genuine payment was ever attempted on that cart. The legitimate Payflow Pro flow always establishes a Payflow method first (setPaymentMethodOnCart(payflowpro), thencreatePayflowProToken), so a real decline always carries a Payflow method; only the no-payment case is unguarded.This PR requires a Payflow payment method on the cart before the resolver proceeds:
A genuine Payflow decline still carries a Payflow method and still notifies, so the intended behavior is unchanged. A cart with no Payflow method is refused with the resolver's existing
Transaction has been declined.message and no notification is sent.Config::METHOD_PAYFLOWPROandTransparent::CC_VAULT_CODEare the complete set of Payflow method codes that reach this resolver in core (Transparentwas already imported;Configis added as ause).Related Pull Requests
Same change submitted to Mage-OS: mage-os/mageos-magento2#341
Fixed Issues (if relevant)
N/A. No existing GitHub issue was found. Searched
magento/magento2issues and pull requests forPayflowProResponse,handlePayflowProResponse payment failed, and open PRs withPayflowProResponsein the title; none matched. Search coverage is not proof of absence, so please close this as a duplicate if a prior report exists.Manual testing scenarios (*)
The module ships no unit tests, so this PR adds
PayflowProResponseTest. The behavior can also be exercised end to end on a store withMagento_PaypalGraphQlenabled:createEmptyCart).handlePayflowProResponsemutation for that cart with apaypal_payloadthat fails response validation.PaymentFailuresInterface::handle()and the store sends the merchant "Payment Transaction Failed" notification, even though the cart never had a Payflow payment selected.Transaction has been declined.input error and sends no notification.setPaymentMethodOnCartwithpayflowpro), then submit a declining response. Both before and after this change the merchant notification is sent, confirming genuine Payflow declines are unaffected.Contribution checklist (*)
app/code/Magento/PaypalGraphQl/Test/Unit/Model/Resolver/PayflowProResponseTest.php(the module had no unit tests). It covers a cart with no Payflow method (and an unrelated method) being refused without notifying, a genuine Payflow decline still notifying, and a valid response returning the cart, across bothpayflowproandpayflowpro_cc_vault.2.4-developwith PHPUnit 12.5.14: 7/7 green, and confirmed it fails (getResponseObject ... was not expected to be called) when the guard is reverted, so it is a real regression guard.vendor/bin/phpcs --standard=Magento2reports 0 errors and 0 warnings on both changed files. I did not run the full unit suite locally; relying on CI for that.