Commit e97306ac authored by Mazy's avatar Mazy

add login if pay success in tourest

parent 1018359e
...@@ -156,13 +156,20 @@ ...@@ -156,13 +156,20 @@
if (self.payFinish) { if (self.payFinish) {
self.payFinish(); self.payFinish();
} }
[[ZJUserInfoManager shared] updataUserInfo:^(ZJMineUserInfoModel * model) {
if (self.presentingViewController){
[self dismissViewControllerAnimated:YES completion:nil];
return;
}
[self.navigationController popViewControllerAnimated:YES];
} failure:^(id error) {
if (self.presentingViewController){
[self dismissViewControllerAnimated:YES completion:nil];
return;
}
[self.navigationController popViewControllerAnimated:YES];
}];
if (self.presentingViewController){
[self dismissViewControllerAnimated:YES completion:nil];
return;
}
[self.navigationController popViewControllerAnimated:YES];
} faliure:^{ } faliure:^{
[MBProgressHUD hideHUD]; [MBProgressHUD hideHUD];
...@@ -179,11 +186,19 @@ ...@@ -179,11 +186,19 @@
- (IBAction)restoreBtnClick:(id)sender{ - (IBAction)restoreBtnClick:(id)sender{
[ZTPurchaseManager restorePurchasesWithView:self.view success:^{ [ZTPurchaseManager restorePurchasesWithView:self.view success:^{
if (self.presentingViewController) { [[ZJUserInfoManager shared] updataUserInfo:^(ZJMineUserInfoModel * model) {
[self dismissViewControllerAnimated:YES completion:nil]; if (self.presentingViewController){
return; [self dismissViewControllerAnimated:YES completion:nil];
} return;
[self.navigationController popViewControllerAnimated:YES]; }
[self.navigationController popViewControllerAnimated:YES];
} failure:^(id error) {
if (self.presentingViewController){
[self dismissViewControllerAnimated:YES completion:nil];
return;
}
[self.navigationController popViewControllerAnimated:YES];
}];
}]; }];
} }
......
...@@ -40,30 +40,45 @@ class ZTPurchaseManager: NSObject { ...@@ -40,30 +40,45 @@ class ZTPurchaseManager: NSObject {
print("productId transactionId receiptData: \(dict)") print("productId transactionId receiptData: \(dict)")
// TODO: 服务器验证 // TODO: 服务器验证
let innerHud = MBProgressHUD.showAdded(to: inView, animated: true) let innerHud = MBProgressHUD.showAdded(to: inView, animated: true)
TQNetworkTools.shared().post(withBodyAction: iosIPAVerifyReceipt, parameters: [:], body: dict, success: { (data) in TQNetworkTools.shared().post(withBodyAction: iosIPAVerifyReceipt, parameters: [:], body: dict, success: { (data) in
innerHud.hide(animated: true) innerHud.hide(animated: true)
print("success----iosIPAVerifyReceipt-----------------\(data)------") print("success----iosIPAVerifyReceipt-----------------\(data)------")
if let dict = data as? [String:Any] { if let dict = data as? [String:Any] {
if let result = dict["result"] as? [String:Any] { if let result = dict["result"] as? [String:Any] {
if let data = result["data"] as? [String:Any] { if let data = result["data"] as? [String:Any] {
print("SwiftyStoreKit---1-\(data)")
if let status = data["status"] as? Bool { if let status = data["status"] as? Bool {
print("SwiftyStoreKit--2--\(status)")
if status { if status {
print("SwiftyStoreKit--3--\(status)")
if product.needsFinishTransaction { if product.needsFinishTransaction {
SwiftyStoreKit.finishTransaction(product.transaction) SwiftyStoreKit.finishTransaction(product.transaction)
} }
print("Purchase Success: \(product.productId)") print("Purchase Success: \(product.productId)")
success() success()
} else {
MBProgressHUD.showError("未知错误,请联系客服")
} }
}else {
MBProgressHUD.showError("未知错误,请联系客服")
} }
}else {
MBProgressHUD.showError("未知错误,请联系客服")
} }
}else {
MBProgressHUD.showError("未知错误,请联系客服")
} }
}else {
MBProgressHUD.showError("未知错误,请联系客服")
} }
}) { (error) in }) { (error) in
innerHud.hide(animated: true) innerHud.hide(animated: true)
// print("\(error)") print("\(error)")
faliure(); faliure();
} }
} else { } else {
print("Purchase Success: not needsFinishTransaction")
success() success()
} }
case .error(let error): case .error(let error):
...@@ -72,15 +87,19 @@ class ZTPurchaseManager: NSObject { ...@@ -72,15 +87,19 @@ class ZTPurchaseManager: NSObject {
switch error.code { switch error.code {
case .unknown: case .unknown:
print("Unknown error. Please contact support") print("Unknown error. Please contact support")
MBProgressHUD.showError(NSLocalizedString("alert_unfriend_error", comment: ""), to: inView) MBProgressHUD.showError("无法连接到 iTunes Store, 请稍后再试")
case .paymentCancelled:
MBProgressHUD.showError("您已取消购买")
case .paymentInvalid:
MBProgressHUD.showError("无法购买, 请试试其他的")
print("The purchase identifier was invalid")
case .clientInvalid: print("Not allowed to make the payment") case .clientInvalid: print("Not allowed to make the payment")
case .paymentCancelled: break
case .paymentInvalid: print("The purchase identifier was invalid")
MBProgressHUD.showError(NSLocalizedString("The purchase identifier was invalid", comment: ""), to: inView)
case .paymentNotAllowed: print("The device is not allowed to make the payment") case .paymentNotAllowed: print("The device is not allowed to make the payment")
case .storeProductNotAvailable: print("The product is not available in the current storefront") case .storeProductNotAvailable: print("The product is not available in the current storefront")
case .cloudServicePermissionDenied: print("Access to cloud service information is not allowed") case .cloudServicePermissionDenied: print("Access to cloud service information is not allowed")
case .cloudServiceNetworkConnectionFailed: print("Could not connect to the network") case .cloudServiceNetworkConnectionFailed:
MBProgressHUD.showError("无法连接到网络")
print("Could not connect to the network")
case .cloudServiceRevoked: print("User has revoked permission to use this cloud service") case .cloudServiceRevoked: print("User has revoked permission to use this cloud service")
default: print((error as NSError).localizedDescription) default: print((error as NSError).localizedDescription)
} }
...@@ -130,23 +149,67 @@ class ZTPurchaseManager: NSObject { ...@@ -130,23 +149,67 @@ class ZTPurchaseManager: NSObject {
// 恢复购买 // 恢复购买
@objc class func restorePurchases(view:UIView, success: @escaping(()->Void)) { @objc class func restorePurchases(view:UIView, success: @escaping(()->Void)) {
let hud = MBProgressHUD.showAdded(to: view, animated: true) let hud = MBProgressHUD.showAdded(to:view, animated: true)
SwiftyStoreKit.restorePurchases(atomically: true) { results in SwiftyStoreKit.restorePurchases(atomically: true) { results in
hud.hide(animated: true); hud.hide(animated: true);
if results.restoreFailedPurchases.count > 0 { if results.restoreFailedPurchases.count > 0 {
print("Restore Failed: \(results.restoreFailedPurchases)") print("Restore Failed: \(results.restoreFailedPurchases)")
} } else if results.restoredPurchases.count > 0 {
else if results.restoredPurchases.count > 0 {
print("Restore Success: \(results.restoredPurchases)") print("Restore Success: \(results.restoredPurchases)")
if results.restoredPurchases.filter({ $0.needsFinishTransaction }).count <= 0 {
MBProgressHUD.showSuccess(NSLocalizedString("alert_produce_restore_success", comment: ""), to: UIApplication.shared.windows.first) if let product = results.restoredPurchases.last {
success() let receiptData = SwiftyStoreKit.localReceiptData
let receiptString = receiptData?.base64EncodedString(options: []) ?? ""
print("receiptString: \(receiptString)")
let dict = ["productId": product.productId, "transactionId" : (product.transaction.transactionIdentifier ?? ""), "receiptData" : receiptString]
print("productId transactionId receiptData: \(dict)")
// TODO: 服务器验证
let innerHud = MBProgressHUD.showAdded(to:view, animated: true)
TQNetworkTools.shared().post(withBodyAction: iosIPAVerifyReceipt, parameters: [:], body: dict, success: { (data) in
innerHud.hide(animated: true)
print("success----iosIPAVerifyReceipt-----------------\(data)------")
guard let dict = data as? [String:Any], let result = dict["result"] as? [String:Any], let data = result["data"] as? [String:Any] else {
return
}
guard let status = data["status"] as? Bool, status == true else {
return
}
if product.needsFinishTransaction {
SwiftyStoreKit.finishTransaction(product.transaction)
}
print("Purchase Success: \(product.productId)")
success()
}) { (error) in
innerHud.hide(animated: true)
}
} }
}
else { } else {
MBProgressHUD.showError(NSLocalizedString("alert_no_produce_restore", comment: "")) MBProgressHUD.showError("没有商品可恢复")
print("Nothing to Restore") print("Nothing to Restore")
} }
} }
} }
// @objc class func restorePurchases(view:UIView, success: @escaping(()->Void)) {
// let hud = MBProgressHUD.showAdded(to: view, animated: true)
// SwiftyStoreKit.restorePurchases(atomically: true) { results in
// hud.hide(animated: true);
// if results.restoreFailedPurchases.count > 0 {
// print("Restore Failed: \(results.restoreFailedPurchases)")
// }
// else if results.restoredPurchases.count > 0 {
// print("Restore Success: \(results.restoredPurchases)")
// if results.restoredPurchases.filter({ $0.needsFinishTransaction }).count <= 0 {
// MBProgressHUD.showSuccess(NSLocalizedString("alert_produce_restore_success", comment: ""), to: UIApplication.shared.windows.first)
// success()
// }
// }
// else {
// MBProgressHUD.showError(NSLocalizedString("alert_no_produce_restore", comment: ""))
// print("Nothing to Restore")
// }
// }
// }
} }
...@@ -274,7 +274,10 @@ static NSString *ID = @"mineID"; ...@@ -274,7 +274,10 @@ static NSString *ID = @"mineID";
}]; }];
}; };
} else if ([ZJUserInfoManager shared].isLogin) {
[self headerSenderClick];
} }
} }
break; break;
default: default:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment