Esempio n. 1
0
def test_create_from_google_play_receipt():
    receipt = {
        'orderId': 1337,
        'productId': 'pew pew',
        'purchaseTime': '01.01.2016 12:00'
    }
    purchase = Purchase.from_google_play_receipt(receipt)

    assert purchase.transaction_id == receipt['orderId']
    assert purchase.product_id == receipt['productId']
    assert purchase.purchased_at == receipt['purchaseTime']
    assert purchase.quantity == 1
Esempio n. 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')
Esempio n. 3
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')
Esempio n. 4
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")