diff --git a/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift b/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift index 1fff84f9d..856048db7 100644 --- a/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift +++ b/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift @@ -352,19 +352,42 @@ 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 + + let selectedShippingMethod = try? ApplePayOrderItem( + name: shippingMethodName, + unitAmount: shippingMethod.amount, + quantity: 1, + discountAmount: nil, + taxAmount: nil + ) + + return .init(shippingMethods: [pkShippingMethod], selectedShippingMethodOrderItem: selectedShippingMethod) } // Convert to PKShippingMethods