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

74 lines
2.2 KiB
Mathematica
Raw Normal View History

2025-11-13 19:20:57 +08:00
//
// IAPVerifyTransactionObj.m
//
#import "IAPVerifyTransactionObj.h"
#import "PayVM.h"
#import "KBAuthManager.h"
#import "KBHUD.h"
2025-12-08 19:48:13 +08:00
//#import "KBLoginSheetViewController.h"
2025-12-03 12:55:51 +08:00
#import "KBBizCode.h"
2025-12-15 15:22:27 +08:00
NSString * 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;
}
#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
2025-12-05 20:18:18 +08:00
// , @"type": @(type)
NSDictionary *params = @{ @"receipt": receipt ?: @""};
2025-11-13 19:20:57 +08:00
__weak typeof(self) weakSelf = self;
2025-12-15 15:40:25 +08:00
[KBHUD showWithStatus:@"请稍等..."];
2025-11-13 19:20:57 +08:00
[self.payVM applePayReqWithParams:params needShow:NO completion:^(NSInteger sta, NSString * _Nullable msg) {
2025-12-15 15:03:35 +08:00
// [KBHUD dismiss];
2025-12-15 15:22:27 +08:00
// [KBHUD showInfo:(sta == !KBBizCodeSuccess ? KBLocalized(@"Payment failed") : KBLocalized(@"Payment successful"))];
2025-12-03 12:55:51 +08:00
if (sta == KBBizCodeSuccess) {
2025-11-13 19:20:57 +08:00
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
2025-12-15 15:22:27 +08:00
[KBHUD showInfo:@"Success"];
[[NSNotificationCenter defaultCenter] postNotificationName:KBIAPDidCompletePurchaseNotification object:nil];
2025-11-17 20:07:39 +08:00
if (handler) handler(KBLocalized(@"Success"), nil);
2025-12-12 16:09:14 +08:00
}else if(sta == KBBizCodeReceiptError){
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}else {
2025-12-12 14:46:38 +08:00
[KBHUD showError:@"Failed"];
2025-11-17 20:07:39 +08:00
if (handler) handler(KBLocalized(@"Failed"), nil);
2025-11-13 19:20:57 +08:00
}
(void)weakSelf; // keep self during block life if needed
}];
}
#pragma mark - Helpers
- (BOOL)checkLogin {
2025-12-05 20:18:18 +08:00
BOOL loggedIn = [[KBUserSessionManager shared] isLoggedIn];
2025-11-13 19:20:57 +08:00
if (!loggedIn) {
2025-12-05 20:18:18 +08:00
[[KBUserSessionManager shared] goLoginVC];
2025-11-13 19:20:57 +08:00
}
return YES;
}
@end