Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate Mac App Store receipt server side

I have added IAP to my Mac Appstore application. I am unable to properly validate the receipt server-side. I am reading the receipt using this code:

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];

// This is my own method to convert to base64
NSString *receiptString = [NSData base64forData:receipt];

I am then sending the data to my server which in turn queries https://buy.itunes.apple.com/verifyReceipt to see if the receipt is valid. I always end up with an invalid receipt whatever I'm trying. I have also tried using the gem Venice which has the same issue when I provide it my receipt file as plain text or encoded with base64 command line tool. But at the same time it fails with whichever receipt file I try from all of my apps in /Applications.

Has anyone successfully implemented receipt validation on the Mac Appstore?

like image 277
koopajah Avatar asked Apr 09 '14 08:04

koopajah


1 Answers

After investigating this a lot more I finally found a gem that works with the Mac Appstore receipts: itunes-receipt

require 'itunes/receipt'

# pass Base64 encoded raw receipt data which you received from your app
receipt = Itunes::Receipt.verify! 'ewoJInNpZ25hdHVyZSIgPSAi...'
receipt.product_id     # => 'com.example.products.100gems'
receipt.transaction_id # => '1234567890'
like image 166
koopajah Avatar answered Sep 20 '22 23:09

koopajah