Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display order shippingMethod if there is no checkoutModules #1017

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down