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
def test_create_from_app_store_receipt(): receipt = { 'transaction_id': 1337, 'product_id': 'pew pew', 'purchase_date': '01.01.2016 12:00', 'quantity': 100500 } purchase = Purchase.from_app_store_receipt(receipt) assert purchase.transaction_id == receipt['transaction_id'] assert purchase.product_id == receipt['product_id'] assert purchase.purchased_at == receipt['purchase_date'] assert purchase.quantity == receipt['quantity']
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')
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')
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")
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']]
def _parse_ios6_receipt(self, receipt): if self.bundle_id != receipt['bid']: raise InAppValidationError('Bundle id mismatch') return Purchase.from_app_store_receipt(receipt)
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']]