128 lines
4.0 KiB
Swift
128 lines
4.0 KiB
Swift
//
|
|
// BRPayDataRequest.swift
|
|
// BeeReel
|
|
//
|
|
// Created by 长沙鸿瑶 on 2025/7/26.
|
|
//
|
|
|
|
import UIKit
|
|
import StoreKit
|
|
|
|
class BRPayDataRequest: NSObject {
|
|
|
|
private var oldTemplateModel: BRPayDateModel?
|
|
private(set) var newTemplateModel: BRPayDateModel?
|
|
|
|
private var completerBlock: ((_ model: BRPayDateModel?) -> Void)?
|
|
|
|
private var isLoding = false
|
|
private var isToast = false
|
|
|
|
|
|
func requestProducts(isLoding: Bool = false, isToast: Bool = true, completer: ((_ model: BRPayDateModel?) -> Void)?) {
|
|
self.completerBlock = completer
|
|
self.isLoding = isLoding
|
|
self.isToast = isToast
|
|
|
|
// if let model = self.newTemplateModel {
|
|
// self.completerBlock?(model)
|
|
// return
|
|
// }
|
|
|
|
|
|
if isLoding {
|
|
BRHUD.show()
|
|
}
|
|
|
|
BRStoreAPI.requestPayTemplate(isToast: isToast) { [weak self] model in
|
|
if isLoding {
|
|
BRHUD.dismiss()
|
|
}
|
|
guard let self = self else { return }
|
|
guard let model = model else {
|
|
self.completerBlock?(nil)
|
|
return
|
|
}
|
|
self.newTemplateModel = model
|
|
completer?(model)
|
|
}
|
|
|
|
// BRStoreAPI.requestPayTemplate(isToast: isToast) { [weak self] model in
|
|
// guard let self = self else { return }
|
|
// guard let model = model else {
|
|
// if isLoding {
|
|
// BRHUD.dismiss()
|
|
// }
|
|
// self.completerBlock?(nil)
|
|
// return
|
|
// }
|
|
// self.oldTemplateModel = model
|
|
//
|
|
// var productIdArr: [String] = []
|
|
// model.list_sub_vip?.forEach { item in
|
|
// productIdArr.append(BRIAP.manager.getProductId(templateId: item.ios_template_id) ?? "")
|
|
// }
|
|
// model.list_coins?.forEach { item in
|
|
// productIdArr.append(BRIAP.manager.getProductId(templateId: item.ios_template_id) ?? "")
|
|
// }
|
|
//
|
|
// let set = Set(productIdArr)
|
|
// let productsRequest = SKProductsRequest(productIdentifiers: set)
|
|
// productsRequest.delegate = self
|
|
// productsRequest.start()
|
|
//
|
|
// }
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//MARK: -------------- SKProductsRequestDelegate --------------
|
|
extension BRPayDataRequest: SKProductsRequestDelegate {
|
|
|
|
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
|
|
if isLoding {
|
|
BRHUD.dismiss()
|
|
}
|
|
|
|
guard let templateModel = self.oldTemplateModel else { return }
|
|
let products = response.products
|
|
|
|
var newCoinList: [BRPayItem] = []
|
|
var newVipList: [BRPayItem] = []
|
|
|
|
templateModel.list_coins?.forEach { item in
|
|
let productId = BRIAP.manager.getProductId(templateId: item.ios_template_id) ?? ""
|
|
for product in products {
|
|
if productId == product.productIdentifier {
|
|
item.price = product.price.stringValue
|
|
item.currency = product.priceLocale.currencySymbol
|
|
newCoinList.append(item)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
templateModel.list_sub_vip?.forEach { item in
|
|
let productId = BRIAP.manager.getProductId(templateId: item.ios_template_id) ?? ""
|
|
for product in products {
|
|
if productId == product.productIdentifier {
|
|
item.price = product.price.stringValue
|
|
item.currency = product.priceLocale.currencySymbol
|
|
newVipList.append(item)
|
|
break
|
|
}
|
|
}
|
|
}
|
|
templateModel.list_coins = newCoinList
|
|
templateModel.list_sub_vip = newVipList
|
|
|
|
self.newTemplateModel = templateModel
|
|
|
|
DispatchQueue.main.async {
|
|
self.completerBlock?(templateModel)
|
|
}
|
|
}
|
|
}
|
|
|
|
|