From c2c4cb96ef0754a967e1098cfd47eb14755cd9fd Mon Sep 17 00:00:00 2001 From: Saeed Bashir Date: Wed, 5 Jul 2023 13:20:23 +0500 Subject: [PATCH] chore: incorporate changes of course price and currency code for execute api in app_nav (#1768) --- Source/CourseDashboardAccessErrorView.swift | 22 +++++++++++-------- Source/NewCourseDashboardViewController.swift | 8 +++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Source/CourseDashboardAccessErrorView.swift b/Source/CourseDashboardAccessErrorView.swift index 3d68f9934..aacded5b5 100644 --- a/Source/CourseDashboardAccessErrorView.swift +++ b/Source/CourseDashboardAccessErrorView.swift @@ -10,7 +10,7 @@ import Foundation protocol CourseDashboardAccessErrorViewDelegate: AnyObject { func findCourseAction() - func upgradeCourseAction(course: OEXCourse, price: String?, completion: @escaping ((Bool)->())) + func upgradeCourseAction(course: OEXCourse, coursePrice: String, price: NSDecimalNumber?, currencyCode: String?, completion: @escaping ((Bool)->())) func coursePrice(cell: CourseDashboardAccessErrorView, price: String?, elapsedTime: Int) } @@ -27,8 +27,8 @@ class CourseDashboardAccessErrorView: UIView { private lazy var upgradeButton: CourseUpgradeButtonView = { let upgradeButton = CourseUpgradeButtonView() upgradeButton.tapAction = { [weak self] in - guard let course = self?.course else { return } - self?.delegate?.upgradeCourseAction(course: course, price: self?.coursePrice) { _ in + guard let course = self?.course, let coursePrice = self?.localizedCoursePrice else { return } + self?.delegate?.upgradeCourseAction(course: course, coursePrice: coursePrice, price: self?.price, currencyCode: self?.currencyCode) { _ in self?.upgradeButton.stopAnimating() } } @@ -73,7 +73,9 @@ class CourseDashboardAccessErrorView: UIView { private var course: OEXCourse? private var error: CourseAccessHelper? - var coursePrice: String? + private var localizedCoursePrice: String? + private var price: NSDecimalNumber? + private var currencyCode: String? required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") @@ -222,14 +224,16 @@ class CourseDashboardAccessErrorView: UIView { let startTime = CFAbsoluteTimeGetCurrent() DispatchQueue.main.async { [weak self] in self?.upgradeButton.startShimeringEffect() - PaymentManager.shared.productPrice(courseSku) { [weak self] price in + PaymentManager.shared.fetchPrroduct(courseSku) { [weak self] product in guard let weakSelf = self else { return } - if let price = price { + if let product = product, let coursePrice = product.localizedPrice { let elapsedTime = CFAbsoluteTimeGetCurrent() - startTime - weakSelf.coursePrice = price - weakSelf.delegate?.coursePrice(cell: weakSelf, price: price, elapsedTime: elapsedTime.millisecond) - weakSelf.upgradeButton.setPrice(price) + weakSelf.localizedCoursePrice = coursePrice + weakSelf.price = product.price + weakSelf.currencyCode = product.priceLocale.currencyCode + weakSelf.delegate?.coursePrice(cell: weakSelf, price: coursePrice, elapsedTime: elapsedTime.millisecond) + weakSelf.upgradeButton.setPrice(coursePrice) weakSelf.upgradeButton.stopShimmerEffect() } else { diff --git a/Source/NewCourseDashboardViewController.swift b/Source/NewCourseDashboardViewController.swift index e7fbeee6d..380170902 100644 --- a/Source/NewCourseDashboardViewController.swift +++ b/Source/NewCourseDashboardViewController.swift @@ -411,10 +411,10 @@ extension NewCourseDashboardViewController: CourseDashboardAccessErrorViewDelega } } - func upgradeCourseAction(course: OEXCourse, price: String?, completion: @escaping ((Bool) -> ())) { + func upgradeCourseAction(course: OEXCourse, coursePrice: String, price: NSDecimalNumber?, currencyCode: String?, completion: @escaping ((Bool) -> ())) { let upgradeHandler = CourseUpgradeHandler(for: course, environment: environment) - guard let courseID = course.course_id, let coursePrice = price else { + guard let courseID = course.course_id else { courseUpgradeHelper.handleCourseUpgrade(upgradeHadler: upgradeHandler, state: .error(.generalError, nil)) completion(false) return @@ -422,9 +422,9 @@ extension NewCourseDashboardViewController: CourseDashboardAccessErrorViewDelega environment.analytics.trackUpgradeNow(with: courseID, pacing: pacing, screenName: .courseDashboard, coursePrice: coursePrice) - courseUpgradeHelper.setupHelperData(environment: environment, pacing: pacing, courseID: courseID, coursePrice: coursePrice, screen: .courseDashboard) + courseUpgradeHelper.setupHelperData(environment: environment, pacing: pacing, courseID: courseID, localizedCoursePrice: coursePrice, screen: .courseDashboard) - upgradeHandler.upgradeCourse { [weak self] status in + upgradeHandler.upgradeCourse(price: price, currencyCode: currencyCode) { [weak self] status in guard let weakSelf = self else { return } weakSelf.enableUserInteraction(enable: false)