Subscription Status Request Not Working.

I have an app that once the user launches the app it checks whether they have an active subscription purchased through in-app purchases to access bonus content. In the development environment it works correctly. However, in production, it does not. It says everyone is subscribed. No one has purchased a subscription yet because the response from Apple or my parsing of the response is making everyone have an active subscription. I thought the standard was to test to see if a user has a subscription because they can cancel it and return to the app. So I'm just checking to see if they have one on launch. Could this be because they may not have any data returned from the receipt server so therefore there is not "status" field? The parsing starts on line 63. Thanks in advance.


-(void)checkInAppPurchaseStatus:(NSURL *)receiptURL withReceipt:(NSData *)receipt completionBlock:(void (^)(BOOL success, BOOL isActive))completionBlock{
    /
    BOOL sandbox = [[receiptURL lastPathComponent] isEqualToString:@"sandboxReceipt"];
    NSURL *storeURL = [NSURL URLWithString:@"https:/
    NSError *error;
   
    /
    if(sandbox){
        /
        storeURL = [NSURL URLWithString:@"https:/
    }
   
    NSLog(@"store url: %@", storeURL.absoluteString);
   
    /
    NSDictionary *jsonParamsDict  = [NSDictionary dictionaryWithObjectsAndKeys:
                                     [receipt base64EncodedStringWithOptions:0], @"receipt-data",
                                     @"mypasswordishere", @"password",
                                     nil];
   
    NSData *requestData = [NSJSONSerialization dataWithJSONObject:jsonParamsDict options:0 error:&error];
    NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
    NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:storeURL];
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:requestData];
    /
   
    /
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
   
    /
    NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        /
        BOOL success = YES;
        BOOL isActive = YES;
        /
       
        /
        [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
       
        /
        NSDictionary *dataSource = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
        NSLog(@"datasource from global check subscription status %@", dataSource);
       
        /
        if(error) {
            /
            success = NO;
            isActive = NO;
           
            /
            [self restAPICallCompletedWithGlobalError:error forCall:@"global check subscription status"];
        }
        else{
            /
            if(!dataSource){
                /
                isActive = NO;
            }
            else{
                /
                NSArray *lastestReceiptArray = [dataSource objectForKey:@"latest_receipt_info"];
                NSDictionary *dictLatestReceiptsInfo = [lastestReceiptArray lastObject];
                NSDateFormatter *formatter = [NSDateFormatter new];
                [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss VV"];
                NSDate *expirationDate = [formatter dateFromString:[dictLatestReceiptsInfo objectForKey:@"expires_date"]];
                NSLog(@"expiration date %@", expirationDate);
               
                /
                if( [[dataSource objectForKey:@"status"] integerValue] == 0){
                    /
                    if([expirationDate timeIntervalSinceNow] < 0.0) {
                        NSLog(@"user subscription has expired");
                        /
                        isActive = NO;
                    }
                    else{
                        NSLog(@"user subscription has not expired");
                        /
                        isActive = YES;
                    }
                }
                else{
                    /
                    isActive = NO;
                }
            }
        }
       
        /
        dispatch_async(dispatch_get_main_queue(), ^{
            /
            completionBlock(success, isActive);
        });
    }];
   
    [postDataTask resume];
}

Accepted Reply

A similar question was asked in the (more appropriate) In App Purchase Forum within the past 24 hours. A coincidence?


Your formulation is better bit it still has the following issue (quoting from the answer there):


"Status==0 means the receipt is a valid receipt not that the receipt contains any particular IAP. In particular, it does not indicate whether the subscription is never been purchased, current, expired, or canceled.

"For iOS 7 style app receipts, the status code is reflects the status of the app receipt as a whole. For example, if you send a valid app receipt that contains an expired subscription, the response is

0
because the receipt as a whole is valid."

https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW2

Replies

A similar question was asked in the (more appropriate) In App Purchase Forum within the past 24 hours. A coincidence?


Your formulation is better bit it still has the following issue (quoting from the answer there):


"Status==0 means the receipt is a valid receipt not that the receipt contains any particular IAP. In particular, it does not indicate whether the subscription is never been purchased, current, expired, or canceled.

"For iOS 7 style app receipts, the status code is reflects the status of the app receipt as a whole. For example, if you send a valid app receipt that contains an expired subscription, the response is

0
because the receipt as a whole is valid."

https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW2

Sorry, I missed the IAP Forum, definitely wasn't me. Thanks for the answer! I thought it was a basic quick check to see if the user was currently subscribed.