fix: decode actual API response format #29

Merged
schwifty merged 1 commit from schwifty/fix-api-response-decoding into main 2026-03-22 21:27:15 +00:00
Collaborator

Problem

Every API call in the beacon app was failing with "Failed to load businesses" (and similar errors for other endpoints).

Root Cause

The iOS APIResponse<T> generic decoder expected {Success, Message, Data} keys, but the actual Payfrit API returns {OK, ERROR, BUSINESSES} (flat keys, no nested Data). Since Success was never present, the decoder defaulted to false and threw errors.

Additionally:

  • Business model mapped id to "ID" but API returns "BusinessID"
  • Business model mapped name to "BusinessName" but API returns "Name"
  • ServicePoint model had the same ID vs ServicePointID mismatch

Fix

  • Replaced the broken generic APIResponse<T> with endpoint-specific response structs that match the actual API format
  • Fixed Business model to decode both BusinessID/ID and Name/BusinessName
  • Fixed ServicePoint model to decode both ServicePointID/ID

Test Plan

  • Login with OTP
  • Verify business list loads
  • Select business, verify service points load
  • Beacon scanning and provisioning flow
## Problem Every API call in the beacon app was failing with "Failed to load businesses" (and similar errors for other endpoints). ## Root Cause The iOS `APIResponse<T>` generic decoder expected `{Success, Message, Data}` keys, but the actual Payfrit API returns `{OK, ERROR, BUSINESSES}` (flat keys, no nested `Data`). Since `Success` was never present, the decoder defaulted to `false` and threw errors. Additionally: - `Business` model mapped `id` to `"ID"` but API returns `"BusinessID"` - `Business` model mapped `name` to `"BusinessName"` but API returns `"Name"` - `ServicePoint` model had the same `ID` vs `ServicePointID` mismatch ## Fix - Replaced the broken generic `APIResponse<T>` with endpoint-specific response structs that match the actual API format - Fixed `Business` model to decode both `BusinessID`/`ID` and `Name`/`BusinessName` - Fixed `ServicePoint` model to decode both `ServicePointID`/`ID` ## Test Plan - [ ] Login with OTP - [ ] Verify business list loads - [ ] Select business, verify service points load - [ ] Beacon scanning and provisioning flow
schwifty added 1 commit 2026-03-22 21:27:10 +00:00
The API returns {OK: true, BUSINESSES: [...]} but the iOS client was
decoding {Success: true, Data: [...]} which never matched — causing
"Failed to load businesses" on every call. Also fixes Business model
(BusinessID/Name vs ID/BusinessName) and ServicePoint model
(ServicePointID vs ID). All response decoders now match the real API.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
schwifty merged commit 1624e0e59d into main 2026-03-22 21:27:15 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: payfrit/payfrit-beacon-ios#29
No description provided.