Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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