From be5ce79b33db60ead718ea1a78ef2fded4f20380 Mon Sep 17 00:00:00 2001 From: Hugo EXTRAT Date: Thu, 10 Oct 2024 17:21:22 +0200 Subject: [PATCH 1/2] 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 From b3a12eb4487269fd184aec4fd4254965d2e6c3ca Mon Sep 17 00:00:00 2001 From: Hugo EXTRAT Date: Thu, 10 Oct 2024 21:07:37 +0200 Subject: [PATCH 2/2] feat: add selectedShippingMethodOrderItem --- .../ApplePayTokenizationViewModel.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift b/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift index a5200b376..856048db7 100644 --- a/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift +++ b/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/ApplePayTokenizationViewModel.swift @@ -378,8 +378,16 @@ class ApplePayTokenizationViewModel: PaymentMethodTokenizationViewModel { ) 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: nil) + return .init(shippingMethods: [pkShippingMethod], selectedShippingMethodOrderItem: selectedShippingMethod) } // Convert to PKShippingMethods