From be5ce79b33db60ead718ea1a78ef2fded4f20380 Mon Sep 17 00:00:00 2001 From: Hugo EXTRAT Date: Thu, 10 Oct 2024 17:21:22 +0200 Subject: [PATCH] feat: display order shippingMethod if there is no checkoutModules --- .../ApplePayTokenizationViewModel.swift | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift b/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift index 1fff84f9d..a5200b376 100644 --- a/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift +++ b/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift @@ -352,19 +352,34 @@ class ApplePayTokenizationViewModel: PaymentMethodTokenizationViewModel { } func getShippingMethodsInfo() -> ShippingMethodsInfo { + var factor: NSDecimalNumber + if AppState.current.currency?.isZeroDecimal == true { + factor = 1 + } else { + factor = 100 + } + guard let options = PrimerAPIConfigurationModule .apiConfiguration? .checkoutModules? .first(where: { $0.type == "SHIPPING"})? .options as? ShippingMethodOptions else { - return .init(shippingMethods: nil, selectedShippingMethodOrderItem: nil) - } - var factor: NSDecimalNumber - if AppState.current.currency?.isZeroDecimal == true { - factor = 1 - } else { - factor = 100 + guard let shippingMethod = PrimerAPIConfigurationModule + .apiConfiguration? + .clientSession?.order?.shippingMethod, + let shippingMethodName = shippingMethod.methodName else { + return .init(shippingMethods: nil, selectedShippingMethodOrderItem: nil) + } + + let pkShippingMethod = PKShippingMethod( + label: shippingMethodName, + amount: NSDecimalNumber(value: shippingMethod.amount).dividing(by: factor) + ) + pkShippingMethod.detail = shippingMethod.methodDescription + pkShippingMethod.identifier = shippingMethod.methodId + + return .init(shippingMethods: [pkShippingMethod], selectedShippingMethodOrderItem: nil) } // Convert to PKShippingMethods