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?

有帮助吗?

解决方案

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'
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top