dotpot/InAppPy

[BUG] Async example wrong

Kylmakalle opened this issue · 1 comments

Seems like session for validator creates only on __aenter__

File "inapppy/asyncio/appstore.py", line 47, in validate
    api_response = await self.post_json(receipt_json)
  File "inapppy/asyncio/appstore.py", line 30, in post_json
    async with self._session.post(
AttributeError: 'NoneType' object has no attribute 'post'

Working example for me

async with validator:
    validation_result = await validator.validate(...)
gfx commented

Same here. I made a test code:

class AppStoreClient:
    async def verify_receipt(self, receipt_data: str) -> bool:
        async with AppStoreValidator(
            bundle_id=bundle_id,
            sandbox=sandbox,
        ) as validator:
            try:
                validation_result = await validator.validate(receipt=receipt_data)
                return validation_result.is_valid
            except InAppPyValidationError as ex:
                print(f"Validation error occurred: {ex.raw_response}", file=sys.stderr)
                return False

It doesn't make a request to the Apple server at all. Just because __aenter__ does not return self.