| | |
| | | } |
| | | |
| | | @objc func becomeVIPAction(){ |
| | | #if DEBUG |
| | | toPay() |
| | | #else |
| | | ParentVerifiyView.show {[unowned self] in |
| | | guard let userId = UserViewModel.getUserInfo()?.user?.id.string else {alert(msg: "请先登录");return} |
| | | guard let product = products.first else {alert(msg: "获取内购失败");return} |
| | | |
| | | Services.orderStudent(count: 12, price: product.price.doubleValue).subscribe(onNext: {[unowned self] data in |
| | | if let m = data.data{ |
| | | showHUD("正在购买") |
| | | InPurchaseManager.purchaseProduct(ID: ProductMemberID, applicationUsername: userId) {[unowned self] model in |
| | | let transactionIdentifier = model.receipt?.in_app.first?.original_transaction_id ?? "" |
| | | |
| | | hiddenHUD() |
| | | Services.pay(orderId: m.orderId, transactionIdentifier: transactionIdentifier).subscribe(onNext: {[unowned self] data in |
| | | var count = 0 |
| | | showHUD("正在查询支付结果") |
| | | let t = Timer(timeInterval: 2.0, repeats: true) {[unowned self] timer in |
| | | Services.queryOrderState(orderId: m.orderId).subscribe(onNext: {[unowned self]status in |
| | | if status.data == true{ |
| | | alertSuccess(msg: "购买成功") |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) {[unowned self] in |
| | | navigationController?.popViewController() |
| | | NotificationCenter.default.post(name: MeUserInfoUpdate_Noti, object: nil) |
| | | } |
| | | timer.invalidate() |
| | | return |
| | | } |
| | | count += 1 |
| | | if count >= 15{ |
| | | hiddenHUD() |
| | | print("循环结束") |
| | | showHUD("查询结果失败,请联系客服") |
| | | timer.invalidate() |
| | | } |
| | | },onError: {error in |
| | | timer.invalidate() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | t.fire() |
| | | RunLoop.current.add(t, forMode: .common) |
| | | }).disposed(by: disposeBag) |
| | | |
| | | } errorClouse: { error in |
| | | hiddenHUD() |
| | | alert(msg: error.localizedDescription) |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | self.toPay() |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | private func toPay(){ |
| | | guard let userId = UserViewModel.getUserInfo()?.user?.id.string else {alert(msg: "请先登录");return} |
| | | guard let product = products.first else {alert(msg: "获取内购失败");return} |
| | | |
| | | Services.orderStudent(count: 12, price: product.price.doubleValue).subscribe(onNext: {[unowned self] data in |
| | | if let m = data.data{ |
| | | showHUD("正在购买") |
| | | InPurchaseManager.purchaseProduct(ID: ProductMemberID, applicationUsername: userId) {[unowned self] model in |
| | | let transactionIdentifier = model.receipt?.in_app.first?.original_transaction_id ?? "" |
| | | |
| | | hiddenHUD() |
| | | Services.pay(orderId: m.orderId, transactionIdentifier: transactionIdentifier).subscribe(onNext: {[unowned self] data in |
| | | var count = 0 |
| | | showHUD("正在查询支付结果") |
| | | let t = Timer(timeInterval: 2.0, repeats: true) {[unowned self] timer in |
| | | Services.queryOrderState(orderId: m.orderId).subscribe(onNext: {[unowned self]status in |
| | | if status.data == true{ |
| | | alertSuccess(msg: "购买成功") |
| | | DispatchQueue.main.asyncAfter(deadline: .now()+1) {[unowned self] in |
| | | navigationController?.popViewController() |
| | | NotificationCenter.default.post(name: MeUserInfoUpdate_Noti, object: nil) |
| | | } |
| | | timer.invalidate() |
| | | return |
| | | } |
| | | count += 1 |
| | | if count >= 15{ |
| | | hiddenHUD() |
| | | print("循环结束") |
| | | showHUD("查询结果失败,请联系客服") |
| | | timer.invalidate() |
| | | } |
| | | },onError: {error in |
| | | timer.invalidate() |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | t.fire() |
| | | RunLoop.current.add(t, forMode: .common) |
| | | }).disposed(by: disposeBag) |
| | | |
| | | } errorClouse: { error in |
| | | hiddenHUD() |
| | | alert(msg: error.localizedDescription) |
| | | } |
| | | } |
| | | }).disposed(by: disposeBag) |
| | | } |
| | | } |