nnsnodnb / django-ios-storekit

:moneybag: iOS In-App Purchase's receipt validation server plugin for Django
https://pypi.org/project/django-ios-storekit
MIT License
18 stars 2 forks source link

appstore.py:validate() fails on line 37 with sandbox receipts, throws KeyError exception #13

Open Vidder opened 6 years ago

Vidder commented 6 years ago

The KeyError exception is possibly because there is no key called "response" in the response from Apple servers.

def validate(self, receipt, password=None):
    receipt_json = {'receipt-data': receipt}
    if password:
        receipt_json['password'] = password
    api_response = requests.post(self.url, json=receipt_json).json()
    **status = api_response['response']['status']** ...
    if status != api_result_ok:
        error = AppValidationError(api_result_errors.get(status, 'Unknown API status'), api_response)
        raise error
    response = api_response['response']

Line 43 with similar access might also be problematic.

nnsnodnb commented 6 years ago

@Vidder Which did you check with "non-consumption", "consumption" or "subscription"?

Vidder commented 6 years ago

it was a non-consumable subscription.

Vidder commented 6 years ago

You may have reviewed this already but just in case https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html#//apple_ref/doc/uid/TP40010573-CH104-SW4

nnsnodnb commented 6 years ago

@Vidder I'm sorry for the delay in correspondence. I released 1.0.3 . Please update to new version django-ios-storekit with your using package manager.

Vidder commented 6 years ago

Thank you. I will test this out.

Vidder commented 6 years ago

Now it throws the following: Exception Type: DataError at URL Exception Value: (1264, "Out of range value for column 'transaction_id' at row 1")

For what it is worth, this may be because the storekit_inapp table defines transaction_id as int(11). However, the response seems to have a 16-digit transaction id.

Locals on stack are as follows:

cls | <class 'storekit.models.InApp'>

in_app | {'is_trial_period': False, 'original_purchase_date': '2018-05-17 21:49:29 Etc/GMT', 'original_purchase_date_ms': 1526593769000, 'original_purchase_date_pst': '2018-05-17 14:49:29 America/Los_Angeles', 'original_transaction_id': 1000000399635972, 'product_id': 'someproduct', 'purchase_date': '2018-05-17 21:49:27 Etc/GMT', 'purchase_date_ms': 1526593767000, 'purchase_date_pst': '2018-05-17 14:49:27 America/Los_Angeles', 'quantity': 1, 'transaction_id': 1000000399635972} is_save | True json | {'expires_date': '2018-05-17 21:54:27 Etc/GMT', 'expires_date_ms': '1526594067000', 'expires_date_pst': '2018-05-17 14:54:27 America/Los_Angeles', 'is_in_intro_offer_period': 'false', 'is_trial_period': 'false', 'original_purchase_date': '2018-05-17 21:49:29 Etc/GMT', 'original_purchase_date_ms': '1526593769000', 'original_purchase_date_pst': '2018-05-17 14:49:29 America/Los_Angeles', 'original_transaction_id': '1000000399635972', 'product_id': 'someproductid', 'purchase_date': '2018-05-17 21:49:27 Etc/GMT', 'purchase_date_ms': '1526593767000', 'purchase_date_pst': '2018-05-17 14:49:27 America/Los_Angeles', 'quantity': '1', 'transaction_id': '1000000399635972', 'web_order_line_item_id': '1000000033322585'}