Skip to content

Commit

Permalink
Release: 2.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
denysdanyliukboosters committed Oct 25, 2023
1 parent 774def9 commit 271091f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Sources/PandaSDK/Models/PandaPayload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ 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,
screenBackgroundColor: UIColor? = nil,
entryPoint: String? = nil,
pageLoadingTimeout: TimeInterval = 3.0,
htmlDownloadTimeout: TimeInterval? = nil,
autoDismissible: Bool = true,
targetLanguage: String? = nil,
fromLanguage: String? = nil,
strings: [[String: String]]? = nil,
Expand All @@ -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
Expand Down
15 changes: 13 additions & 2 deletions Sources/PandaSDK/Views/WebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Sources/PandaSDK/Views/WebViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 271091f

Please sign in to comment.