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 2 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
10 changes: 6 additions & 4 deletions ecommerce/extensions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,11 +861,13 @@ 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
18 changes: 15 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 @@ -50,6 +48,20 @@ def create_ios_product(course, ios_product, configuration):
logger.error(error_msg)
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 """
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