Skip to content

Commit b31a56c

Browse files
Merge pull request #88 from AppSci/release/2.0.4
Release: 2.0.4
2 parents 774def9 + 271091f commit b31a56c

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

Sources/PandaSDK/Models/PandaPayload.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ public struct PandaPayload {
1414
internal let pageLoadingTimeout: TimeInterval
1515
internal let htmlDownloadTimeout: TimeInterval?
1616
internal let data: [String: Any]?
17+
internal let autoDismissible: Bool
1718

1819
public init(
1920
shouldShowDefaultScreen: Bool = true,
2021
screenBackgroundColor: UIColor? = nil,
2122
entryPoint: String? = nil,
2223
pageLoadingTimeout: TimeInterval = 3.0,
2324
htmlDownloadTimeout: TimeInterval? = nil,
25+
autoDismissible: Bool = true,
2426
targetLanguage: String? = nil,
2527
fromLanguage: String? = nil,
2628
strings: [[String: String]]? = nil,
@@ -36,6 +38,7 @@ public struct PandaPayload {
3638
self.entryPoint = entryPoint
3739
self.pageLoadingTimeout = pageLoadingTimeout
3840
self.htmlDownloadTimeout = htmlDownloadTimeout
41+
self.autoDismissible = autoDismissible
3942
var data: [String: Any] = [:]
4043
if let targetLanguage = targetLanguage {
4144
data["target_language"] = targetLanguage

Sources/PandaSDK/Views/WebViewController.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ final class WebViewController: UIViewController, WKScriptMessageHandler {
387387
}
388388

389389
private func bindVM(_ viewModel: WebViewModel) {
390+
isAutoDismissable = viewModel.payload?.autoDismissible ?? isAutoDismissable
390391
viewModel.onScreenDataUpdate = { [weak self] in
391392
self?.loadPage(html: $0.html)
392393
}
@@ -620,9 +621,19 @@ extension WebViewController {
620621
func sendLocalizedPrices(products: [Product]) {
621622
let localizedPricesToSend = products.map { product -> [String : Any] in
622623
var localizedPriceInfo = [String: Any]()
623-
var value = product.price
624+
var price: Decimal
625+
if let introductoryOffer = product.subscription?.introductoryOffer {
626+
switch introductoryOffer.paymentMode {
627+
case .payAsYouGo, .payUpFront:
628+
price = introductoryOffer.price
629+
default:
630+
price = product.price
631+
}
632+
} else {
633+
price = product.price
634+
}
624635
var roundedValue = Decimal()
625-
NSDecimalRound(&roundedValue, &value, 2, .bankers)
636+
NSDecimalRound(&roundedValue, &price, 2, .bankers)
626637
let micros = roundedValue * Decimal(1_000_000)
627638
localizedPriceInfo["productId"] = product.id
628639
localizedPriceInfo["priceAmountMicros"] = micros

Sources/PandaSDK/Views/WebViewModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Foundation
1010
import StoreKit
1111

1212
protocol WebViewModelProtocol {
13+
var payload: PandaPayload? { get }
1314
var onPurchase: ((_ product: String?, _ source: String, _ viewController: WebViewController, _ screenId: String, _ screenName: String, _ course: String?) -> Void)! { get set }
1415
var onApplePayPurchase: ((_ pandaID: String?, _ source: String, _ screenId: String, _ screenName: String, _ viewController: WebViewController) -> Void)! { get set }
1516
var onViewWillAppear: ((_ screenId: String?, _ screenName: String?) -> Void)? { get set }

0 commit comments

Comments
 (0)