Apple Pay SDKs
Learn how you can use our standalone SDKs to start accepting payments via Apple Pay.
Learn how you can integrate Apple Pay functionality directly to your iOS app without using the Pine Labs Payment SDK. We offer a lightweight, standalone SDK called ApplePaySDK.xcframework, which facilitates Apple Pay payments with minimal setup.
Follow the below steps to install the SDK.
- [Prerequisite] Integrate APIs in Your Backend
- Get Access to the SDK
- Add the Framework to Your App
- Add Apple Pay as a Payment Option
- Delegate Setup
- Payment Data Structure
1. [Prerequisite] Integrate APIs in Your Backend
Start a payment by triggering the payment flow. To start a payment, follow the below steps:
1.1. Generate Token
Integrate our Generate Token API in your backend servers to generate the auth token. Use the token generated to authenticate Pine Labs Online APIs.
Below are the sample requests and response for the Generate Token API.
curl --location 'https://pluraluat.v2.pinepg.in/api/auth/v1/token' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header 'Request-Timestamp: 2024-07-09T07:57:08.022Z' \
--header 'Request-ID: c17ce30f-f88e-4f81-ada1-c3b4909ed235' \
--data '
{
"client_id": "a17ce30e-f88e-4f81-ada1-c3b4909ed232",
"client_secret": "fgwei7egyhuggwp39w8rh",
"grant_type": "client_credentials"
}
'
Refer to our Generate Token API documentation to learn more.
1.2. Create Order
To create an Order, use our Create Order API, for authentication use the generated access token in the headers of the API request.
Below are the sample requests and response for a Create Order API.
curl --location 'https://pluraluat.v2.pinepg.in/api/pay/v1/orders' \
--header 'Authorization: Bearer {token}' \
--header 'Content-Type: application/json' \
--header 'Request-ID: c17ce30f-f88e-4f81-ada1-c3b4909ed235' \
--header 'Request-Timestamp: 2024-07-09T07:57:08.022Z' \
--header 'accept: application/json' \
--data '
{
"order_amount": {
"value": 250,
"currency": "INR"
},
"purchase_details": {
"customer": {
"billing_address": {
"address1": "10 Downing Street Westminster London",
"address2": "Oxford Street Westminster London",
"address3": "Baker Street Westminster London",
"pincode": "51524036",
"city": "Westminster",
"state": "Westminster",
"country": "London",,
"full_name": "Kevin Bob",
"adddress_type": "Home",
"address_category": "billing"
},
"shipping_address": {
"address1": "10 Downing Street Westminster London",
"address2": "Oxford Street Westminster London",
"address3": "Baker Street Westminster London",
"pincode": "51524036",
"city": "Westminster",
"state": "Westminster",
"country": "London",,
"full_name": "Kevin Bob",
"adddress_type": "Home",
"address_category": "shipping"
},
"email_id": "joe.sam@gmail.com",
"first_name": "Kevin",
"last_name": "Smith",
"mobile_number": "9876543210"
},
"merchant_metadata": {
"key1": "val1",
"key2": "val2"
}
},
"pre_auth": false,
"merchant_order_reference": "7bcd1b99-6d67-4c84-87dc-58e6a20a842d"
}
'
Refer to our Create Order API documentation to learn more.
2. Get Access to the SDK
To get the access to ApplePaySDK, please contact the Pine Labs Online integration team.
3: Add the Framework to Your App
- Drag and drop
ApplePaySDK.xcframeworkinto the file navigator of your Xcode project. - When prompted, make sure to:
- ✅ Check “Copy items if needed”
- ✅ Add to your app target
- Open the General tab of your app target.
- Under Frameworks, Libraries, and Embedded Content, ensure that
ApplePaySDK.xcframeworkis set to Embed & Sign.
Once you have added the SDK, you can import it into your Swift files by using the below command.
import ApplePaySDK
4. Add Apple Pay as a Payment Option
Below is an example showing how to start an Apple Pay payment using our SDK.
import UIKit
import PassKit
import ApplePaySDK
class ViewController: UIViewController, ApplePayHandlerDelegate {
private var applePayHandler: ApplePayHandler!
override func viewDidLoad() {
super.viewDidLoad()
let paymentData: [String: Any] = [
"paymentAmount": 50000, // ₹500.00
"currency": "INR",
"merchantDisplayName": "Test Merchant"
]
applePayHandler = ApplePayHandler(
appleMerchantID: "merchant.com.test.applepay",
orderToken: "sample-order-token",
paymentData: paymentData
)
applePayHandler.delegate = self
if applePayHandler.checkApplePayAvailability() {
let button = PKPaymentButton(paymentButtonType: .buy, paymentButtonStyle: .black)
button.addTarget(self, action: #selector(applePayTapped), for: .touchUpInside)
button.center = view.center
view.addSubview(button)
} else {
print("Apple Pay not available on this device")
}
}
@objc func applePayTapped() {
applePayHandler.onApplePayButtonClicked(from: self)
}
func applePayDidFinish(success: Bool, error: Error?) {
print("Apple Pay Finished: success=\(success), error=\(String(describing: error))")
}
}
📘 Note:
- You can customize the appearance of the Apple Pay button by modifying the parameters in the following line of code.
- Apple allows only limited customization options for the Apple Pay button’s style and type.
let button = PKPaymentButton(paymentButtonType: .buy, paymentButtonStyle: .black)
Refer to the Apple Pay Button Customization documentation for more details.
5. Delegate Setup
The SDK provides a delegate protocol — ApplePayHandlerDelegate — which notifies your view controller about the status of an Apple Pay transaction.
func applePayDidFinish(success: Bool, error: Error?)
This method is triggered when an Apple Pay transaction completes, indicating whether it was successful or if an error occurred.
Ensure that your view controller conforms to this delegate protocol to properly handle and respond to payment outcomes.
6. Payment Data Structure
The paymentData dictionary must include key payment parameters required to initiate a transaction.
Below is the minimal structure used in the example:
let paymentData: [String: Any] = [
"paymentAmount": 50000, // Amount in paise (₹500.00)
"currency": "INR",
"merchantDisplayName": "Test Merchant"
]
You can also include additional fields if they are available from your payment initialization response:
let paymentAmount = fetchResponse?.paymentData?.paymentAmount?.amount ?? 0.00
let currency = fetchResponse?.paymentData?.paymentAmount?.currency ?? "INR"
let merchantId = fetchResponse?.merchantInfo?.merchantId ?? 0
let displayName = fetchResponse?.merchantInfo?.merchantDisplayName ?? "Display Name"
let mobileNo = fetchResponse?.customerInfo?.mobileNo ?? ""
let emailId = fetchResponse?.customerInfo?.emailId ?? ""
let applePayMID = fetchResponse?.merchantInfo?.applePayMerchantIdentifier ?? ""
let paymentData: [String: Any] = [
"paymentAmount": paymentAmount,
"currency": currency,
"merchantId": merchantId,
"merchantDisplayName": displayName,
"mobileNo": mobileNo,
"emailId": emailId
]
Reference: Public Methods
The SDK exposes two primary public methods for initializing and handling payments.
checkApplePayAvailability() -> Bool
Determines whether Apple Pay is supported and available on the user’s device.
- Returns:
trueif Apple Pay is supported and the device has at least one eligible card added.
onApplePayButtonClicked(from viewController: UIViewController)
This is the primary method that triggers the Apple Pay payment flow. It:
- Builds a
PKPaymentRequestusing the provided order details. - Presents the
PKPaymentAuthorizationControllerto the user. - Handles merchant validation, payment processing, and authorization steps.
- Notifies the delegate with the transaction’s success or failure status.
Delegate Protocol
public protocol ApplePayHandlerDelegate: AnyObject {
func applePayDidFinish(success: Bool, error: Error?)
}
The delegate method is called when the Apple Pay transaction completes—either successfully or with an error—allowing the app to handle post-payment logic accordingly.
