Remove a saved payment method
Delete one of the customer's saved payment methods, and drop it from the checkout's list.
checkout.removeSavedPaymentMethod(_:) deletes one of the methods savedPaymentMethods() lists from the customer's saved methods, and drops it from that list. Use it to let the customer manage what they've saved, at checkout or in a setup session, for example behind an Edit button. The drop-in offers it with allowsRemovingSavedPaymentMethods.
try await checkout.removeSavedPaymentMethod(method)Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
method | PaySavedPaymentMethod | Yes | One of this checkout's savedPaymentMethods(). |
Returns
None. When it returns, Pay.com has deleted the method and it's no longer in savedPaymentMethods(). When it throws, the method stays in the list.
Errors
removeSavedPaymentMethod(_:) throws a PayError when it can't delete the method.
| Error | When |
|---|---|
unsupported | The method isn't one of this checkout's savedPaymentMethods(). Nothing was sent. |
paymentInProgress | A payment, or another removal, is running on this checkout. Nothing was sent. |
sessionExpired | Pay.com returned HTTP 401. The session expired. |
requestRejected | Pay.com refused the removal, for example because the method no longer exists. |
server, network, unexpectedResponse | Pay.com failed, couldn't be reached, or returned a response this SDK version can't read. |
Example
import PayCheckout
import PayCore
import UIKit
extension PayoutMethodViewController {
func confirmRemove(_ method: PaySavedPaymentMethod) {
let alert = UIAlertController(title: "Remove this payment method?", message: nil, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Remove", style: .destructive) { _ in
Task { @MainActor in
do throws(PayError) {
try await self.checkout.removeSavedPaymentMethod(method)
self.reloadRows(self.checkout.savedPaymentMethods())
} catch {
self.showMessage(error.localizedDescription)
}
}
})
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel))
present(alert, animated: true)
}
}Next steps
- Let customers choose a payout method: List the saved methods and use one.
- Present the drop-in: Removing behind Edit, with
allowsRemovingSavedPaymentMethods.
Was this page helpful?