Structure

PKPaymentError

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

Declaration

struct PKPaymentError

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.

The example code in Listing 1 shows how to create an error directly and how to create one using a convenience method.

Listing 1

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

var errorCode: Int

The error code for this instance.

var errorUserInfo: [String : Any]

Additional details about an error.

var localizedDescription: String

A user-facing, localized string that describes the error.

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.

enum PKPaymentError.Code

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

Querying the Error Domain

static var errorDomain: String

The error domain for this error.

let PKPaymentErrorDomain: String

The error domain for specific errors associated with Apple Pay in-app or web payments.

Comparing Errors

static func != (PKPaymentError, PKPaymentError) -> Bool

Returns a Boolean value indicating whether two values are not equal.

See Also

Errors

struct PKPaymentErrorKey

Additional details about an error on the Apple Pay sheet.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software