This is "didSelectShippingContact" function that calls when shipping address updates. I want api call in this function so i can get taxes. But the problem is if i don’t add delay here it is not updating apple pay ui. But i don't know how much delay this API wants. I add constant 5 seconds here. Anyone helps me. Please . Thanks.
func applePayContext(_ context: STPApplePayContext,
didSelectShippingContact contact: PKContact,
handler: @escaping (_ update: PKPaymentRequestShippingContactUpdate) -> Void
){
summery = []
var spmethod : [PKShippingMethod] = []
DispatchQueue.main.asyncAfter(deadline: .now() + 5){ [weak self] in
print(NSDecimalNumber(string: self?.dataService.paymentModel?.totalPrice ?? "0"))
self?.summery =
self?.shippingPriceCalculator(productName: self?.productName ?? "", price: NSDecimalNumber(string: self?.dataService.paymentModel?.totalPrice ?? "0"), shipingPrice: UInt64(self?.dataService.paymentModel?.totalPrice ?? "") ?? 0 , brandName: self?.brandName ?? "", totalTax: NSDecimalNumber(string: self?.dataService.paymentModel?.totalTax ?? "0")) ?? []
handler(PKPaymentRequestShippingContactUpdate(errors: nil, paymentSummaryItems: self?.summery ?? [], shippingMethods: spmethod))
}
spmethod = shippingMethodCalculator()
handler(PKPaymentRequestShippingContactUpdate(errors: nil, paymentSummaryItems: summery, shippingMethods: spmethod))
}