Note N1 · Markasium
VERIFYING THE IYZICO CALLBACK
Verifying the Iyzico Checkout Form callback: don't trust the callback, ask Iyzico
- Sheet
- MARKASIUM
- Topic
- Spring Boot · Iyzico
- Source
- payment/PaymentService.java
- Date
- 2026-11-12
- Reading
- 3 min
Short answer: trust nothing in the callback request Iyzico sends through the browser. Take only the token and ask Iyzico for the payment result on the server side.
A payment counts as successful only when four conditions hold together: the request succeeded, paymentStatus is SUCCESS,
basketId is your order, and the paid amount equals the expected amount. If the same token arrives twice, do nothing; if the callback never arrives,
ask Iyzico about pending orders at regular intervals.
01Flow
Card data never reaches the Markasium server. The server gets a payment page URL from Iyzico, putting the order number (conversationId,
basketId) and the return address (callbackUrl) in the request. The customer pays on Iyzico's page. Iyzico sends the browser to the
return address with a POST; the body only carries a token.
@PostMapping("/api/v1/payments/iyzico/callback")
public ResponseEntity<Void> callback(@RequestParam(value = "token", required = false) String token) {
return ResponseEntity.status(HttpStatus.SEE_OTHER)
.location(URI.create(paymentService.handleCallback(token))).build();
}
The response is always 303 See Other: the browser goes to the result page with a GET, so refreshing does not resubmit the payment form.
02Why the callback can't be trusted
This request comes from the customer's browser, not from Iyzico's servers; every field in it can be changed. So the endpoint requires no session, but it decides nothing by itself: it finds the payment record by token and asks Iyzico for the result.
JsonNode res = iyzico.retrieveCheckoutForm(token, basketId);
boolean ok = "success".equals(res.path("status").asText())
&& "SUCCESS".equals(res.path("paymentStatus").asText())
&& basketId.equals(res.path("basketId").asText())
&& p.getAmount().compareTo(new BigDecimal(res.path("paidPrice").asText("0"))) == 0;
The amount is compared with compareTo. BigDecimal.equals also looks at scale and treats 10.0 and 10.00 as different.
03The same callback twice
The back button or a refresh can send the same callback again. If the payment record is already SUCCESS, Iyzico is not asked again; the customer
goes straight to the success page.
04Paying in two tabs and cancelled orders
A customer can pay for the same order in two tabs, or the order may be cancelled while the payment is in progress. In both cases the money has been taken. If another successful payment exists for the same order, or the order can no longer be marked as paid, the payment is refunded immediately.
boolean duplicate = paymentRepo.findByOrderIdAndStatus(orderId, PaymentStatus.SUCCESS).stream()
.anyMatch(other -> !other.getId().equals(p.getId()));
if (duplicate || !orderService.markPaid(orderId)) {
refundPayment(p, p.getAmount(), duplicate ? "Mükerrer ödeme" : "Sipariş iptal edilmişti");
}
05The lost callback
If the customer closes the tab after paying, the callback never arrives, yet the money has been taken. A job running every five minutes asks Iyzico about orders older than 30 minutes that are still awaiting payment (at most 50 per run).
- If paid, the callback logic runs as is; the order reaches the restaurant.
- If not, the payment is closed as "abandoned" and the order is cancelled. Statistics count it separately from card declines.
If the job fails on one order it logs it and moves on; one broken order does not stop the whole run. Only the error type is logged, not the message; details returned by the payment provider do not leak into logs.
06Failed payment
If Iyzico does not approve the payment, the record becomes FAILED and the provider's error message (at most 300 characters) is kept as the reason.
The order moves to "payment failed"; the customer returns to the checkout page with the reason. The reason is URL-encoded before being added to the address.
07Audit trail
Every successful payment, every failed payment and every refund is written to the audit log: user, order or subscription, amount. The card itself never reaches Markasium; the user key Iyzico returns for a saved card is stored, so the customer does not re-enter the card next time. A saved card can only be deleted with its owner's key; someone else's card token does not match it.
→More notes from this project
—End of notewritten by MUHAMMEDPYZ