#ahad-applepay-shipping

1 messages · Page 1 of 1 (latest)

molten basin
#

Hello

opal crystal
#

Hi how are you?

molten basin
#

Good, let me have a read and see if I understand

opal crystal
#

Thanks.

molten basin
#

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?

opal crystal
#

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.

trail moon
#

👋 Hopping in to help!

opal crystal
#

Hi thanks for saying’s.

echo sedge
#

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?

opal crystal
#

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.

echo sedge
#

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?

opal crystal
#

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))
}

echo sedge
#

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))
}
opal crystal
#

thanks.

#

This code not updating.

echo sedge
#

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.

opal crystal
#

Yes i was adding if conditions here.

#

self?.summery is [PKPaymentSummaryItem]

echo sedge
#

So has this specific code ever been run?

opal crystal
#

yes.

echo sedge
#

And self?.summery = doesn't throw a syntax/build error?

opal crystal
#

No everything is working fine.

echo sedge
#

Okay, so what about handler being called twice?

#

Why are you doing that?

opal crystal
#

hmm.

#

let me remove this.

echo sedge
#

I think if you remove the second one it might work as expected? Hard to say for sure.

opal crystal
#

Thanks.