Displaying a Read-Only Pickup Address
Configure a payment request to display a read-only pickup address on the payment sheet.
Overview
The payment sheet displays the shipping address in the same place whether the shipping method is delivery or pickup. You can prevent the user from editing the address of a pickup and still require other information about the person making the pickup.
Add a Read-Only Pickup Address
Set the following four properties of your payment request to display a read-only pickup address:
Add the postalAddress to requiredShippingContactFields to show the pickup address. To request additional information about the person picking up the item, such as a name or phone number, add other required fields.
Set shippingContact to the pickup address. Optionally set the name of the pickup address to a store or location name.
Set shippingContactEditingMode to PKShippingContactEditingMode.storePickup.
The code below configures an in-store pickup at Example Company and requires an email for the pickup person:
let paymentRequest = PKPaymentRequest
// Set the shipping type.
paymentRequest.shippingType = .storePickup
// Set the required shipping contact fields to display the pickup address and
// require an email for the person picking up the package.
paymentRequest.requiredShippingContactFields = [.postalAddress, .email]
// Create the shipping contact information.
let addr = CNMutablePostalAddress()
addr.street = "123 Any Street"
addr.city = "Any Town"
addr.state = "CA"
addr.postalCode = "95014"
addr.isoCountryCode = "US"
// Add a store or location name.
let pickupAddress = PKContact()
pickupAddress.postalAddress = addr
// Optionally, add a name to the contact.
pickupAddress.name = PersonNameComponents()
pickupAddress.name?.familyName = "Example Company"
// Set the shipping contact.
paymentRequest.shippingContact = pickupAddress
// Set the shipping contact information to read-only.
paymentRequest.shippingContactEditingMode = .storePickup