2
This commit is contained in:
@@ -32,6 +32,12 @@ NSString * const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurcha
|
||||
|
||||
KBLOG(@"receipt = %@", receipt);
|
||||
KBLOG(@"transactionId = %@, originalId = %@", transaction.transactionIdentifier,transaction.originalTransaction.transactionIdentifier);
|
||||
#if DEBUG
|
||||
// [self kb_debugLogReceipt:receipt transaction:transaction];
|
||||
#endif
|
||||
#if DEBUG
|
||||
// [self kb_debugLogReceipt:receipt transaction:transaction];
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -55,6 +61,7 @@ NSString * const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurcha
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:KBIAPDidCompletePurchaseNotification object:nil];
|
||||
if (handler) handler(KBLocalized(@"Success"), nil);
|
||||
}else if(sta == KBBizCodeReceiptError){
|
||||
[KBHUD dismiss];
|
||||
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
|
||||
}else {
|
||||
[KBHUD showError:@"Failed"];
|
||||
@@ -74,4 +81,68 @@ NSString * const KBIAPDidCompletePurchaseNotification = @"KBIAPDidCompletePurcha
|
||||
return YES;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
- (void)kb_debugLogReceipt:(NSString *)receipt transaction:(SKPaymentTransaction *)transaction {
|
||||
if (![receipt isKindOfClass:[NSString class]] || receipt.length == 0) {
|
||||
KBLOG(@"[IAPVerifyTransactionObj] debug receipt empty");
|
||||
return;
|
||||
}
|
||||
NSURL *url = [NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"];
|
||||
if (!url) { return; }
|
||||
|
||||
NSDictionary *payload = @{ @"receipt-data": receipt, @"exclude-old-transactions": @NO };
|
||||
NSError *jsonError = nil;
|
||||
NSData *body = [NSJSONSerialization dataWithJSONObject:payload options:0 error:&jsonError];
|
||||
if (jsonError || !body) {
|
||||
KBLOG(@"[IAPVerifyTransactionObj] debug receipt json error: %@", jsonError);
|
||||
return;
|
||||
}
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
|
||||
request.HTTPMethod = @"POST";
|
||||
request.HTTPBody = body;
|
||||
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
|
||||
request.timeoutInterval = 30;
|
||||
|
||||
NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
|
||||
if (error) {
|
||||
KBLOG(@"[IAPVerifyTransactionObj] debug receipt request error: %@", error);
|
||||
return;
|
||||
}
|
||||
if (data.length == 0) {
|
||||
KBLOG(@"[IAPVerifyTransactionObj] debug receipt empty response");
|
||||
return;
|
||||
}
|
||||
|
||||
NSError *parseError = nil;
|
||||
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
|
||||
if (!json || parseError) {
|
||||
KBLOG(@"[IAPVerifyTransactionObj] debug receipt parse error: %@", parseError);
|
||||
return;
|
||||
}
|
||||
|
||||
NSNumber *status = json[@"status"];
|
||||
KBLOG(@"[IAPVerifyTransactionObj] receipt status: %@, env transaction: %@ / %@", status, transaction.transactionIdentifier, transaction.originalTransaction.transactionIdentifier);
|
||||
|
||||
void (^logEntries)(NSArray *entries, NSString *label) = ^(NSArray *entries, NSString *label) {
|
||||
for (NSDictionary *item in entries) {
|
||||
KBLOG(@"[IAPVerifyTransactionObj][%@] product:%@ transaction:%@ original:%@ purchase_date:%@", label, item[@"product_id"], item[@"transaction_id"], item[@"original_transaction_id"], item[@"purchase_date"]);
|
||||
}
|
||||
};
|
||||
|
||||
NSArray *latestInfos = json[@"latest_receipt_info"];
|
||||
if ([latestInfos isKindOfClass:[NSArray class]] && latestInfos.count > 0) {
|
||||
logEntries(latestInfos, @"latest_receipt_info");
|
||||
}
|
||||
|
||||
NSDictionary *receiptDict = json[@"receipt"];
|
||||
NSArray *inAppInfos = receiptDict[@"in_app"];
|
||||
if ([inAppInfos isKindOfClass:[NSArray class]] && inAppInfos.count > 0) {
|
||||
logEntries(inAppInfos, @"receipt.in_app");
|
||||
}
|
||||
}];
|
||||
[task resume];
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
12
keyBoard/Class/Pay/M/KBPerson.swift
Normal file
12
keyBoard/Class/Pay/M/KBPerson.swift
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// KBPerson.swift
|
||||
// keyBoard
|
||||
//
|
||||
// Created by Mac on 2025/12/15.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class KBPerson: NSObject {
|
||||
|
||||
}
|
||||
4
keyBoard/Class/Pay/M/keyBoard-Bridging-Header.h
Normal file
4
keyBoard/Class/Pay/M/keyBoard-Bridging-Header.h
Normal file
@@ -0,0 +1,4 @@
|
||||
//
|
||||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user