Skip to content

Commit

Permalink
Fix: Support create-mobile-skus to run again if failed (openedx-unsup…
Browse files Browse the repository at this point in the history
…ported#4129)

* fix: Support create-mobile-skus to run again if we found an error previously
  • Loading branch information
jawad-khan authored and abdullahwaheed committed Mar 1, 2024
1 parent 21cb144 commit 166c1aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
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 @@ def _update_app_store_product(self, mobile_seat, price):
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)

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 @@ def create_ios_product(course, ios_product, configuration):
"""
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)
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 @@ def create_ios_product(course, ios_product, configuration):
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,
configuration['apple_id'], headers)
ios_stock_record.product.attr.app_store_id = in_app_purchase_id
ios_stock_record.product.save()

return in_app_purchase_id


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

0 comments on commit 166c1aa

Please sign in to comment.