#ahad-applepay-shipping
1 messages · Page 1 of 1 (latest)
Hi how are you?
Good, let me have a read and see if I understand
Thanks.
sorry waiting on someone on my team to confirm. In the meantime can you tell me more about the delay? Where did you see an issue? do you have a video/gif? Are there docs you referred to?
Yes sure.
oh, the video is not uploading here.
This is "didSelectShippingContact" that triggers when we update the address in the apple pay sheet. My problem is i need to call api when the address change. On the basis of address, we need to update the shipping costs. But if i do this without adding delay then the price not updating. But with delay price is updating.
👋 Hopping in to help!
Hi thanks for saying’s.
Hello! In the code you provided the only place you're calculating the shipping changes is inside the dispatched async code. Can you show the code that doesn't work as expected that does not include the async code at all?
Hello @echo sedge api call is working fine. The problem is apple sheet not changing prices asynchronously. But is i add delay then api calls and sends the response to me. Without delay, it ignores the data.
Right, I understand the issue. The problem is you shared the code with the delay fix. Can you share the code without that fix? The code that doesn't work as expected?
one min.
func applePayContext(_ context: STPApplePayContext,
didSelectShippingContact contact: PKContact,
handler: @escaping (_ update: PKPaymentRequestShippingContactUpdate) -> Void
){
summery = []
var spmethod : [PKShippingMethod] = []
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))
}
Formatted version:
func applePayContext( context: STPApplePayContext,
didSelectShippingContact contact: PKContact,
handler: @escaping ( update: PKPaymentRequestShippingContactUpdate) -> Void
){
summery = []
var spmethod : [PKShippingMethod] = []
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))
}
Why are you calling the handler twice in this code?
And what is the intended behavior of this line? self?.summery =
It seems like that would be a syntax error?
Or is that the first part of the line and it's wrapping strangely?
It seems to be a distinct line.
So has this specific code ever been run?
yes.
And self?.summery = doesn't throw a syntax/build error?
No everything is working fine.
I think if you remove the second one it might work as expected? Hard to say for sure.
Thanks.