// // IAPVerifyTransactionObj.m // #import "IAPVerifyTransactionObj.h" #import "PayVM.h" #import "KBBizCode.h" NSNotificationName const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurchaseNotification"; @interface IAPVerifyTransactionObj () @property (nonatomic, strong) PayVM *payVM; @end @implementation IAPVerifyTransactionObj - (instancetype)init { if (self = [super init]) { _payVM = [PayVM new]; } return self; } - (void)verifyReceipt:(NSString *)receipt completion:(void (^)(BOOL success, NSString * _Nullable message, NSInteger statusCode))completion { if (![receipt isKindOfClass:NSString.class] || receipt.length == 0) { if (completion) { completion(NO, KBLocalized(@"Receipt missing"), KBBizCodeReceiptError); } return; } NSDictionary *params = @{ @"receipt": receipt ?: @"" }; __weak typeof(self) weakSelf = self; [self.payVM applePayReqWithParams:params needShow:NO completion:^(NSInteger sta, NSString * _Nullable msg) { dispatch_async(dispatch_get_main_queue(), ^{ __strong typeof(weakSelf) self = weakSelf; (void)self; BOOL success = (sta == KBBizCodeSuccess); NSString *tip = msg ?: (success ? KBLocalized(@"Success") : KBLocalized(@"Payment failed")); if (completion) { completion(success, tip, sta); } }); }]; } - (void)verifySignedPayload:(NSString *)payload completion:(void (^)(BOOL success, NSString * _Nullable message, NSInteger statusCode))completion { if (![payload isKindOfClass:NSString.class] || payload.length == 0) { if (completion) { completion(NO, KBLocalized(@"Payload missing"), KBBizCodeReceiptError); } return; } NSDictionary *params = @{ @"signedPayload": payload ?: @"" }; __weak typeof(self) weakSelf = self; [self.payVM applePayReqWithParams:params needShow:NO completion:^(NSInteger sta, NSString * _Nullable msg) { dispatch_async(dispatch_get_main_queue(), ^{ __strong typeof(weakSelf) self = weakSelf; (void)self; BOOL success = (sta == KBBizCodeSuccess); NSString *tip = msg ?: (success ? KBLocalized(@"Success") : KBLocalized(@"Payment failed")); if (completion) { completion(success, tip, sta); } }); }]; } @end