Fix iOS compilation errors in StoreKitManager

Fixed all compilation errors:

1. Changed from switch/case to if-let pattern for Kotlin ApiResult types
   - ApiResult doesn't have .success/.failure/.loading/.idle cases in Swift
   - Used "as? ApiResultSuccess" and "as? ApiResultError" pattern instead

2. Fixed SubscriptionStatus name conflict
   - Fully qualified as ComposeApp.SubscriptionStatus
   - Avoids conflict with StoreKit's Product.SubscriptionInfo.Status

3. Fixed VerificationResponse handling
   - VerificationResponse only has success, tier, error fields
   - After verification, fetch full subscription status via getSubscriptionStatus
   - Properly unwrap optional response.data

4. Added try-catch for Kotlin suspend functions
   - Kotlin suspend functions throw in Swift
   - Wrapped await calls in do-try-catch blocks

5. Removed unused getReceiptData function
   - Inlined the logic directly in verifyTransactionWithBackend

iOS build now succeeds with no errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Trey t
2025-11-24 14:20:22 -06:00
parent b5b3353529
commit d92a4fd4f1

View File

@@ -184,54 +184,42 @@ class StoreKitManager: ObservableObject {
}
// Get transaction receipt data
guard let receiptData = try? await getReceiptData(for: transaction) else {
print("❌ StoreKit: Failed to get receipt data")
return
}
let receiptData = String(transaction.id)
// Call backend verification endpoint
let result = await subscriptionApi.verifyIOSReceipt(
let result = try await subscriptionApi.verifyIOSReceipt(
token: token,
receiptData: receiptData,
transactionId: String(transaction.id)
)
switch result {
case .success(let response):
print("✅ StoreKit: Backend verification successful - Tier: \(response.tier)")
// Handle result (Kotlin ApiResult type)
if let successResult = result as? ApiResultSuccess<VerificationResponse>,
let response = successResult.data,
response.success {
print("✅ StoreKit: Backend verification successful - Tier: \(response.tier ?? "unknown")")
// Update subscription cache
await MainActor.run {
let subscription = SubscriptionStatus(
tier: response.tier,
usage: response.usage,
limits: response.limits,
limitationsEnabled: response.limitationsEnabled
)
SubscriptionCacheWrapper.shared.updateSubscription(subscription)
// Fetch updated subscription status from backend
let statusResult = try await subscriptionApi.getSubscriptionStatus(token: token)
if let statusSuccess = statusResult as? ApiResultSuccess<ComposeApp.SubscriptionStatus>,
let subscription = statusSuccess.data {
await MainActor.run {
SubscriptionCacheWrapper.shared.updateSubscription(subscription)
}
}
case .failure(let error):
print("❌ StoreKit: Backend verification failed: \(error)")
case .loading:
break
case .idle:
break
} else if let errorResult = result as? ApiResultError {
print("❌ StoreKit: Backend verification failed: \(errorResult.message)")
} else if let successResult = result as? ApiResultSuccess<VerificationResponse>,
let response = successResult.data,
!response.success {
print("❌ StoreKit: Backend verification failed: \(response.error ?? "Unknown error")")
}
} catch {
print("❌ StoreKit: Backend verification error: \(error)")
}
}
/// Get receipt data for transaction
private func getReceiptData(for transaction: Transaction) async throws -> String {
// In StoreKit 2, we send the transaction ID instead of the legacy receipt
// The backend should verify the transaction with Apple's servers
return String(transaction.id)
}
/// Verify the cryptographic signature of a transaction
private func checkVerified<T>(_ result: VerificationResult<T>) throws -> T {
switch result {