Enumeration

PKPaymentError.Code

An error code that you provide to indicate problems with address or contact information on an Apple Pay sheet.

Declaration

enum PKPaymentError.Code : Int, _ErrorCodeProtocol

Overview

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: paymentContactInvalidError(withContactField:localizedDescription:).

For a shipping address that is unserviceable: paymentShippingAddressUnserviceableError(withLocalizedDescription:).

For an error with the billing address: paymentBillingAddressInvalidError(withKey:localizedDescription:).

For an error with the shipping address: paymentShippingAddressInvalidError(withKey:localizedDescription:).

The code in Listing 1 shows how to create payment errors directly and using a convenience method.

Listing 1

Creating payment errors

// Creating a general shipping address error with NSError
NSError *addressError = [[NSError alloc] initWithDomain:PKPaymentErrorDomain
                        code:PKPaymentShippingContactInvalidError
                        userInfo:@{NSLocalizedDescriptionKey: @“Address is invalid”,
                        PKPaymentErrorContactFieldUserInfoKey: PKContactFieldPostalAddress}];

// Creating a shipping address error specific to the zip code:
NSError *zipCodeError = [[NSError alloc] initWithDomain:PKPaymentErrorDomain
                        code:PKPaymentShippingContactInvalidError
                        userInfo:@{NSLocalizedDescriptionKey: @“Zip code is invalid”, 
                        PKPaymentErrorContactFieldUserInfoKey: PKContactFieldPostalAddress,                      
                        PKPaymentErrorPostalAddressUserInfoKey:CNPostalAddressPostalCodeKey}];

// Creating a billing address error specific to the street with a convenience method
NSError *billingAddressInvalidStreet = [PKPaymentRequest
                             paymentBillingAddressInvalidErrorWithKey:CNPostalAddressStreetKey 
                             localizedDescription:@"Invalid Street"];

Topics

Error Codes

case billingContactInvalidError

The error code to indicate an invalid billing address or billing name.

case shippingContactInvalidError

The error code to indicate an invalid shipping address, email, phone, or name.

case shippingAddressUnserviceableError

The error code for an unserviceable shipping address.

case unknownError

The error code for an unknown error.

See Also

Identifying the Error

static var billingContactInvalidError: PKPaymentError.Code

The error code to indicate an invalid billing address or billing name.

static var shippingContactInvalidError: PKPaymentError.Code

The error code to indicate an invalid shipping address, email, phone, or name.

static var shippingAddressUnserviceableError: PKPaymentError.Code

The error code for an unserviceable shipping address.

static var unknownError: PKPaymentError.Code

The error code for an unknown error.