Validate Mac App Store receipt server side
Asked Answered
C

1

6

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?

Cracknel answered 9/4, 2014 at 8:42 Comment(0)
C
3

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'
Cracknel answered 6/5, 2014 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.