35 lines
1.1 KiB
Swift
35 lines
1.1 KiB
Swift
|
|
//
|
||
|
|
// CoinsRechargeViewModel.swift
|
||
|
|
// Crush
|
||
|
|
//
|
||
|
|
// Created by Leon on 2025/9/16.
|
||
|
|
//
|
||
|
|
|
||
|
|
class CoinsRechargeViewModel{
|
||
|
|
|
||
|
|
|
||
|
|
func purchase(product: IAPProducts, completion: ((Bool, String?)->Void)? = nil){
|
||
|
|
guard let productId = product.productId else {return}
|
||
|
|
if let tradeId = product.tradeId, tradeId.count > 0 {
|
||
|
|
IAPCore.shared.addPayProductId(productId: productId, tradeId: tradeId)
|
||
|
|
return
|
||
|
|
}
|
||
|
|
|
||
|
|
var params = [String:Any]()
|
||
|
|
params.updateValue(productId, forKey: "productId")
|
||
|
|
params.updateValue("1", forKey: "version")
|
||
|
|
// if let chargeAmount = product.chargeAmount{
|
||
|
|
// params.updateValue(chargeAmount, forKey: "chargeAmount")
|
||
|
|
// }
|
||
|
|
|
||
|
|
WalletProvider.request(.tradePrecharge(params: params), modelType: CoinRechargePreOrderResponse.self) { result in
|
||
|
|
switch result {
|
||
|
|
case .success(let model):
|
||
|
|
completion?(true, model?.tradeNo)
|
||
|
|
case .failure:
|
||
|
|
completion?(false, nil)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|