Git Product home page Git Product logo

iap-validator's Introduction

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.

iap-validator's People

Contributors

carsonmcdonald avatar mtmcfarl avatar naudo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.