Repository navigation
fix(iyzico): an invoice billed in lira is charged the lira on the invoice - #181
Conversation
…efunded at the invoice's own rate
…ed card too, and what a refund gives back
Panelica
left a comment
There was a problem hiding this comment.
Thank you, @ertugrulkeyvan. Charging the lira the invoice shows is the right behaviour, and the tests make the case clearly.
One thing needs changing before this can go in, in refund():
A payment taken before this change is refunded short. It was charged at the stored rate, not the invoice's. A lira-billed invoice frozen at 40 and paid when the stored rate was 42 took ₺420. A full refund of €10 after this change converts at 40, sends ₺400, and the customer gets ₺20 less than was taken. On main the same refund sends ₺420. We measured this with a test built on yours (paidPrice 420, stored rate 42, invoice rate 40).
The rate the payment was actually taken at is on the payment itself: paidPrice from iyzico against the shop amount recorded on the transaction (amount_in). Converting with that ratio gives back exactly what was taken for payments from before and after the change, and keeps a part refund proportional.
Could you switch refund() to that, and add a test for a payment taken at the stored rate?
…from iyzico's paid price and the recorded amount
…took, in full and in part
|
Thank you, that is a real case I had missed. Pushed:
The earlier tests still pass, since for payments taken at the invoice's rate the ratio is that rate. |
|
Thank you, @ertugrulkeyvan, merged, with one commit on top. An invoice billed in lira is now charged the lira it shows, from the pay page and from a stored card, and a refund converts at the rate the payment was actually taken at. The commit we added, 2f91fa2: iyzico answers a refund with the payment's own id, so a refund is recorded under the same transaction id with nothing in |
What
iyzico now charges the lira amount the invoice shows, not today's conversion of it.
An iyzico merchant account settles in lira, so the module converts the amount due into TRY before charging. It converted with the TRY rate stored today.
An invoice billed in lira (Setup → Currencies, the invoice's billing stamp) already says what it comes to: its rate was frozen the day it was raised. Take a €10.00 invoice raised at 40: it shows ₺400.00. Once the stored rate had moved to 42, iyzico charged ₺420.00, and the customer saw a different figure on the payment page and on their card than on the invoice.
We bill Turkish customers in lira and take cards through iyzico, so every renewal across a rate change showed the gap.
After this, for an invoice billed in lira:
paidPriceagainst the amount recorded for the payment (amount_in). That holds both for payments charged at the invoice's rate and for those charged at the stored rate before this change. A full refund gives back exactly the lira that were taken, and a part stays in proportion. Without a recorded payment, the invoice's rate is used, then the stored one.Unchanged:
Recording a payment needed no change. The callback and the stored-card path already convert back with the rate written down when the charge started, which is now the invoice's rate.
How
invoiceLiraRate(): the invoice'sexchange_ratewhen it has a billing conversion into TRY, otherwise null.tryPrice(): takes the invoice and prefers that rate.capture()andchargeStoredMethod()pass the invoice.refund(): finds the transaction, the same way the Stripe module does, and converts withpaidPrice / amount_in; it falls back to the invoice's rate, then the stored rate. An amount within a cent of what was taken refunds what was taken.The work is split into four commits: the fix and its tests, then the refund rate from review and its tests.
Tests
tests/Feature/IyzicoInvoiceLiraRateTest.php, 7 tests:Five of them fail on
mainor on the first version of this branch.IyzicoGatewayTestandIyzicoStoredCardTestpass unchanged.Full suite: 4093 passed. The one failure is the
CurrencyAndBackupTestdb backup test, which fails onmaintoo in my local setup.