Skip to content

Commit 3573999

Browse files
DulMephistoschirag04
authored andcommitted
Start using Grand Unified Receipt format and remove usage of deprecated methods (chirag04#210)
1 parent ad34d0f commit 3573999

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

InAppUtils/InAppUtils.m

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,24 @@ - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
193193
}
194194

195195
RCT_EXPORT_METHOD(receiptData:(RCTResponseSenderBlock)callback)
196+
{
197+
NSString *receipt = [self grandUnifiedReceipt];
198+
if (receipt == nil) {
199+
callback(@[@"not_available"]);
200+
} else {
201+
callback(@[[NSNull null], receipt]);
202+
}
203+
}
204+
205+
// Fetch Grand Unified Receipt
206+
- (NSString *)grandUnifiedReceipt
196207
{
197208
NSURL *receiptUrl = [[NSBundle mainBundle] appStoreReceiptURL];
198209
NSData *receiptData = [NSData dataWithContentsOfURL:receiptUrl];
199210
if (!receiptData) {
200-
callback(@[@"not_available"]);
211+
return nil;
201212
} else {
202-
callback(@[[NSNull null], [receiptData base64EncodedStringWithOptions:0]]);
213+
return [receiptData base64EncodedStringWithOptions:0];
203214
}
204215
}
205216

@@ -220,7 +231,7 @@ - (void)productsRequest:(SKProductsRequest *)request
220231
@"currencyCode": [item.priceLocale objectForKey:NSLocaleCurrencyCode],
221232
@"priceString": item.priceString,
222233
@"countryCode": [item.priceLocale objectForKey: NSLocaleCountryCode],
223-
@"downloadable": item.downloadable ? @"true" : @"false" ,
234+
@"downloadable": item.isDownloadable ? @"true" : @"false" ,
224235
@"description": item.localizedDescription ? item.localizedDescription : @"",
225236
@"title": item.localizedTitle ? item.localizedTitle : @"",
226237
};
@@ -248,7 +259,7 @@ - (NSDictionary *)getPurchaseData:(SKPaymentTransaction *)transaction {
248259
@"transactionDate": @(transaction.transactionDate.timeIntervalSince1970 * 1000),
249260
@"transactionIdentifier": transaction.transactionIdentifier,
250261
@"productIdentifier": transaction.payment.productIdentifier,
251-
@"transactionReceipt": [[transaction transactionReceipt] base64EncodedStringWithOptions:0]
262+
@"transactionReceipt": [self grandUnifiedReceipt]
252263
}];
253264
// originalTransaction is available for restore purchase and purchase of cancelled/expired subscriptions
254265
SKPaymentTransaction *originalTransaction = transaction.originalTransaction;

0 commit comments

Comments
 (0)