Files
keyboard/keyBoard/Class/Pay/M/IAPVerifyTransactionObj.m
2025-12-05 20:18:18 +08:00

67 lines
1.8 KiB
Objective-C

//
// IAPVerifyTransactionObj.m
//
#import "IAPVerifyTransactionObj.h"
#import "PayVM.h"
#import "KBAuthManager.h"
#import "KBHUD.h"
#import "KBLoginSheetViewController.h"
#import "KBBizCode.h"
@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;
[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];
if (handler) handler(KBLocalized(@"Success"), nil);
} else {
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