Files
keyboard/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.m

70 lines
2.4 KiB
Mathematica
Raw Normal View History

2025-11-13 19:20:57 +08:00
//
// IAPVerifyTransactionObj.m
//
#import "IAPVerifyTransactionObj.h"
#import "PayVM.h"
2025-12-03 12:55:51 +08:00
#import "KBBizCode.h"
2025-12-15 15:22:27 +08:00
2025-12-16 13:49:08 +08:00
NSNotificationName const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurchaseNotification";
2025-11-13 19:20:57 +08:00
@interface IAPVerifyTransactionObj ()
@property (nonatomic, strong) PayVM *payVM;
@end
@implementation IAPVerifyTransactionObj
- (instancetype)init {
if (self = [super init]) {
_payVM = [PayVM new];
}
return self;
}
2025-12-16 13:49:08 +08:00
- (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) {
2025-12-16 14:14:49 +08:00
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) {
2025-12-16 13:49:08 +08:00
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);
}
});
}];
}
2025-11-13 19:20:57 +08:00
@end