mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
Co-authored-by: RevenueCat Git Bot <72824662+RCGitBot@users.noreply.github.com> Co-authored-by: andy boedo <andresboedo@gmail.com> Co-authored-by: Cesar de la Vega <cesarvegaro@gmail.com>
53 lines
1.9 KiB
Swift
53 lines
1.9 KiB
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// RedeemWebPurchaseAPI.swift
|
|
//
|
|
// Created by Antonio Rico Diez on 2024-10-17.
|
|
|
|
import Foundation
|
|
|
|
class RedeemWebPurchaseAPI {
|
|
|
|
typealias RedeemWebPurchaseResponseHandler = Backend.ResponseHandler<CustomerInfo>
|
|
|
|
private let redeemWebPurchaseResponseCallbacksCache: CallbackCache<CustomerInfoCallback>
|
|
private let backendConfig: BackendConfiguration
|
|
|
|
init(backendConfig: BackendConfiguration) {
|
|
self.backendConfig = backendConfig
|
|
self.redeemWebPurchaseResponseCallbacksCache = .init()
|
|
}
|
|
|
|
func postRedeemWebPurchase(appUserID: String,
|
|
redemptionToken: String,
|
|
completion: @escaping RedeemWebPurchaseResponseHandler) {
|
|
let config = NetworkOperation.UserSpecificConfiguration(httpClient: self.backendConfig.httpClient,
|
|
appUserID: appUserID)
|
|
|
|
let factory = PostRedeemWebPurchaseOperation.createFactory(
|
|
configuration: config,
|
|
postData: .init(appUserID: appUserID, redemptionToken: redemptionToken),
|
|
customerInfoCallbackCache: self.redeemWebPurchaseResponseCallbacksCache
|
|
)
|
|
|
|
let callback = CustomerInfoCallback(cacheKey: factory.cacheKey,
|
|
source: PostRedeemWebPurchaseOperation.self,
|
|
completion: completion)
|
|
let cacheStatus = self.redeemWebPurchaseResponseCallbacksCache.add(callback)
|
|
|
|
self.backendConfig.addCacheableOperation(
|
|
with: factory,
|
|
delay: .none,
|
|
cacheStatus: cacheStatus
|
|
)
|
|
}
|
|
|
|
}
|