diff --git a/ecommerce/extensions/iap/api/v1/google_validator.py b/ecommerce/extensions/iap/api/v1/google_validator.py index e93fb4a03ec..209d5903565 100644 --- a/ecommerce/extensions/iap/api/v1/google_validator.py +++ b/ecommerce/extensions/iap/api/v1/google_validator.py @@ -13,8 +13,7 @@ def validate(self, receipt, configuration, basket): Accepts receipt, validates that the purchase has already been completed in Google for the mentioned product_id. """ - # purchaseToken will be removed in coming releases in favour of purchase_token - purchase_token = receipt.get('purchase_token', receipt.get('purchaseToken')) + purchase_token = receipt.get('purchase_token') # Mobile assumes one course is purchased at a time product_sku = get_consumable_android_sku(basket.total_excl_tax) verifier = GooglePlayVerifier( @@ -23,20 +22,13 @@ def validate(self, receipt, configuration, basket): ) try: result = self.verify_result(verifier, purchase_token, product_sku) - except errors.GoogleError: - logger.error('Purchase validation failed, Now moving to fallback approach for non consumable skus') + except errors.GoogleError as exc: + logger.error('Purchase validation failed %s', exc) + result = { + 'error': exc.raw_response, + 'message': exc.message + } - try: - # Fallback to the old approach and verify token with partner_sku - # This fallback is temporary until all android products are switched to consumable products. - sku = basket.all_lines().first().stockrecord.partner_sku - result = self.verify_result(verifier, purchase_token, sku) - except errors.GoogleError as exc: - logger.error('Purchase validation failed %s', exc) - result = { - 'error': exc.raw_response, - 'message': exc.message - } return result def verify_result(self, verifier, purchase_token, product_sku): diff --git a/ecommerce/extensions/iap/api/v1/ios_validator.py b/ecommerce/extensions/iap/api/v1/ios_validator.py index a091cfa1365..1c80ad7297f 100644 --- a/ecommerce/extensions/iap/api/v1/ios_validator.py +++ b/ecommerce/extensions/iap/api/v1/ios_validator.py @@ -18,7 +18,7 @@ def validate(self, receipt, configuration, basket=None): # pylint: disable=unus try: validation_result = validator.validate( - receipt.get('purchase_token', receipt.get('purchaseToken')), + receipt.get('purchase_token'), exclude_old_transactions=True # if True, include only the latest renewal transaction ) except InAppPyValidationError as ex: diff --git a/ecommerce/extensions/iap/api/v1/tests/test_google_validator.py b/ecommerce/extensions/iap/api/v1/tests/test_google_validator.py index a73c3eb76f9..91ec6ed9335 100644 --- a/ecommerce/extensions/iap/api/v1/tests/test_google_validator.py +++ b/ecommerce/extensions/iap/api/v1/tests/test_google_validator.py @@ -42,7 +42,7 @@ class GoogleValidatorTests(TestCase): "purchase_token": VALID_PURCHASE_TOKEN, } INVALID_RECEIPT = { - "purchaseToken": INVALID_PURCHASE_TOKEN, + "purchase_token": INVALID_PURCHASE_TOKEN, } CONFIGURATION = { "google_bundle_id": "test.google.bundle.id", @@ -74,11 +74,6 @@ def test_validate_failure(self, mock_google_verifier): with LogCapture(logger_name) as google_validator_log_capture: response = self.validator.validate(self.INVALID_RECEIPT, self.CONFIGURATION, self.basket) google_validator_log_capture.check_present( - ( - logger_name, - 'ERROR', - "Purchase validation failed, Now moving to fallback approach for non consumable skus" - ), ( logger_name, 'ERROR', @@ -89,21 +84,3 @@ def test_validate_failure(self, mock_google_verifier): ) self.assertIn('error', response) self.assertIn('message', response) - - @mock.patch('ecommerce.extensions.iap.api.v1.google_validator.GooglePlayVerifier') - def test_validate_failure_for_consumable_sku(self, mock_google_verifier): - logger_name = 'ecommerce.extensions.iap.api.v1.google_validator' - with mock.patch.object(GooglePlayVerifierProxy, 'verify_with_result', - side_effect=[errors.GoogleError(), GooglePlayVerifierResponse()]), \ - LogCapture(logger_name) as google_validator_log_capture: - mock_google_verifier.return_value = GooglePlayVerifierProxy() - - response = self.validator.validate(self.INVALID_RECEIPT, self.CONFIGURATION, self.basket) - google_validator_log_capture.check_present( - ( - logger_name, - 'ERROR', - "Purchase validation failed, Now moving to fallback approach for non consumable skus" - ), - ) - self.assertEqual(response, self.VALIDATED_RESPONSE) diff --git a/ecommerce/extensions/iap/api/v1/tests/test_ios_validator.py b/ecommerce/extensions/iap/api/v1/tests/test_ios_validator.py index 45cbcf37c04..7d782fb9eb4 100644 --- a/ecommerce/extensions/iap/api/v1/tests/test_ios_validator.py +++ b/ecommerce/extensions/iap/api/v1/tests/test_ios_validator.py @@ -28,10 +28,10 @@ class IOSValidatorTests(TestCase): """ IOS Validator Tests """ VALID_RECEIPT = { - "purchaseToken": VALID_PURCHASE_TOKEN, + "purchase_token": VALID_PURCHASE_TOKEN, } INVALID_RECEIPT = { - "purchaseToken": INVALID_PURCHASE_TOKEN, + "purchase_token": INVALID_PURCHASE_TOKEN, } def setUp(self): diff --git a/ecommerce/extensions/iap/api/v1/tests/test_views.py b/ecommerce/extensions/iap/api/v1/tests/test_views.py index 7db577f6f20..de5d95858e1 100644 --- a/ecommerce/extensions/iap/api/v1/tests/test_views.py +++ b/ecommerce/extensions/iap/api/v1/tests/test_views.py @@ -300,7 +300,7 @@ def setUp(self): self.logger_name = 'ecommerce.extensions.iap.api.v1.views' self.post_data = { - 'purchaseToken': 'inapp:org.edx.mobile:android.test.purchased', + 'purchase_token': 'inapp:org.edx.mobile:android.test.purchased', 'payment_processor': 'android-iap', 'basket_id': self.basket.id } diff --git a/ecommerce/extensions/iap/tests/processors/test_ios_iap.py b/ecommerce/extensions/iap/tests/processors/test_ios_iap.py index 6ad118c021d..6a39ba2ffbf 100644 --- a/ecommerce/extensions/iap/tests/processors/test_ios_iap.py +++ b/ecommerce/extensions/iap/tests/processors/test_ios_iap.py @@ -58,7 +58,7 @@ def setUp(self): ) self.product_sku = self.product.stockrecords.first().partner_sku self.RETURN_DATA = { - 'purchaseToken': 'inapp:test.edx.edx:ios.test.purchased', + 'purchase_token': 'inapp:test.edx.edx:ios.test.purchased', 'price': 40.25, 'currency_code': 'USD', }