From 5736a9b8de74d80ebf08ebbf0357ff8a33f3010f Mon Sep 17 00:00:00 2001 From: Jawad Khan Date: Tue, 6 Aug 2024 12:57:08 +0500 Subject: [PATCH] fix: Added ios inapp price check --- .../extensions/iap/api/v1/tests/test_utils.py | 16 ++++++++++++---- ecommerce/extensions/iap/api/v1/utils.py | 3 +++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/ecommerce/extensions/iap/api/v1/tests/test_utils.py b/ecommerce/extensions/iap/api/v1/tests/test_utils.py index 1433fe948f3..c7c1ab6de93 100644 --- a/ecommerce/extensions/iap/api/v1/tests/test_utils.py +++ b/ecommerce/extensions/iap/api/v1/tests/test_utils.py @@ -73,17 +73,25 @@ def test_create_ios_product(self, _, __, ___, ____, _____, ______, _______): course = { 'key': 'test', 'name': 'test', - 'price': '123' + 'price': 123 } error_msg = create_ios_product(course, self.ios_seat, self.configuration) self.assertEqual(error_msg, None) - # @mock.patch('ecommerce.extensions.iap.api.v1.utils.create_inapp_purchase') + def test_error_on_ios_product_price_threshhold(self, _,): + course = { + 'key': 'test', + 'name': 'test', + 'price': 1001 + } + error_msg = create_ios_product(course, self.ios_seat, self.configuration) + self.assertEqual(error_msg, 'Error: Appstore does not allow price> 1000') + def test_create_ios_product_with_failure(self, _): course = { 'key': 'test', 'name': 'test', - 'price': '123' + 'price': 123 } error_msg = create_ios_product(course, self.ios_seat, self.configuration) expected_msg = "[Couldn't create inapp purchase id] for course [{}] with sku [{}]".format( @@ -110,7 +118,7 @@ def test_create_inapp_purchase(self, _): course = { 'key': 'test', 'name': 'test', - 'price': '123' + 'price': 123 } headers = get_auth_headers(self.configuration) create_inapp_purchase(course, 'test.sku', '123', headers) diff --git a/ecommerce/extensions/iap/api/v1/utils.py b/ecommerce/extensions/iap/api/v1/utils.py index 1f8929f02be..100233bce4e 100644 --- a/ecommerce/extensions/iap/api/v1/utils.py +++ b/ecommerce/extensions/iap/api/v1/utils.py @@ -34,6 +34,9 @@ def create_ios_product(course, ios_product, configuration): Create in app ios product on connect store. return error message in case of failure. """ + if course['price'] > 1000: + return 'Error: Appstore does not allow price> 1000' + headers = get_auth_headers(configuration) try: in_app_purchase_id = get_or_create_inapp_purchase(ios_product, course, configuration, headers)