PKPaymentError
An error type that you create to indicate problems with address or contact information on an Apple Pay sheet.
Declaration
struct PKPaymentErrorOverview
The user must resolve any errors that you report on the Apple Pay sheet before they’re able to authorize the transaction. You return any errors in PKPaymentAuthorizationResult or PKPaymentRequestShippingContactUpdate.
You can build your own payment error (NSError), or use one of the following convenience methods from PKPaymentRequest to build it for you.
For an error with contact information, use paymentContactInvalidError(withContactField:localizedDescription:).
For a shipping address that is unserviceable, use paymentShippingAddressUnserviceableError(withLocalizedDescription:).
For an error with the billing address, use paymentBillingAddressInvalidError(withKey:localizedDescription:).
For an error with the shipping address, use paymentShippingAddressInvalidError(withKey:localizedDescription:).
The following code example shows:
How to create an error directly.
How to create an error using a convenience method.
Creating payment errors:
// A general billing address error created with NSError
let billingAddressError = NSError.init(domain: PKPaymentErrorDomain,
code: PKPaymentError.billingContactInvalidError.rawValue,
userInfo: [NSLocalizedDescriptionKey:"Address has an error",
PKPaymentErrorKey.contactFieldUserInfoKey: PKContactField.postalAddress])
// A specific billing address error created with a convenience method
let billingAddressInvalidStreet = PKPaymentRequest.paymentBillingAddressInvalidError(withKey:CNPostalAddressStreetKey,
localizedDescription: "Invalid street")Topics
Describing the error
Identifying the error
billingContactInvalidErrorshippingContactInvalidErrorshippingAddressUnserviceableErrorcouponCodeExpiredErrorcouponCodeInvalidErrorunknownErrorPKPaymentError.Code