Getting the receipt for an in-app purchase

I have added support for the in-app purchase for a subscription to my Mac OS app. I successfully receive the SKPaymentTransaction which is great; however, I don't see how to obtain the receipt for the purchase which I believe would contain the start and end dates for the purchase. How do I get that?

Answered by PBK in 131923022

The receipt is encoded. You must decode it. You can do that yourself (it's complicated) or send it to the Apple servers for decoding. This is all explained here:


https://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/Introduction.html

from:

https://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateLocally.html#//apple_ref/doc/uid/TP40010573-CH1-SW2


When an application is installed from the App Store, it contains an application receipt that is cryptographically signed, ensuring that only Apple can create valid receipts. The receipt is stored inside the application bundle. Call the

appStoreReceiptURL
method of the
NSBundle
class to locate the receipt.

Note: In OS X, if the

appStoreReceiptURL
method is not available (on older systems), you can fall back to a hardcoded path. The receipt’s path is
/Contents/_MASReceipt/receipt
inside the app bundle.

Thanks, I have retrieved the NSData. From reading some documentation on this, it looks like I need a string, and then convert into a JSON object. So far I am unable to get the string. Here's what I have:

NSURL* receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];

NSLog(@"receiptURL: %@", receiptURL);

NSData* receiptURLObject = [NSData dataWithContentsOfURL:receiptURL];

NSString* receiptAsString = [[NSString alloc] initWithData:receiptURLObject encoding:NSUTF8StringEncoding];

NSLog(@"receiptAsString: %@", receiptAsString);

which results in:

receiptURL: Contents/_MASReceipt/receipt -- file:///Users/rickschlueter/Library/Developer/Xcode/DerivedData/Funventory-gkxxajonbpotwngswjacynttksjz/Build/Products/Debug/Goods.app/

receiptAsString: (null)

What I am trying to get to is the ending date for a subscription. I have now gotten the receipt as a string, something like:

MIIZyAYJKoZIhvcNAQcCoIIZuTCCGbUCAQExCzAJBgUrDgMCGgUAMIIJaQYJKoZIhv.....

How do I get the end date for the subscription?

Accepted Answer

The receipt is encoded. You must decode it. You can do that yourself (it's complicated) or send it to the Apple servers for decoding. This is all explained here:


https://developer.apple.com/library/mac/releasenotes/General/ValidateAppStoreReceipt/Introduction.html

I now have the receipts and can examine them. Thank you very much.

Getting the receipt for an in-app purchase
 
 
Q