Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Fix: Support create-mobile-skus to run again if failed #4129

Merged
merged 3 commits into from
Feb 15, 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
9 changes: 5 additions & 4 deletions ecommerce/extensions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,12 @@
partner_short_code = self.context['request'].site.siteconfiguration.partner.short_code
configuration = settings.PAYMENT_PROCESSOR_CONFIG[partner_short_code.lower()][IOSIAP.NAME.lower()]
headers = get_auth_headers(configuration)
try:
ios_product_id = mobile_seat.attr.app_store_id
apply_price_of_inapp_purchase(price, ios_product_id, headers)
except AttributeError:
ios_product_id = getattr(mobile_seat.attr, 'app_store_id', None)
if not ios_product_id:
logger.error("app_store_id not associated with [%s]", mobile_seat.course)
return

apply_price_of_inapp_purchase(price, ios_product_id, headers)

Check warning on line 869 in ecommerce/extensions/api/serializers.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/api/serializers.py#L869

Added line #L869 was not covered by tests

def get_partner(self):
"""Validate partner"""
Expand Down
20 changes: 17 additions & 3 deletions ecommerce/extensions/iap/api/v1/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
"""
headers = get_auth_headers(configuration)
try:
in_app_purchase_id = create_inapp_purchase(course, ios_product.partner_sku, configuration['apple_id'], headers)
ios_product.product.attr.app_store_id = in_app_purchase_id
ios_product.product.save()
in_app_purchase_id = get_or_create_inapp_purchase(ios_product, course, configuration, headers)

Check warning on line 39 in ecommerce/extensions/iap/api/v1/utils.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/iap/api/v1/utils.py#L39

Added line #L39 was not covered by tests
localize_inapp_purchase(in_app_purchase_id, headers)
apply_price_of_inapp_purchase(course['price'], in_app_purchase_id, headers)
upload_screenshot_of_inapp_purchase(in_app_purchase_id, headers)
Expand All @@ -51,6 +49,22 @@
return error_msg


def get_or_create_inapp_purchase(ios_stock_record, course, configuration, headers):
"""
Returns inapp_purchase_id from product attr
If not present there create a product on ios store and return its inapp_purchase_id
"""

in_app_purchase_id = getattr(ios_stock_record.product.attr, 'app_store_id', '')
if not in_app_purchase_id:
in_app_purchase_id = create_inapp_purchase(course, ios_stock_record.partner_sku,

Check warning on line 60 in ecommerce/extensions/iap/api/v1/utils.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/iap/api/v1/utils.py#L58-L60

Added lines #L58 - L60 were not covered by tests
configuration['apple_id'], headers)
ios_stock_record.product.attr.app_store_id = in_app_purchase_id
ios_stock_record.product.save()

Check warning on line 63 in ecommerce/extensions/iap/api/v1/utils.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/iap/api/v1/utils.py#L62-L63

Added lines #L62 - L63 were not covered by tests

return in_app_purchase_id

Check warning on line 65 in ecommerce/extensions/iap/api/v1/utils.py

View check run for this annotation

Codecov / codecov/patch

ecommerce/extensions/iap/api/v1/utils.py#L65

Added line #L65 was not covered by tests


def request_connect_store(url, headers, data=None, method="post"):
""" Request the given endpoint with multiple tries and backoff time """
# Adding backoff and retries because of following two reasons
Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/iap/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def post(self, request):
product_class__name=SEAT_PRODUCT_CLASS_NAME,
children__expires__gt=now(),
course=course_run,
)
).distinct()

if not parent_product.exists():
failed_course_runs.append(course_run_key)
Expand Down
4 changes: 3 additions & 1 deletion ecommerce/extensions/iap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def create_mobile_seat(sku_prefix, existing_web_seat):
if 'ios' in sku_prefix:
# We need this attribute defined for ios products
# Actual values will be assigned when we create product on appstore
new_mobile_seat.attr.app_store_id = ''
app_store_id = getattr(new_mobile_seat.attr, 'app_store_id', None)
if not app_store_id:
new_mobile_seat.attr.app_store_id = ''

new_mobile_seat.attr.save()

Expand Down
Loading