Skip to content

Detect a currency change after the Quickpay payment was created - #63

Merged
loevgaard merged 1 commit into
2.xfrom
fix/convert-currency-drift
Aug 17, 2026
Merged

Detect a currency change after the Quickpay payment was created#63
loevgaard merged 1 commit into
2.xfrom
fix/convert-currency-drift

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Fixes robustness finding R7 of #57.

Problem

ConvertPaymentAction wrote $details['currency'] = $paymentModel->getCurrencyCode() unconditionally, on every conversion. A Quickpay payment's currency is fixed at creation, so if the Payum payment's currency changed after the Quickpay payment existed, the stored value silently drifted: the shop believed one currency while Quickpay kept authorizing in the other — with the amount read in the wrong unit. (A null model currency also overwrote a good stored value.)

Fix

  • Create path: unchanged, and now the details' currency is written from the same asserted value the payment is created with.
  • Already-created path: the model's currency is compared against the stored one. A mismatch throws a LogicException naming the payment and both currencies — the payment must be cancelled and a fresh one converted. A model without a currency keeps the stored value; an agreeing model is a no-op refresh.

Tests

Drifted currency throws with zero HTTP requests; a currency-less model keeps the stored value; the existing already-created and create-path tests pin the unchanged behavior.

@codecov

codecov Bot commented Aug 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.04%. Comparing base (4aeed1e) to head (5759e1f).

Additional details and impacted files
@@             Coverage Diff              @@
##                2.x      #63      +/-   ##
============================================
+ Coverage     96.93%   97.04%   +0.10%     
- Complexity      144      151       +7     
============================================
  Files            15       15              
  Lines           392      406      +14     
============================================
+ Hits            380      394      +14     
  Misses           12       12              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

A Quickpay payment's currency is fixed at creation — the authorize
happens in that currency no matter what the details say. But
ConvertPaymentAction overwrote the stored currency on every conversion,
so a Payum payment whose currency changed after conversion silently
drifted: the shop believed one currency while Quickpay kept charging in
the other, reading the amount in the wrong unit.

A drifted currency now throws a LogicException naming both currencies —
the payment must be cancelled and a fresh one converted. A model without
a currency (nullable on Payum's model) keeps the stored value instead of
overwriting it with null, and an agreeing model refreshes it as before.
@loevgaard
loevgaard force-pushed the fix/convert-currency-drift branch from 36ecfef to 5759e1f Compare August 17, 2026 06:55
@loevgaard
loevgaard merged commit 3733a6f into 2.x Aug 17, 2026
21 checks passed
@loevgaard
loevgaard deleted the fix/convert-currency-drift branch August 17, 2026 07:03
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.

1 participant