Implement Apple Pay in iOS
Posted By : Lucky Mehndiratta | 19-Nov-2020
Implement Apple Pay in iOS(Swift)
Today's as the demand for online purchase increase people look other option to pay an amount of the purchase. There are so many methods to do it but Apple provides the best and easy method of payment in iOS Mobile Applications is Apple Pay. Apple Pay is an easy way for mobile developers as well as users to use for payment. Apple Pay overcomes the debit & credit card information typing with a quick one press payment.
Let's Get Started
To integrate the Apple Pay in iOS Mobile Application first we need to configure Apple Developer Account to get the Merchant ID. So the following steps help to configure
1 Check whether your apple developer account is joined Apple Developer Program or not
2 Open Xcode and create a new project and fill in all the details as you move further
3 Get the Bundle Id from Xcode
4 Open the Link: https://developer.apple.com/account/
5 Enter your credentials and select the Certificate, Identifiers & Profile
6 Select Certificate & click on + to create the certificate
7 Select Apple Development & continue and create a CSR(Certificate Signing Request) from your KeyChain and upload and press continue
8 Select Identifier & click on + to create new identifier
9 Select App Id & click on continue & select app, click on continue
10 Enter your Bundle Id and description & Enable Apple Pay Payment Processing
11 Now open Xcode and select target and go to Signing & Capabilities
12 Click on + Capability & add Apple Pay and click on + to add Merchant Key
Start Coding Now
let payableItem = PKPaymentSummaryItem.init(label: "giveyourProductName", amount: "enterproductPrice")
let network = [PKPaymentNetwork.amex] ------> add or delete network as per the requirement
if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: network) {
// request Apple Pay
let paymentRequest = PKPaymentRequest()
paymentRequest.currencyCode = "Add Currency Code()"
paymentRequest.countryCode = "Add Country Code"
paymentRequest.merchantIdentifier = "Add Merchant Id"
paymentRequest.merchantCapabilities = PKMerchantCapability.capability3DS
paymentRequest.supportedNetworks = network
paymentRequest.paymentSummaryItems = [payableItem]guard let vc = PKPaymentAuthorizationViewController(paymentRequest:paymentRequest) else {
return}
vc.delegate = self ------>> Add delegate
self.present(vc, animated: true, completion: nil)} else {
showDefaultAlert(title: "Oops!", message: "Something went wrong")
}
//--------------> Add Payment Delegate <---------------------
extension ViewController: PKPaymentAuthorizationViewControllerDelegate {
func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) {}
func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) {
}
}
Run the code and see the changes in your code
Official Links:-
1 https://developer.apple.com
2 https://developer.apple.com/apple-pay/sandbox-testing/
3 https://developer.apple.com/documentation/passkit/apple_pay/
We, at Oodles Technologies, provide full-scale SaaS app development services to build scalable, responsive, and quality-driven web and mobile applications. Contact us for technical assistance or drop us a line at [email protected] for more detail.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Lucky Mehndiratta
He worked on swift language, UI Design, Api. He is quick in his work and performs at his best.