Skip to content

Express ApplePay Payment

zik-edfa edited this page Feb 9, 2023 · 1 revision

ApplePay


ApplePay Configuration Before starting, the ApplePay implementation makes sure you have enabled the ApplePay capability to your project and configured the ApplePay to your developer account.

  • Request the ExpressPay or LogIn to your bank merchant account and download the CSR to generate ApplePay Processing Certificate on your developer account by following Instructions
  • Download and send the generated Certificate to ExpressPay
  • Important: Use the same developer account and merchant id.

ExpressApplePay

ExpressApplePay class allows you to implement payment via Apple Pay by following easy steps:

Step 1: Create an instance of ExpressApplePay

let expressApplePay = ExpressApplePay()

Step 2: Create an instance of ExpressPaySaleOrder

 /* Required */
let order = ExpressPaySaleOrder(
    id: UUID().uuidString,
    amount: Double("0.10") ?? 0,
    currency: "SAR",
    description: "Test Order"
)

Step 3: Create an instance of ExpressPayPayerOptions (Optional)

/*
Optional
[if you don't want to pass these detail keep it nil ]
*/
let payerOptions = ExpressPayPayerOptions(
    middleName: "Muhammd Iqbal",
    birthdate: Foundation.Date.formatter.date(from: "1987-03-30"),
    address2: "Hyderabad Pakistan",
    state: "Sindh"
) 

Step 4: Create an instance of ExpressPayPayer

/* Required (all fields are mandatory except `options`)*/
let payer = ExpressPayPayer(
    firstName: "Zohaib",
    lastName: "Kambrani",
    address: "Riyadh Olaya KSA",
    country: "SA",
    city: "Riyadh",
    zip: "12271",
    email: "a2zzuhaib@gmail.com",
    phone: "+966500409598",
    ip: "188.54.52.147", // Utils to fetch your public IP -> ExpressPayPublicIP
    options: payerOptions // Optional
)

Step 4: ApplePay merchant identifier The merchant identifier should be configured to the apple developer account and into your project Guide

  • Important: Request the ExpressPay to provide the bank-provided CSR to generate the ApplePay Processing Certificate on the above guide
  • Important: Use the same developer account and merchant id.
let APPLEPAY_MERCHANT_ID = "<your configured merchant it at apple developer account>"

Step 5: Set order, payer, payerOptions, merchant identifier details to the ExpressApplePay instance.

expressApplePay
    .set(order: order)
    .set(payer: payer)
    .set(applePayMerchantID: APPLEPAY_MERCHANT_ID)

Step 6: Set the callbacks to the ExpressApplePay instance to notify you of the different statuses.

.on(authentication:@escaping ((PKPayment) -> Void)) This will be called when the ApplePay verifies the user authentication by FaceID, TouchID or Passcode

expressApplePay.on(authentication: { auth in
    <#code#>
})

.on(transactionFailure:@escaping (([String:Any]) -> Void)) This will be called when the process receive any type of failure during processing payment (must inspect the 'res' before proceed)

expressApplePay.on(transactionFailure: { res in
    <#code#>
})

.on(transactionSuccess:@escaping (([String:Any]) -> Void)) This will be called when the process is completed with success status (must inspect the 'res' before proceed)

expressApplePay.on(transactionSuccess: { res in
    <#code#>
})

Step 7: Initialize/Start the ApplePay Payment

.initialize(target:UIViewController, onError:@escaping ((Any) -> Void), onPresent:(() ->Void)?) This will present the ApplePay authentication sheet from bottom
Facing Issue? Call/Message | Email

expressApplePay.initialize(
    target: self, // UIViewController
    onError: { errors in
        <#code#>
    },
    onPresent: {
        <#code#>
    }
)

Optional Set Shipping Address

.set(shippingAddress:ExpressPayShippingAddress) This will allow you to pass shipping address

expressApplePay.set(
    shippingAddress: ExpressPayShippingAddress(
        name: "Zohaib Kambrani",
        address: "Riyadh Saudi Arabia",
        email: "zikambrani@gmail.com",
        phone: "+966500409598"
    )
)

Optional Set Merchant Capability

.set(merchantCapability:PKMerchantCapability) This will allow you to set merchantCapability to ApplePay PKPaymentRequest

expressApplePay.set(
    merchantCapability: .capability3DS
)

Optional Add Purchase Item

.addPurchaseItem(label:String, amount:Double, type:PKPaymentSummaryItemType) This will allow you to add purchase item to ApplePay PKPaymentRequest .final or .pending

expressApplePay.addPurchaseItem(
    label: "Item Name",
    amount: 0.10,
    type: .final
)

ExpressPay

The ExpressPay iOS SDK - https://expresspay.sa

Clone this wiki locally