Exemple #1
0
    def validate(self, receipt):
        receipt_json = {'receipt-data': receipt}

        try:
            api_response = requests.post(self.url, json=receipt_json).json()
        except (ValueError, RequestException):
            raise InAppValidationError('HTTP error')

        status = api_response['status']
        if status != api_result_ok:
            error = api_result_errors.get(status, InAppValidationError('Unknown API status'))
            raise error

        receipt = api_response['receipt']
        purchases = self._parse_receipt(receipt)
        return purchases
Exemple #2
0
    def validate(self, receipt, signature):
        ok = self._validate_signature(receipt, signature)

        if not ok:
            raise InAppValidationError('Bad signature')

        try:
            receipt_json = json.loads(receipt)

            if receipt_json['packageName'] != self.bundle_id:
                raise InAppValidationError('Bundle id mismatch')

            if receipt_json['purchaseState'] != purchase_state_ok:
                raise InAppValidationError('Item is not purchased')

            return [Purchase.from_google_play_receipt(receipt_json)]
        except (KeyError, ValueError):
            raise InAppValidationError('Bad receipt')
Exemple #3
0
 def _parse_ios7_receipt(self, receipt):
     if self.bundle_id != receipt['bundle_id']:
         raise InAppValidationError('Bundle id mismatch')
     return [Purchase.from_app_store_receipt(r) for r in receipt['in_app']]
Exemple #4
0
from pyinapp.purchase import Purchase
from pyinapp.errors import InAppValidationError
from requests.exceptions import RequestException
import requests

api_result_ok = 0
api_result_errors = {
    21000: InAppValidationError('Bad json'),
    21002: InAppValidationError('Bad data'),
    21003: InAppValidationError('Receipt authentication'),
    21004: InAppValidationError('Shared secret mismatch'),
    21005: InAppValidationError('Server is unavailable'),
    21006: InAppValidationError('Subscription has expired'),
    21007:
    InAppValidationError('Sandbox receipt was sent to the production env'),
    21008:
    InAppValidationError('Production receipt was sent to the sandbox env'),
}


class AppStoreValidator(object):
    def __init__(self, bundle_id, sandbox=False):
        self.bundle_id = bundle_id

        if sandbox:
            self.url = 'https://sandbox.itunes.apple.com/verifyReceipt'
        else:
            self.url = 'https://buy.itunes.apple.com/verifyReceipt'

    def validate(self, receipt, password=None):
        receipt_json = {'receipt-data': receipt, 'password': password}
Exemple #5
0
 def _parse_ios6_receipt(self, receipt):
     if self.bundle_id != receipt['bid']:
         raise InAppValidationError('Bundle id mismatch')
     return Purchase.from_app_store_receipt(receipt)
Exemple #6
0
 def _parse_ios7_receipt(self, receipt, response):
     if self.bundle_id != receipt['bundle_id']:
         error = InAppValidationError('Bundle id mismatch', response)
         raise error
     return [Purchase.from_app_store_receipt(r, response) for r in receipt['in_app']]