Files
keyboard/keyBoard/Class/Pay/VM/PayVM.m

65 lines
2.5 KiB
Mathematica
Raw Normal View History

2025-11-13 19:20:57 +08:00
//
// PayVM.m
//
#import "PayVM.h"
#import "KBNetworkManager.h"
#import "KBAPI.h"
#import "KBHUD.h"
2025-12-03 12:55:51 +08:00
#import "KBBizCode.h"
2025-11-13 19:20:57 +08:00
@implementation PayVM
- (void)applePayReqWithParams:(NSDictionary *)params
needShow:(BOOL)needShow
completion:(KBPayCompletion)completion {
if (needShow) { [KBHUD show]; }
2025-12-05 20:18:18 +08:00
[[KBNetworkManager shared] POST:API_VALIDATE_RECEIPT jsonBody:params headers:nil completion:^(NSDictionary * _Nullable json, NSURLResponse * _Nullable response, NSError * _Nullable error) {
2025-11-13 19:20:57 +08:00
if (needShow) { [KBHUD dismiss]; }
if (error) {
2025-12-03 12:55:51 +08:00
// if (completion) completion(ERROR_CODE, error.localizedDescription ?: KBLocalized(@"Network error"));
2025-11-13 19:20:57 +08:00
return;
}
2025-12-03 12:55:51 +08:00
// NSInteger sta = [self.class extractStatusFromResponseObject:jsonOrData response:response];
// NSString *msg = [self.class extractMessageFromResponseObject:jsonOrData] ?: (sta == KBBizCodeSuccess ? @"OK" : KBLocalized(@"Failed"));
if (completion) completion(KBBizCodeSuccess, @"ok");
2025-11-13 19:20:57 +08:00
}];
}
#pragma mark - Helpers
2025-12-03 12:55:51 +08:00
//+ (NSInteger)extractStatusFromResponseObject:(id)obj response:(NSURLResponse *)resp {
// // JSON code/status/success
// if ([obj isKindOfClass:NSDictionary.class]) {
// NSDictionary *d = (NSDictionary *)obj;
// id code = d[@"code"] ?: d[@"status"] ?: d[@"retcode"];
// if ([code isKindOfClass:NSNumber.class]) {
// return [((NSNumber *)code) integerValue] == 0 ? SUCCESS_CODE : ERROR_CODE;
// }
// if ([code isKindOfClass:NSString.class]) {
// // "0"
// return [((NSString *)code) integerValue] == 0 ? SUCCESS_CODE : ERROR_CODE;
// }
// id success = d[@"success"] ?: d[@"ok"];
// if ([success respondsToSelector:@selector(boolValue)]) {
// return [success boolValue] ? SUCCESS_CODE : ERROR_CODE;
// }
// }
// // HTTP 2xx
// NSInteger http = 0;
// if ([resp isKindOfClass:NSHTTPURLResponse.class]) { http = ((NSHTTPURLResponse *)resp).statusCode; }
// return (http >= 200 && http < 300) ? SUCCESS_CODE : ERROR_CODE;
//}
2025-11-13 19:20:57 +08:00
+ (NSString *)extractMessageFromResponseObject:(id)obj {
if (![obj isKindOfClass:NSDictionary.class]) return nil;
NSDictionary *d = (NSDictionary *)obj;
NSString *msg = d[@"message"] ?: d[@"msg"] ?: d[@"error"];
if (![msg isKindOfClass:NSString.class]) msg = nil;
return msg;
}
@end