Type Method

paymentShippingAddressInvalidErrorWithKey:localizedDescription:

Creates a shipping address error with the supplied key and user-facing error message.

Declaration

+ (NSError *)paymentShippingAddressInvalidErrorWithKey:(NSString *)postalAddressKey localizedDescription:(NSString *)localizedDescription;

Parameters

postalAddressKey

A key value from CNPostalAddress that indicates which part of the address has an error.

localizedDescription

Optional. Provide a localized, user-facing error message string to help the user resolve the error.

Discussion

You can use this convenience method to create a payment error object instead of creating an NSError object yourself. This convenience method indicates an error in the shipping address received from an Apple Pay sheet.

The error you provide and its optional message appear on the Apple Pay sheet. The available space to display messages is limited, so you should keep your messages concise.

For example, Listing 1 shows how to create errors for indicating problems with the zip code and street, using the keys CNPostalAddressPostalCodeKey and CNPostalAddressStreetKey.

Listing 1

Creating custom errors

// Create errors for the zip code and street address
NSError *shippingInvalidZip = [PKPaymentRequest 
    paymentShippingAddressInvalidErrorWithKey:CNPostalAddressPostalCodeKey 
    localizedDescription:@"Invalid ZIP code"];
 
NSError *shippingInvalidStreet = [PKPaymentRequest    paymentShippingAddressInvalidErrorWithKey:CNPostalAddressStreetKey 
    localizedDescription:@"Missing street name"];

// The result contains both errors
PKPaymentAuthorizationResult *result = [[PKPaymentAuthorizationResult alloc]
    initWithStatus:PKPaymentAuthorizationStatusFailure 
    errors:@[shippingInvalidZip, shippingInvalidStreet]];

See Also

Providing Error Information

+ paymentBillingAddressInvalidErrorWithKey:localizedDescription:

Creates a billing address error with the supplied key and user-facing error message.

+ paymentContactInvalidErrorWithContactField:localizedDescription:

Creates a contact error with the supplied field and user-facing error message.

+ paymentShippingAddressUnserviceableErrorWithLocalizedDescription:

Creates an error for an unserviceable address, with the supplied user-facing error message.