内购价格随地区变化
This commit is contained in:
parent
536482bd2d
commit
a18432c64b
@ -16,9 +16,22 @@ class VPWalletAPI {
|
||||
|
||||
///获取支付模版
|
||||
static func requestPayTemplate(isLoding: Bool = false, isToast: Bool = true, completer: ((_ model: VPPayTemplateModel?) -> Void)?) {
|
||||
|
||||
if isLoding {
|
||||
VPHUD.show()
|
||||
}
|
||||
|
||||
VPIAPManager.manager.requestProductData(isToast: isToast) { model in
|
||||
if isLoding {
|
||||
VPHUD.dismiss()
|
||||
}
|
||||
completer?(model)
|
||||
}
|
||||
}
|
||||
|
||||
static func _requestPayTemplate(isToast: Bool = true, completer: ((_ model: VPPayTemplateModel?) -> Void)?) {
|
||||
var param = VPNetworkParameters(path: "/paySettingsV3")
|
||||
param.method = .get
|
||||
param.isLoding = isLoding
|
||||
param.isToast = isToast
|
||||
|
||||
VPNetwork.request(parameters: param) { (response: VPNetworkResponse<VPPayTemplateModel>) in
|
||||
|
@ -20,6 +20,12 @@ class VPIAPManager {
|
||||
///成功回调
|
||||
private var completionHandler: CompletionHandler?
|
||||
|
||||
///获取支付模版回调
|
||||
private var productDataHandler: ((_ model: VPPayTemplateModel?) -> Void)?
|
||||
|
||||
///原始支付模版数据
|
||||
private var oldPayTemplateModel: VPPayTemplateModel?
|
||||
|
||||
private lazy var iapManager: JXIAPManager = {
|
||||
let manager = JXIAPManager()
|
||||
manager.delegate = self
|
||||
@ -37,6 +43,7 @@ class VPIAPManager {
|
||||
|
||||
///开始内购
|
||||
func start(model: VPPayTemplateItem, shortPlayId: String? = nil, videoId: String? = nil, isDiscount: Bool = false, hudShowView: UIView? = nil, handler: CompletionHandler? = nil) {
|
||||
// self.iapManager.showCodeRedemption()
|
||||
|
||||
if let _ = self.waitRestoreModel {
|
||||
VPToast.show(text: "veloria_pay_error_1".localized)
|
||||
@ -135,6 +142,35 @@ 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)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private func getProductId(templateId: String?) -> String? {
|
||||
guard let templateId = templateId else { return nil }
|
||||
return VPIAPManager.IAPPrefix + templateId
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//MARK: -------------- JXIAPManagerDelegate --------------
|
||||
@ -201,6 +237,44 @@ extension VPIAPManager: JXIAPManagerDelegate {
|
||||
self.completionHandler?(false)
|
||||
}
|
||||
|
||||
func jx_iapPayGotProducts(productIds: [SKProduct]) {
|
||||
guard let payTemplateModel = self.oldPayTemplateModel else { return }
|
||||
|
||||
var newCoinList: [VPPayTemplateItem] = []
|
||||
var newVipList: [VPPayTemplateItem] = []
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension VPIAPManager {
|
||||
|
@ -162,7 +162,9 @@ class JXIAPManager: NSObject {
|
||||
extension JXIAPManager: SKProductsRequestDelegate {
|
||||
func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
|
||||
if self.operationType == .request {
|
||||
self.delegate?.jx_iapPayGotProducts?(productIds: response.products)
|
||||
DispatchQueue.main.async {
|
||||
self.delegate?.jx_iapPayGotProducts?(productIds: response.products)
|
||||
}
|
||||
self.operationType = .idle
|
||||
} else if self.operationType == .buy {
|
||||
|
||||
|
@ -17,3 +17,5 @@ veloria@test.com
|
||||
Test@168
|
||||
veloria1@test.com
|
||||
Discover2024
|
||||
veloria2@test.com
|
||||
Test@168
|
Loading…
x
Reference in New Issue
Block a user