def verify_receipt(receipt_data, user=None):
    """
    Returns the receipt data, or raises a ValidationError.
    """
    #data = json.dumps({'receipt-data': '{' + receipt_data + '}'})
    data = '{{\n "receipt-data" : "{}" \n}}'.format(receipt_data)

    def verify(url):
        tries = 3
        for try_ in range(1, tries + 1):
            try:
                req = urllib2.Request(url, data)
                resp = urllib2.urlopen(req, timeout=18) # app timeout is supposed to be 60
                return json.loads(resp.read())
            except (urllib2.URLError, socket_error) as e:
                if try_ == tries:
                    raise e

    cleaned_data = verify(settings.IAP_VERIFICATION_URL)

    # See: http://developer.apple.com/library/ios/#technotes/tn2259/_index.html
    if cleaned_data['status'] == 21007:
        cleaned_data = verify(settings.IAP_VERIFICATION_SANDBOX_URL)

    if cleaned_data['status'] != 0:
        extra = {'status': cleaned_data['status']}
        if user is not None and user.is_authenticated():
            extra['username'] = user.username
            extra['response_from_apple'] = json.dumps(cleaned_data)
        client.captureMessage('IAP receipt validation failed', extra=extra)
        raise ValidationError("Your purchase went through, but there was an error processing it. Please contact support: [email protected]")

    return cleaned_data['receipt']
Beispiel #2
0
def _canvas_api(endpoint, data):
    data = json.dumps(data)
    headers = {
        'Authorization': 'Basic ZHJhd3F1ZXN0OkRUZ3JnWTJT', # DTgrgY2S
        'Content-Type': 'application/json',
        'Content-Length': len(data),
        'X_REQUESTED_WITH': 'XMLHttpRequest',
        'ACCEPT': '*/*',
    }
    req = urllib2.Request('https://example.com/api' + endpoint, data, headers)
    f = urllib2.urlopen(req, timeout=_CANVAS_TIMEOUT)
    resp = json.loads(f.read())
    f.close()
    return resp
Beispiel #3
0
def verify_receipt(receipt_data, user=None):
    """
    Returns the receipt data, or raises a ValidationError.
    """
    #data = json.dumps({'receipt-data': '{' + receipt_data + '}'})
    data = '{{\n "receipt-data" : "{}" \n}}'.format(receipt_data)

    def verify(url):
        tries = 3
        for try_ in range(1, tries + 1):
            try:
                req = urllib2.Request(url, data)
                resp = urllib2.urlopen(
                    req, timeout=18)  # app timeout is supposed to be 60
                return json.loads(resp.read())
            except (urllib2.URLError, socket_error) as e:
                if try_ == tries:
                    raise e

    cleaned_data = verify(settings.IAP_VERIFICATION_URL)

    # See: http://developer.apple.com/library/ios/#technotes/tn2259/_index.html
    if cleaned_data['status'] == 21007:
        cleaned_data = verify(settings.IAP_VERIFICATION_SANDBOX_URL)

    if cleaned_data['status'] != 0:
        extra = {'status': cleaned_data['status']}
        if user is not None and user.is_authenticated():
            extra['username'] = user.username
            extra['response_from_apple'] = json.dumps(cleaned_data)
        client.captureMessage('IAP receipt validation failed', extra=extra)
        raise ValidationError(
            "Your purchase went through, but there was an error processing it. Please contact support: [email protected]"
        )

    return cleaned_data['receipt']
 def test_playback_data(self):
     data = json.dumps({'foo': 'bar'})
     self._check(create_quest_comment(playback_data=data).id, data)
Beispiel #5
0
 def set_json_data(self, data):
     self.blob = json.dumps(data)
Beispiel #6
0
 def create_with_json(cls, comment, json_data):
     return cls.objects.create(comment=comment, blob=json.dumps(json_data))
Beispiel #7
0
 def set_json_data(self, data):
     self.blob = json.dumps(data)
Beispiel #8
0
 def create_with_json(cls, comment, json_data):
     return cls.objects.create(comment=comment, blob=json.dumps(json_data))
 def test_playback_data(self):
     data = json.dumps({'foo': 'bar'})
     self._check(create_quest_comment(playback_data=data).id, data)