Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: 2.0.4 #88

Merged
merged 1 commit into from
Oct 25, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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