Creates an Apple Pay one-time payment session for processing payments through Apple Pay.
A session object with methods to manage the Apple Pay payment flow
This method creates a session object that provides helper methods to bridge between Apple's native ApplePaySession and PayPal's payment processing.
The session provides methods to:
// Check if Apple Pay is available
const isApplePayAvailable =
window.ApplePaySession && ApplePaySession.canMakePayments();
if (!isApplePayAvailable) {
return;
}
// Create PayPal SDK Apple Pay session
const applePaySession = sdkInstance.createApplePayOneTimePaymentSession();
// Get Apple Pay config from eligible methods
const paymentMethods = await sdkInstance.findEligibleMethods({
currencyCode: "USD",
});
if (paymentMethods.isEligible("applepay")) {
const applePayConfig = paymentMethods.getDetails("applepay").config;
// Handle Apple Pay button click
applePayButton.onclick = async () => {
// Create Apple Pay payment request using the helper method
const paymentRequest = {
...applePaySession.formatConfigForPaymentRequest(applePayConfig),
countryCode: "US",
currencyCode: "USD",
total: {
label: "Demo Store",
amount: "100.00",
type: "final",
},
};
// Start Apple's native ApplePaySession
const appleSdkSession = new ApplePaySession(4, paymentRequest);
// Use Apple's native event handlers with PayPal SDK bridge methods
appleSdkSession.onvalidatemerchant = async (event) => {
const payload = await applePaySession.validateMerchant({
validationUrl: event.validationURL,
displayName: "My Store",
domainName: "example.com",
});
appleSdkSession.completeMerchantValidation(payload.merchantSession);
};
appleSdkSession.onpaymentauthorized = async (event) => {
const order = await createOrder();
await applePaySession.confirmOrder({
orderId: order.orderId,
token: event.payment.token,
billingContact: event.payment.billingContact,
shippingContact: event.payment.shippingContact,
});
appleSdkSession.completePayment({
status: ApplePaySession.STATUS_SUCCESS,
});
};
appleSdkSession.begin();
};
}
Interface for managing Apple Pay payment operations within the PayPal SDK.
Remarks
This interface provides methods for creating and managing Apple Pay payment sessions, allowing merchants to integrate Apple Pay as a payment method in their applications.
The ApplePayPaymentsInstance enables seamless integration with Apple Pay's payment flow, providing a secure and user-friendly way to process payments through the Apple Pay platform.