Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Removed mobile iap depricated code #7

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions ecommerce/extensions/iap/api/v1/google_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/iap/api/v1/ios_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
25 changes: 1 addition & 24 deletions ecommerce/extensions/iap/api/v1/tests/test_google_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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',
Expand All @@ -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)
4 changes: 2 additions & 2 deletions ecommerce/extensions/iap/api/v1/tests/test_ios_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/iap/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/iap/tests/processors/test_ios_iap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
Expand Down
Loading