From 271091f85129a9e29a3fffaddf8eaa29a6ffd1a4 Mon Sep 17 00:00:00 2001 From: denysdanyliukboosters Date: Wed, 25 Oct 2023 15:26:44 +0300 Subject: [PATCH] Release: 2.0.4 --- Sources/PandaSDK/Models/PandaPayload.swift | 3 +++ Sources/PandaSDK/Views/WebViewController.swift | 15 +++++++++++++-- Sources/PandaSDK/Views/WebViewModel.swift | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Sources/PandaSDK/Models/PandaPayload.swift b/Sources/PandaSDK/Models/PandaPayload.swift index 88401c7..0cec64d 100644 --- a/Sources/PandaSDK/Models/PandaPayload.swift +++ b/Sources/PandaSDK/Models/PandaPayload.swift @@ -14,6 +14,7 @@ public struct PandaPayload { internal let pageLoadingTimeout: TimeInterval internal let htmlDownloadTimeout: TimeInterval? internal let data: [String: Any]? + internal let autoDismissible: Bool public init( shouldShowDefaultScreen: Bool = true, @@ -21,6 +22,7 @@ public struct PandaPayload { entryPoint: String? = nil, pageLoadingTimeout: TimeInterval = 3.0, htmlDownloadTimeout: TimeInterval? = nil, + autoDismissible: Bool = true, targetLanguage: String? = nil, fromLanguage: String? = nil, strings: [[String: String]]? = nil, @@ -36,6 +38,7 @@ public struct PandaPayload { self.entryPoint = entryPoint self.pageLoadingTimeout = pageLoadingTimeout self.htmlDownloadTimeout = htmlDownloadTimeout + self.autoDismissible = autoDismissible var data: [String: Any] = [:] if let targetLanguage = targetLanguage { data["target_language"] = targetLanguage diff --git a/Sources/PandaSDK/Views/WebViewController.swift b/Sources/PandaSDK/Views/WebViewController.swift index a746d82..e060a1d 100644 --- a/Sources/PandaSDK/Views/WebViewController.swift +++ b/Sources/PandaSDK/Views/WebViewController.swift @@ -387,6 +387,7 @@ final class WebViewController: UIViewController, WKScriptMessageHandler { } private func bindVM(_ viewModel: WebViewModel) { + isAutoDismissable = viewModel.payload?.autoDismissible ?? isAutoDismissable viewModel.onScreenDataUpdate = { [weak self] in self?.loadPage(html: $0.html) } @@ -620,9 +621,19 @@ extension WebViewController { func sendLocalizedPrices(products: [Product]) { let localizedPricesToSend = products.map { product -> [String : Any] in var localizedPriceInfo = [String: Any]() - var value = product.price + var price: Decimal + if let introductoryOffer = product.subscription?.introductoryOffer { + switch introductoryOffer.paymentMode { + case .payAsYouGo, .payUpFront: + price = introductoryOffer.price + default: + price = product.price + } + } else { + price = product.price + } var roundedValue = Decimal() - NSDecimalRound(&roundedValue, &value, 2, .bankers) + NSDecimalRound(&roundedValue, &price, 2, .bankers) let micros = roundedValue * Decimal(1_000_000) localizedPriceInfo["productId"] = product.id localizedPriceInfo["priceAmountMicros"] = micros diff --git a/Sources/PandaSDK/Views/WebViewModel.swift b/Sources/PandaSDK/Views/WebViewModel.swift index ce7abfd..e0e57df 100644 --- a/Sources/PandaSDK/Views/WebViewModel.swift +++ b/Sources/PandaSDK/Views/WebViewModel.swift @@ -10,6 +10,7 @@ import Foundation import StoreKit protocol WebViewModelProtocol { + var payload: PandaPayload? { get } var onPurchase: ((_ product: String?, _ source: String, _ viewController: WebViewController, _ screenId: String, _ screenName: String, _ course: String?) -> Void)! { get set } var onApplePayPurchase: ((_ pandaID: String?, _ source: String, _ screenId: String, _ screenName: String, _ viewController: WebViewController) -> Void)! { get set } var onViewWillAppear: ((_ screenId: String?, _ screenName: String?) -> Void)? { get set }