Apple Pay & Native Pay Methods
Apple Pay
In the iOS Swift SDK, Apple Pay can be used to process payments with a smooth, native experience. Before displaying the Apple Pay sheet, you may want to:
- (Optionally) Configure Apple Pay to collect specific billing data.
- Confirm device compatibility with Apple Pay.
- Use
generateApplePayReceipt
to initiate the Apple Pay flow and complete the payment in two steps.
1. (Optional) Configuring Apple Pay to Collect Billing Data
If you need to collect specific billing data—like an email address—from the user during the Apple Pay flow, configure your MoneyHashSDK
instance as follows:
let applePayConfig = ApplePayConfiguration(collectibleBillingData: [.email])
let moneyHash = MoneyHashSDKBuilder()
.setPublicKey("<YOUR_PUBLIC_KEY>")
.setApplePayConfiguration(applePayConfig)
.build()
collectibleBillingData
is an array ofCollectibleBillingData
. Currently, only.email
is supported.- To disable billing data collection, pass an empty array (
[]
).
2. Check if the Device is Compatible with Apple Pay
To confirm that the device supports Apple Pay, call:
let isCompatible = moneyHash.isDeviceCompatible()
if isCompatible {
// Proceed with Apple Pay
} else {
print("This device does not support Apple Pay")
}
Apple Pay Payment Flow
Apple Pay payments are now handled using a two-step approach:
- Generate an Apple Pay receipt using
generateApplePayReceipt
. - Submit the generated receipt using
submitPaymentReceipt
once you have theintentId
.
This approach gives you full control over Apple Pay configuration and decouples receipt generation from payment submission.
Step 1: Generate the Apple Pay Receipt
There are two ways to customize and generate the receipt:
Option A: Use Apple Pay Parameters
do {
let receipt = try await moneyHash.generateApplePayReceipt(
depositAmount: 10.0,
merchantIdentifier: "merchant.com.example",
currencyCode: "USD",
countryCode: "US",
supportedNetworks: ["visa", "masterCard"],
merchantCapabilities: ["supports3DS"]
)
print("Apple Pay Receipt generated: \(receipt)")
} catch {
print("Error generating Apple Pay receipt: \(error.localizedDescription)")
}
Option B: Use a Preconfigured ApplePayData
Object
ApplePayData
Objectdo {
let applePayData = ApplePayData
let receipt = try await moneyHash.generateApplePayReceipt(
depositAmount: 10.0,
applePayData: applePayData
)
print("Apple Pay Receipt generated: \(receipt)")
} catch {
print("Error generating Apple Pay receipt: \(error.localizedDescription)")
}
Step 2: Submit the Payment Receipt
Once you have the intentId
, finalize the payment using:
do {
let intentId = "<intent_id>" // Obtain this from your backend
let intentDetails = try await moneyHash.submitPaymentReceipt(
intentId: intentId,
nativePayReceipt: receipt
)
print("Payment completed successfully: \(intentDetails)")
} catch {
print("Error submitting payment receipt: \(error.localizedDescription)")
}
Updated 8 days ago