Skip to content

Commit

Permalink
feat: Enable mobile payments for new upcoming courses
Browse files Browse the repository at this point in the history
  • Loading branch information
jawad-khan committed Dec 16, 2024
1 parent 7ba575d commit 670e214
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions ecommerce/extensions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@
)
from ecommerce.extensions.catalogue.utils import attach_vouchers_to_coupon_product
from ecommerce.extensions.checkout.views import ReceiptResponseView
from ecommerce.extensions.iap.api.v1.utils import apply_price_of_inapp_purchase, get_auth_headers
from ecommerce.extensions.iap.api.v1.utils import apply_price_of_inapp_purchase, get_auth_headers, create_ios_product
from ecommerce.extensions.iap.constants import ANDROID_SKU_PREFIX, IOS_SKU_PREFIX
from ecommerce.extensions.iap.processors.ios_iap import IOSIAP
from ecommerce.extensions.iap.utils import create_mobile_seat
from ecommerce.extensions.offer.constants import (
ASSIGN,
AUTOMATIC_EMAIL,
Expand Down Expand Up @@ -827,13 +829,28 @@ def validate_products(self, products):

return products

def _update_mobile_seats(self, course):
def _update_or_create_mobile_seats(self, course):
certificate_type_query = Q(attributes__name='certificate_type',
attribute_values__value_text=CertificateType.VERIFIED)
mobile_query = Q(stockrecords__partner_sku__contains='mobile')
seat_products = course.seat_products
mobile_seats = seat_products.filter(certificate_type_query & mobile_query)
web_seat = seat_products.filter(certificate_type_query & ~mobile_query).first()
if mobile_seats:
self._update_mobile_seats(mobile_seats, web_seat, course)
else:
create_mobile_seat(ANDROID_SKU_PREFIX, web_seat)
ios_seat = create_mobile_seat(IOS_SKU_PREFIX, web_seat)
partner_short_code = self.context['request'].site.siteconfiguration.partner.short_code
configuration = settings.PAYMENT_PROCESSOR_CONFIG[partner_short_code.lower()][IOSIAP.NAME.lower()]
course_data = {
'price': ios_seat.stockrecords.first().price_excl_tax,
'name': course.name,
'key': course.id
}
create_ios_product(course_data, ios_seat, configuration)

def _update_mobile_seats(self, mobile_seats, web_seat, course):
failure_msg = False
try:
for mobile_seat in mobile_seats:
Expand Down Expand Up @@ -927,7 +944,7 @@ def save(self): # pylint: disable=arguments-differ
published = (resp_message is None)

if published:
self._update_mobile_seats(course)
self._update_or_create_mobile_seats(course)

return created, None, None
raise Exception(resp_message)
Expand Down

0 comments on commit 670e214

Please sign in to comment.