#Ronit
1 messages · Page 1 of 1 (latest)
how can i stop payment in Terminal.shared.cancelPaymentIntent(paymentIntent) as this code block shows error in cancel payment
error - Could not execute cancelPaymentIntent because the SDK is busy with another command: collectPaymentMethod.
hey there, you can't cancel the payment intent at that point, that seems right
but I was under the impression that collectPaymentMethod was a cancelable
i cannot find cancelable in this documentation
Declaration
- (nullable SCPCancelable *)
collectPaymentMethod:(nonnull SCPPaymentIntent *)paymentIntent
completion:(nonnull SCPPaymentIntentCompletionBlock)completion;func collectPaymentMethod(_ paymentIntent: PaymentIntent, completion: @escaping PaymentIntentCompletionBlock) -> SCPCancelable?
SCPCancelable
See here in our example in the repo: https://github.com/stripe/stripe-terminal-ios/blob/dc2b5982d3778a826d933caaf95e9b1b1983e76d/Example/Example/PaymentViewController.swift#L138
i am getting error in this line else if let intent = canceledPaymentIntent {
cancelEvent.result = .succeeded
cancelEvent.object = .paymentIntent(intent)
}
What error? you should be able to .cancel the returned cancelable
Or is this inside the event handler?
it is inside event handler
collectCancelable?.cancel { cancelError in
var cancelEvent = LogEvent(method: .cancelCollectPaymentMethod)
if let error = cancelError {
cancelEvent.result = .errored
cancelEvent.object = .error(error as NSError)
} else {
cancelEvent.result = .succeeded
cancelEvent.object = .paymentIntent(intent)
}
self.events.append(cancelEvent)
self.cancelPaymentIntent(intent: intent)
}
yes it works i was using something else in self.cancelPaymentIntent(intent: intent)
does can use this code ?
do {
try await DispatchQueue.main.async {
if let cancelable = self.cancelable {
cancelable.cancel()
// Optionally, perform any additional cleanup or handling when canceled
}
}
} catch {
// Handle the error here (if needed)
print("Error canceling payment: (error)")
}
Assuming self.cancelable was from your call to collectPaymentMethod I think that part would be ok, but I'm not an advance ios developer. Not familiar with what you're doing with DispatchQueue for example or if that would affect how this works