Skip to content

Instantly share code, notes, and snippets.

@cbguder
Created September 23, 2010 21:42
Show Gist options
  • Save cbguder/594427 to your computer and use it in GitHub Desktop.
Save cbguder/594427 to your computer and use it in GitHub Desktop.
Verify in-app purchase receipts
#!/usr/bin/env python
import sys
import json
import base64
import urllib2
liveURL = 'https://buy.itunes.apple.com/verifyReceipt'
sandboxURL = 'https://sandbox.itunes.apple.com/verifyReceipt'
URL = sandboxURL
def main():
if len(sys.argv) < 2:
print 'USAGE: verifyReceipt RECEIPT'
sys.exit()
with open(sys.argv[1]) as f:
verifyReceipt(f.read())
def verifyReceipt(receipt):
receiptData = base64.b64encode(receipt)
jsonData = json.dumps({'receipt-data': receiptData})
s = urllib2.urlopen(URL, jsonData)
responseData = s.read()
s.close()
responseJSON = json.loads(responseData)
print json.dumps(responseJSON, sort_keys=True, indent=4)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment