处理storkit2
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
//#import "KBLoginSheetViewController.h"
|
||||
#import "KBBizCode.h"
|
||||
|
||||
NSString * const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurchaseNotification";
|
||||
NSNotificationName const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurchaseNotification";
|
||||
@interface IAPVerifyTransactionObj ()
|
||||
@property (nonatomic, strong) PayVM *payVM;
|
||||
@end
|
||||
@@ -23,6 +23,29 @@ NSString * const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurcha
|
||||
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);
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - FGIAPVerifyTransaction
|
||||
|
||||
- (void)pushSuccessTradeReultToServer:(NSString *)receipt
|
||||
@@ -40,34 +63,23 @@ NSString * const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurcha
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
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) {
|
||||
[self verifyReceipt:receipt completion:^(BOOL success, NSString * _Nullable message, NSInteger statusCode) {
|
||||
__strong typeof(weakSelf) self = weakSelf;
|
||||
(void)self;
|
||||
if (success) {
|
||||
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
||||
[KBHUD showInfo:@"Success"];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:KBIAPDidCompletePurchaseNotification object:nil];
|
||||
if (handler) handler(KBLocalized(@"Success"), nil);
|
||||
}else if(sta == KBBizCodeReceiptError){
|
||||
} else if (statusCode == KBBizCodeReceiptError) {
|
||||
[KBHUD dismiss];
|
||||
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
||||
}else {
|
||||
[KBHUD showError:@"Failed"];
|
||||
if (handler) handler(KBLocalized(@"Failed"), nil);
|
||||
} else {
|
||||
[KBHUD showError:message ?: KBLocalized(@"Failed")];
|
||||
if (handler) handler(message ?: KBLocalized(@"Failed"), nil);
|
||||
}
|
||||
(void)weakSelf; // keep self during block life if needed
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user