@@ -618,34 +618,25 @@ extension WebViewController {
618618 }
619619 }
620620
621- func sendLocalizedPrices( products: [ Product ] ) {
622- let localizedPricesToSend = products. map { product -> [ String : Any ] in
621+ func sendLocalizedPrices( products: [ Product ] ) async {
622+ var localizedPricesToSend : [ [ String : Any ] ] = [ ]
623+ for product in products {
623624 var localizedPriceInfo = [ String: Any] ( )
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- }
625+ var price = await productPrice ( for: product)
635626 var roundedValue = Decimal ( )
636627 NSDecimalRound ( & roundedValue, & price, 2 , . bankers)
637628 let micros = roundedValue * Decimal( 1_000_000 )
638629 localizedPriceInfo [ " productId " ] = product. id
639630 localizedPriceInfo [ " priceAmountMicros " ] = micros
640631 localizedPriceInfo [ " priceCurrencyCode " ] = product. priceFormatStyle. currencyCode
641- return localizedPriceInfo
632+ localizedPricesToSend . append ( localizedPriceInfo)
642633 }
643634
644635 let localizedPricesToSendJSON = localizedPricesToSend. toJSONString ( )
645636 let jsFunction = " pricingLoaded( \( localizedPricesToSendJSON) ) "
646637
647638 DispatchQueue . main. async {
648- self . wv. evaluateJavaScript ( jsFunction) { ( result, error) in
639+ self . wv. evaluateJavaScript ( jsFunction) { result, error in
649640 if let error = error {
650641 pandaLog ( " \( error) " )
651642 }
@@ -655,6 +646,20 @@ extension WebViewController {
655646 }
656647 }
657648 }
649+
650+ private func productPrice( for product: Product ) async -> Decimal {
651+ let subscription = product. subscription
652+ if let subscription, await subscription. isEligibleForIntroOffer, let introductoryOffer = subscription. introductoryOffer {
653+ switch introductoryOffer. paymentMode {
654+ case . payAsYouGo, . payUpFront:
655+ return introductoryOffer. price
656+ default :
657+ return product. price
658+ }
659+ } else {
660+ return product. price
661+ }
662+ }
658663}
659664
660665extension WebViewController {
0 commit comments