// // IAPVerifyTransactionObj.m // #import "IAPVerifyTransactionObj.h" #import "PayVM.h" #import "KBAuthManager.h" #import "KBHUD.h" //#import "KBLoginSheetViewController.h" #import "KBBizCode.h" NSString * const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurchaseNotification"; @interface IAPVerifyTransactionObj () @property (nonatomic, strong) PayVM *payVM; @end @implementation IAPVerifyTransactionObj - (instancetype)init { if (self = [super init]) { _payVM = [PayVM new]; } return self; } #pragma mark - FGIAPVerifyTransaction - (void)pushSuccessTradeReultToServer:(NSString *)receipt transaction:(SKPaymentTransaction *)transaction complete:(FGIAPVerifyTransactionPushCallBack)handler { if (![self checkLogin]) { return; } NSLog(@"receipt = %@", receipt); NSInteger type = 0; #if DEBUG type = 0; #else type = 1; #endif // , @"type": @(type) NSDictionary *params = @{ @"receipt": receipt ?: @""}; __weak typeof(self) weakSelf = self; [KBHUD showWithStatus:@"请稍等..."]; [self.payVM applePayReqWithParams:params needShow:NO completion:^(NSInteger sta, NSString * _Nullable msg) { // [KBHUD dismiss]; // [KBHUD showInfo:(sta == !KBBizCodeSuccess ? KBLocalized(@"Payment failed") : KBLocalized(@"Payment successful"))]; if (sta == KBBizCodeSuccess) { [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; [KBHUD showInfo:@"Success"]; [[NSNotificationCenter defaultCenter] postNotificationName:KBIAPDidCompletePurchaseNotification object:nil]; if (handler) handler(KBLocalized(@"Success"), nil); }else if(sta == KBBizCodeReceiptError){ [[SKPaymentQueue defaultQueue] finishTransaction:transaction]; }else { [KBHUD showError:@"Failed"]; if (handler) handler(KBLocalized(@"Failed"), nil); } (void)weakSelf; // keep self during block life if needed }]; } #pragma mark - Helpers - (BOOL)checkLogin { BOOL loggedIn = [[KBUserSessionManager shared] isLoggedIn]; if (!loggedIn) { [[KBUserSessionManager shared] goLoginVC]; } return YES; } @end