Repository navigation
fix(paypal): a capture is credited only in the currency the shop charges in - #186
Merged
Panelica merged 2 commits intoOct 12, 2026
Merged
Conversation
…n, the capture endpoint and the webhook
Owner
|
Thank you, @ertugrulkeyvan, merged. A PayPal capture is now credited only in the currency the shop charges in, so a capture of 100 in a cheaper currency can no longer settle an invoice of 100 in the shop's. Checked before merging: every order the panel creates, from the pay button and from the unattended charge of a stored PayPal account, is opened in the shop currency, so genuine payments go through as before. Three of your tests fail on |
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.
What
A PayPal capture is now credited only when it is in the shop's currency.
The PayPal buttons build the order in the browser (
actions.order.create), currency included. Before crediting, the capture is verified with PayPal (verifyCapture()), which checks that it isCOMPLETEDand takes its amount from PayPal rather than from the browser. It did not check the currency.So a capture of 100.00 in a currency worth far less than the shop's was credited as 100.00 in the shop's currency. With a USD shop, a 100.00 USD invoice was marked paid by a 100 HUF capture. This happens on both paths:
/gateway/paypal/capture/{invoice});PAYMENT.CAPTURE.COMPLETEDwebhook.Whether such a capture completes depends on the merchant account's settings for payments in currencies it does not hold. Many accounts accept and convert them.
After this:
verifyCapture()refuses a capture in any currency but the expected one, the shop's by default, compared in upper case.How
PayPalModule::verifyCapture(): takes an optional$expectedCurrency, defaulting toshop_currency_code(). It compares that withamount.currency_code, logs a mismatch and refuses it.processWebhook(), use the default, so neither changes.The work is split into two commits: the fix, then its tests.
Tests
tests/Feature/PayPalCaptureCurrencyTest.php, 4 tests:Three of them fail on
main; there, the 100 HUF capture marks the 100.00 USD invoice paid.PayPalWebhookSecurityTestandPayPalTokenisationTestpass unchanged (63).Full suite: 4107 passed. The one failure is the
CurrencyAndBackupTestdb backup test, which fails onmaintoo in my local setup.