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

chore: incorporate changes of course price and currency code for execute api in app_nav #1768

Merged
merged 1 commit into from
Jul 5, 2023
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
22 changes: 13 additions & 9 deletions Source/CourseDashboardAccessErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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()
}
}
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions Source/NewCourseDashboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,20 +411,20 @@ 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
}

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)

Expand Down