Reader small image

You're reading from  Apple Pay Essentials

Product typeBook
Published inFeb 2016
Reading LevelBeginner
Publisher
ISBN-139781785886386
Edition1st Edition
Languages
Right arrow
Author (1)
Ernest Bruce
Ernest Bruce
author image
Ernest Bruce

Ernest Bruce is an accomplished technical writer and software engineer. He has worked for 13 years at Apple, Inc., where he held the position of Senior Technical Writer writing developer documentation. At Apple, Ernest specialized in writing documentation for the Xcode toolset, focusing on the Xcode user guide, and Xcode overview, as well as unit testing documentation and sample code. He also worked extensively on API documentation for the OS X and iOS platforms. Ernest helped design and develop the Xcode help articles that aid developers in getting around the user interface of the Xcode app. Before his years at Apple, Ernest worked as a programmer for Ping, Inc., where he helped manage the manufacturing processes using APL (A Programming Language). Ernest also has extensive experience in customer service, which has been instrumental to him developing content that readers find clear and easy to read, and that makes complex concepts more approachable. Ernest is the head of Nerd Brawn, LLC, a software development company that focuses on developing platforms that help people learn about their environment and each other in innovative ways. The company is also working on new techniques to present content on desktop computers, tablets, and mobile phones.
Read more about Ernest Bruce

Right arrow

Chapter 6. Apple Pay API Summary

You process Apple Pay transactions in three phases:

  1. Preparation: Create a payment request and populate it with payment information and details about the product the user is purchasing.

  2. Payment sheet interaction: Respond to user interactions with the payment sheet (such as changes to the shipping address or the desired shipping method) through the methods of the PKPaymentAuthorizationViewControllerDelegate protocol.

  3. Payment processing: Process the Apple Pay transaction on the user's device and your own servers through the API provided by your payment gateway and HTTP requests to your order processing web app.

Earlier chapters showed the workflows you use to interact with the major actors in Apple Pay transactions. This chapter provides helpful information on the classes, methods, and properties of the Apple Pay API that you must become familiar with to use it effectively. However, when you need even more detailed information, you should consult the Apple developer...

Main classes


This section describes the major Apple Pay classes you use to process Apple Pay transactions. These classes include:

  • PKPaymentButton: You use this class to display a Pay button, which the user uses to begin an Apple Pay transaction.

  • PKPaymentRequest: This class represents a payment request, which the user authorizes or cancels in the payment sheet.

  • PKPaymentSummaryItem: Instances of this class represent summary items (such as subtotal, shipping costs, and total) in the payment sheet.

  • PKPaymentMethod: This class provides access to information about the payment card used in Apple Pay transaction.

  • PKShippingMethod: Instances of this class represent the shipment methods you support.

  • PKPaymentAuthorizationViewController: This class determines whether the user can use Apple Pay on the device. It is also used to present the payment sheet on the screen.

  • PKPayment: Instances of this class store payment information for Apple Pay transactions.

  • PKPaymentToken: Instances of this class contain...

Payment sheet user event protocol


This section describes the protocol used by the payment sheet to communicate with its delegate.

The PKPaymentAuthorizationViewControllerDelegate protocol

The PKPaymentAuthorizationViewControllerDelegate protocol specifies the set of methods that the payment sheet uses to communicate events to its delegate (which you can implement to respond to calls to these methods). The following sections identify the actions that the user can perform in the payment sheet and the delegate methods called when the user performs them.

The user chooses a payment card

The user can switch payment cards in the payment sheet (that is, if the user added more than one payment card to Apple Pay on the device).

-paymentAuthorizationViewController:didSelectPaymentMethod: completion:

This is called when the user chooses a payment card. If the payment card affects the payment request's summary items (for example, if you provide a discount to use a store card), you must compute the summary...

Auxiliary classes


This section describes some additional classes you must use to work with the Apple Pay API. The classes are:

  • PKContact: This is used to represent contact information (name, phone number, and e-mail) and addresses

  • CNPhoneNumber: This is used to represent a phone number

  • CNPostalAddress: This is used to represent addresses

The PKContact class

The PKContact class contains properties that represent the components of a billing or shipping address. The payment sheet provides instances of this class to its delegate when the user selects a shipping address (paymentAuthorizationViewController: didSelectShippingContact:completion:), and in the PKPayment object it provides when the user authorizes the payment request (paymentAuthorizationViewController:didAuthorizePayment:completion:).

Contact address components

These properties contain the information requested in the requiredBillingAddressFields or requiredShippingAddressFields properties of the PKPaymentRequest object. The value of...

Summary


This chapter described most of the classes you have to work with to process Apple Pay payments. It also described the protocol used by the payment sheet to communicate user actions to its delegate so that you can respond appropriately. Finally, the chapter listed a few additional classes that you must work with to access address components, such as a person's name, phone number, and postal address.

This is the end of Apple Pay Essentials, conceived to help you add Apple Pay support to your apps. This book introduced the world of online payments, describing how payment associations, payment gateways, and banks work together to transfer funds from a customer's payment card to a merchant's account. Apple Pay improves on this model by adding convenience, privacy, and security to the process.

You learned about using the REST API in your client app to communicate with server web apps that provide the information that the app needs (such as details about the products you have for sale and...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Apple Pay Essentials
Published in: Feb 2016Publisher: ISBN-13: 9781785886386
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Ernest Bruce

Ernest Bruce is an accomplished technical writer and software engineer. He has worked for 13 years at Apple, Inc., where he held the position of Senior Technical Writer writing developer documentation. At Apple, Ernest specialized in writing documentation for the Xcode toolset, focusing on the Xcode user guide, and Xcode overview, as well as unit testing documentation and sample code. He also worked extensively on API documentation for the OS X and iOS platforms. Ernest helped design and develop the Xcode help articles that aid developers in getting around the user interface of the Xcode app. Before his years at Apple, Ernest worked as a programmer for Ping, Inc., where he helped manage the manufacturing processes using APL (A Programming Language). Ernest also has extensive experience in customer service, which has been instrumental to him developing content that readers find clear and easy to read, and that makes complex concepts more approachable. Ernest is the head of Nerd Brawn, LLC, a software development company that focuses on developing platforms that help people learn about their environment and each other in innovative ways. The company is also working on new techniques to present content on desktop computers, tablets, and mobile phones.
Read more about Ernest Bruce