Skip to content

Commit

Permalink
feat: display order shippingMethod if there is no checkoutModules
Browse files Browse the repository at this point in the history
  • Loading branch information
huextrat committed Oct 10, 2024
1 parent 1c91ec8 commit be5ce79
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be5ce79

Please sign in to comment.