From c2118427cdd0072bb6b2bd3c3d6501dc3c707002 Mon Sep 17 00:00:00 2001 From: jawad khan Date: Mon, 20 May 2024 23:14:11 +0500 Subject: [PATCH] feat: Fix iOS redundant payment error (#4163) LEARNER-9999 --- ecommerce/extensions/iap/api/v1/ios_validator.py | 2 +- ecommerce/extensions/iap/processors/base_iap.py | 2 +- ecommerce/extensions/iap/tests/processors/test_ios_iap.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ecommerce/extensions/iap/api/v1/ios_validator.py b/ecommerce/extensions/iap/api/v1/ios_validator.py index fab0477d092..a091cfa1365 100644 --- a/ecommerce/extensions/iap/api/v1/ios_validator.py +++ b/ecommerce/extensions/iap/api/v1/ios_validator.py @@ -19,7 +19,7 @@ def validate(self, receipt, configuration, basket=None): # pylint: disable=unus try: validation_result = validator.validate( receipt.get('purchase_token', receipt.get('purchaseToken')), - exclude_old_transactions=False # if True, include only the latest renewal transaction + exclude_old_transactions=True # if True, include only the latest renewal transaction ) except InAppPyValidationError as ex: # handle validation error diff --git a/ecommerce/extensions/iap/processors/base_iap.py b/ecommerce/extensions/iap/processors/base_iap.py index 29f125cbcf2..106a881e44e 100644 --- a/ecommerce/extensions/iap/processors/base_iap.py +++ b/ecommerce/extensions/iap/processors/base_iap.py @@ -179,7 +179,7 @@ def parse_ios_response(self, response, product_id): purchases = response['receipt'].get('in_app', []) for purchase in purchases: if purchase['product_id'] == product_id and \ - response['receipt']['receipt_creation_date_ms'] == purchase['purchase_date_ms']: + response['receipt']['original_purchase_date_ms'] == purchase['original_purchase_date_ms']: response['receipt']['in_app'] = [purchase] break diff --git a/ecommerce/extensions/iap/tests/processors/test_ios_iap.py b/ecommerce/extensions/iap/tests/processors/test_ios_iap.py index ba6ff1b85ed..b305b07282e 100644 --- a/ecommerce/extensions/iap/tests/processors/test_ios_iap.py +++ b/ecommerce/extensions/iap/tests/processors/test_ios_iap.py @@ -78,7 +78,7 @@ def setUp(self): 'in_app_ownership_type': 'PURCHASED', 'original_transaction_id': 'old_purchase_id', 'product_id': 'org.edx.mobile.test_product3', - 'purchase_date_ms': '1676562544000', + 'purchase_date_ms': '1676562978000', 'transaction_id': 'old_purchase_id' }, { @@ -86,10 +86,12 @@ def setUp(self): 'original_transaction_id': 'original_test_id', 'product_id': self.product_sku, 'purchase_date_ms': '1676562978000', + 'original_purchase_date_ms': '1676562978005', 'transaction_id': 'test_id' } ], 'receipt_creation_date_ms': '1676562978000', + 'original_purchase_date_ms': '1676562978005' } } self.transaction_id = self.mock_validation_response['receipt']['in_app'][2]['transaction_id']