0.02
No commit activity in last 3 years
No release in over 3 years
This gem will validate base64 encoded receipts from iTunes in app purchases.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

iap-validator can be used to validate base64 encoded iTunes in app purchase receipts.

Getting started

If you haven't read the Apple StoreKit Guide do that first to get an understanding of StoreKit.

Next take a look at this great introduction to in app purchases by Ray Wenderlich.

Once you are able to make purchases you are ready to use this gem. Check out the reference for validating receipts if you want to know more details of how the gem works.

The gem only works with base64 encoded data so you will need to do that first. There are a number of good libraries for doing that in Objective-C: NSDataBase64 or the Google toolbox for mac

Assuming you have read the introduction to in app purchases post above and are using the NSDataBase64 library you would add something like this to the example code to print out a base64 encoded receipt:

- (void)recordTransaction:(SKPaymentTransaction *)transaction
{
  NSLog(@"Test transaction receipt: %@", [transaction.transactionReceipt base64EncodedString]);
}

Once you have your receipt base64 encoded you can verify it with the following code:

require 'iap-validator'

receipt_data = 'PUT THE BASE64 ENCODED RECEIPT HERE'

# Is this a valid receipt?
# in this example, passing true tells IAPValidator to use iTunes Connect in production
if IAPValidator::IAPValidator.valid?(receipt_data, true)
  puts "Receipt is valid"
else
  puts "Receipt is not valid"
end

# You can also get more information about the receipt
# in this example, passing true tells IAPValidator to use iTunes Connect in production
resp = IAPValidator::IAPValidator.validate(receipt_data, true)
puts resp["status"]

In the above example the calls take true as the second argument indicating sandbox use. Without the second argument the calls will default to using the production validation system.

Copyright

Copyright (c) 2011 Carson McDonald. See LICENSE.txt for further details.