This commit is contained in:
zjx 2025-07-19 13:41:15 +08:00
parent a18432c64b
commit 33d6182dbf
3 changed files with 66 additions and 68 deletions

View File

@ -6,6 +6,7 @@
//
import SmartCodable
import StoreKit
class VPWalletAPI {
@ -21,15 +22,64 @@ class VPWalletAPI {
VPHUD.show()
}
VPIAPManager.manager.requestProductData(isToast: isToast) { model in
if isLoding {
VPHUD.dismiss()
_requestPayTemplate(isToast: false) { model in
guard let model = model else {
if isLoding {
VPHUD.dismiss()
}
completer?(nil)
return
}
completer?(model)
var productIdArr: [String] = []
model.list_sub_vip?.forEach { item in
productIdArr.append(VPIAPManager.manager.getProductId(templateId: item.ios_template_id) ?? "")
}
model.list_coins?.forEach { item in
productIdArr.append(VPIAPManager.manager.getProductId(templateId: item.ios_template_id) ?? "")
}
VPIAPManager.manager.requestProductList(productIdArr: productIdArr) { products in
if isLoding {
VPHUD.dismiss()
}
var newCoinList: [VPPayTemplateItem] = []
var newVipList: [VPPayTemplateItem] = []
model.list_coins?.forEach { item in
let productId = VPIAPManager.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
}
}
}
model.list_sub_vip?.forEach { item in
let productId = VPIAPManager.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
}
}
}
model.list_coins = newCoinList
model.list_sub_vip = newVipList
completer?(model)
}
}
}
static func _requestPayTemplate(isToast: Bool = true, completer: ((_ model: VPPayTemplateModel?) -> Void)?) {
private static func _requestPayTemplate(isToast: Bool = true, completer: ((_ model: VPPayTemplateModel?) -> Void)?) {
var param = VPNetworkParameters(path: "/paySettingsV3")
param.method = .get
param.isToast = isToast

View File

@ -20,11 +20,8 @@ class VPIAPManager {
///
private var completionHandler: CompletionHandler?
///
private var productDataHandler: ((_ model: VPPayTemplateModel?) -> Void)?
///
private var oldPayTemplateModel: VPPayTemplateModel?
private var productListHandler: ((_ products: [SKProduct]) -> Void)?
private lazy var iapManager: JXIAPManager = {
let manager = JXIAPManager()
@ -142,31 +139,13 @@ class VPIAPManager {
}
///
func requestProductData(isToast: Bool = false, completer: ((_ model: VPPayTemplateModel?) -> Void)?) {
VPWalletAPI._requestPayTemplate(isToast: isToast) { [weak self] model in
guard let self = self else { return }
guard let model = model else {
completer?(nil)
return
}
self.productDataHandler = completer
self.oldPayTemplateModel = model
var productIdArr: [String] = []
model.list_sub_vip?.forEach { item in
productIdArr.append(self.getProductId(templateId: item.ios_template_id) ?? "")
}
model.list_coins?.forEach { item in
productIdArr.append(self.getProductId(templateId: item.ios_template_id) ?? "")
}
self.iapManager.requestProductList(productIdArr: productIdArr)
}
func requestProductList(productIdArr: [String], completer: ((_ products: [SKProduct]) -> Void)?) {
self.productListHandler = completer
self.iapManager.requestProductList(productIdArr: productIdArr)
}
private func getProductId(templateId: String?) -> String? {
func getProductId(templateId: String?) -> String? {
guard let templateId = templateId else { return nil }
return VPIAPManager.IAPPrefix + templateId
}
@ -237,42 +216,11 @@ extension VPIAPManager: JXIAPManagerDelegate {
self.completionHandler?(false)
}
func jx_iapPayGotProducts(productIds: [SKProduct]) {
guard let payTemplateModel = self.oldPayTemplateModel else { return }
func jx_iapPayGotProducts(products: [SKProduct]) {
var newCoinList: [VPPayTemplateItem] = []
var newVipList: [VPPayTemplateItem] = []
self.productListHandler?(products)
payTemplateModel.list_coins?.forEach { item in
let productId = getProductId(templateId: item.ios_template_id) ?? ""
for product in productIds {
if productId == product.productIdentifier {
item.price = product.price.stringValue
item.currency = product.priceLocale.currencySymbol
newCoinList.append(item)
break
}
}
}
payTemplateModel.list_sub_vip?.forEach { item in
let productId = getProductId(templateId: item.ios_template_id) ?? ""
for product in productIds {
if productId == product.productIdentifier {
item.price = product.price.stringValue
item.currency = product.priceLocale.currencySymbol
newVipList.append(item)
break
}
}
}
payTemplateModel.list_sub_vip = newVipList
payTemplateModel.list_coins = newCoinList
productDataHandler?(payTemplateModel)
self.productDataHandler = nil
self.oldPayTemplateModel = nil
self.productListHandler = nil
}
}

View File

@ -10,7 +10,7 @@ import StoreKit
@objc protocol JXIAPManagerDelegate {
///
@objc optional func jx_iapPayGotProducts(productIds: [SKProduct])
@objc optional func jx_iapPayGotProducts(products: [SKProduct])
///
@objc optional func jx_iapPaySuccess(productId: String, receipt: String, transactionIdentifier: String?)
///
@ -163,7 +163,7 @@ extension JXIAPManager: SKProductsRequestDelegate {
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
if self.operationType == .request {
DispatchQueue.main.async {
self.delegate?.jx_iapPayGotProducts?(productIds: response.products)
self.delegate?.jx_iapPayGotProducts?(products: response.products)
}
self.operationType = .idle
} else if self.operationType == .buy {