优化
This commit is contained in:
parent
a18432c64b
commit
33d6182dbf
@ -6,6 +6,7 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import SmartCodable
|
import SmartCodable
|
||||||
|
import StoreKit
|
||||||
|
|
||||||
class VPWalletAPI {
|
class VPWalletAPI {
|
||||||
|
|
||||||
@ -21,15 +22,64 @@ class VPWalletAPI {
|
|||||||
VPHUD.show()
|
VPHUD.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
VPIAPManager.manager.requestProductData(isToast: isToast) { model in
|
_requestPayTemplate(isToast: false) { model in
|
||||||
if isLoding {
|
guard let model = model else {
|
||||||
VPHUD.dismiss()
|
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")
|
var param = VPNetworkParameters(path: "/paySettingsV3")
|
||||||
param.method = .get
|
param.method = .get
|
||||||
param.isToast = isToast
|
param.isToast = isToast
|
||||||
|
@ -20,11 +20,8 @@ class VPIAPManager {
|
|||||||
///成功回调
|
///成功回调
|
||||||
private var completionHandler: CompletionHandler?
|
private var completionHandler: CompletionHandler?
|
||||||
|
|
||||||
///获取支付模版回调
|
|
||||||
private var productDataHandler: ((_ model: VPPayTemplateModel?) -> Void)?
|
|
||||||
|
|
||||||
///原始支付模版数据
|
private var productListHandler: ((_ products: [SKProduct]) -> Void)?
|
||||||
private var oldPayTemplateModel: VPPayTemplateModel?
|
|
||||||
|
|
||||||
private lazy var iapManager: JXIAPManager = {
|
private lazy var iapManager: JXIAPManager = {
|
||||||
let manager = JXIAPManager()
|
let manager = JXIAPManager()
|
||||||
@ -142,31 +139,13 @@ class VPIAPManager {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///获取支付数据
|
func requestProductList(productIdArr: [String], completer: ((_ products: [SKProduct]) -> Void)?) {
|
||||||
func requestProductData(isToast: Bool = false, completer: ((_ model: VPPayTemplateModel?) -> Void)?) {
|
self.productListHandler = completer
|
||||||
VPWalletAPI._requestPayTemplate(isToast: isToast) { [weak self] model in
|
self.iapManager.requestProductList(productIdArr: productIdArr)
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func getProductId(templateId: String?) -> String? {
|
|
||||||
|
func getProductId(templateId: String?) -> String? {
|
||||||
guard let templateId = templateId else { return nil }
|
guard let templateId = templateId else { return nil }
|
||||||
return VPIAPManager.IAPPrefix + templateId
|
return VPIAPManager.IAPPrefix + templateId
|
||||||
}
|
}
|
||||||
@ -237,42 +216,11 @@ extension VPIAPManager: JXIAPManagerDelegate {
|
|||||||
self.completionHandler?(false)
|
self.completionHandler?(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func jx_iapPayGotProducts(productIds: [SKProduct]) {
|
func jx_iapPayGotProducts(products: [SKProduct]) {
|
||||||
guard let payTemplateModel = self.oldPayTemplateModel else { return }
|
|
||||||
|
|
||||||
var newCoinList: [VPPayTemplateItem] = []
|
self.productListHandler?(products)
|
||||||
var newVipList: [VPPayTemplateItem] = []
|
|
||||||
|
|
||||||
payTemplateModel.list_coins?.forEach { item in
|
self.productListHandler = nil
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import StoreKit
|
|||||||
|
|
||||||
@objc protocol JXIAPManagerDelegate {
|
@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?)
|
@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) {
|
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
|
||||||
if self.operationType == .request {
|
if self.operationType == .request {
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.delegate?.jx_iapPayGotProducts?(productIds: response.products)
|
self.delegate?.jx_iapPayGotProducts?(products: response.products)
|
||||||
}
|
}
|
||||||
self.operationType = .idle
|
self.operationType = .idle
|
||||||
} else if self.operationType == .buy {
|
} else if self.operationType == .buy {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user