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.

  1. [Prerequisite] Integrate APIs in Your Backend
    1. Generate Token
    2. Create Order
  2. Get Access to the SDK
  3. Add the Framework to Your App
  4. Add Apple Pay as a Payment Option
  5. Delegate Setup
  6. 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
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
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

  1. Drag and drop ApplePaySDK.xcframework into the file navigator of your Xcode project.
  2. When prompted, make sure to:
    1. ✅ Check “Copy items if needed”
    2. ✅ Add to your app target
  3. Open the General tab of your app target.
  4. Under Frameworks, Libraries, and Embedded Content, ensure that ApplePaySDK.xcframework is set to Embed & Sign.

Once you have added the SDK, you can import it into your Swift files by using the below command.

Code
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.

Swift
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.
Swift
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.

Swift
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:

Swift
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:

Swift
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: true if 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:

  1. Builds a PKPaymentRequest using the provided order details.
  2. Presents the PKPaymentAuthorizationController to the user.
  3. Handles merchant validation, payment processing, and authorization steps.
  4. Notifies the delegate with the transaction’s success or failure status.

Delegate Protocol

Swift
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.


New chat
Responses are generated using AI and may contain mistakes.
Hi! I'm Pine, your AI developer assistant. Ask me anything about Pine Labs APIs, integrations, or troubleshooting.

Tip: you can create a new chat with + E