Skip to Content
Docs

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

ParameterTypeRequiredDescription
methodPaySavedPaymentMethodYesOne 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.

Removing deletes the saved method from the customer, so it's gone for later payments and payouts too, not only from this screen. Ask the customer to confirm first, as the drop-in does.

Errors

removeSavedPaymentMethod(_:) throws a PayError when it can't delete the method.

ErrorWhen
unsupportedThe method isn't one of this checkout's savedPaymentMethods(). Nothing was sent.
paymentInProgressA payment, or another removal, is running on this checkout. Nothing was sent.
sessionExpiredPay.com returned HTTP 401. The session expired.
requestRejectedPay.com refused the removal, for example because the method no longer exists.
server, network, unexpectedResponsePay.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

Was this page helpful?