keeprocking / pyinapp

In-app purchase validation API wrappers
MIT License
32 stars 13 forks source link

Validation Always Fails #6

Closed pgwzzz closed 7 years ago

pgwzzz commented 7 years ago

Hello.

I'm just trying your library to verify receipt that is sent from Android device.

I've set everything and I bought an item with my friends' smartphone.

The problem is that it always fails to validate.

I found that verify() in pkcs1.py always fails because expected != clearsig.

Could you give any advice for this?

Thank you very much.

bundle_id = '...'
api_key = 'PUBLIC_KEY_FROM_GOOGLE_PLAY_DEVELOPER_CONSOLE'
validator = GooglePlayValidator(bundle_id, api_key)

try:
    receipt = {
        'orderId': '...',
        'packageName': '...',
        'productId': '...',
        'purchaseTime': ...,
        'purchaseState': ...,
        'developerPayload': '...',
        'purchaseToken': '...'
    }
    receipt = json.dumps(receipt)    # if not, error during encode()
    signature = 'abcdefg...'
    purchase = validator.validate(receipt, signature)
    print(True)     # never met this
except InAppValidationError:
    print(False)    # always reached here
pgwzzz commented 7 years ago

Oh, I found two problems. The first problem is that I should not treat receipt as a JSON object which nature is UNORDERED. The second problem is that json.dump() inserts white spaces which are not allowed in this case.

The receipt parameter for validator.validate() must follow the below rule.

  1. Use double quotation marks.
  2. No white space at all.

receipt = '{"orderId":"...","packageName":"...","productId":"...","purchaseTime":...,"purchaseState":...,"developerPayload":"...","purchaseToken":"..."}'

Problem solved.