Before you begin
This guide assumes that you know how to:
Accept payments with PayPal
Prepare the API
PayPal requires the following data to process a payment successfully. Pass the following data in the client session, or in the payment request (for manual payment creation).
Parameter Name | Required | Description |
---|---|---|
3-letter currency code in ISO 4217 format, e.g. USD for US dollars | ||
Details of the line items of the order | ||
The country code of the user is required for PayPal. | ||
Primers direct integration to PayPal enables you send a custom ID to Paypal to link your orders to a specific custom ID. | ||
Primers direct integration to PayPal enables you send a Invoice ID to Paypal to link your orders to a specific invoice ID. | ||
Required field if the Billing Agreement is being created. |
Prepare the SDK for payments
Pre-requisites
Handling redirects is required for Payment Methods that present a webpage or open a 3rd party application for the customer to enter their credentials and validate their payment.
To enable this feature, ensure that you include the urlScheme
parameter when configuring the PrimerPaymentMethodOptions
object.
Set up redirects
1234567
let settings = PrimerSettings( // ... paymentMethodOptions: PrimerPaymentMethodOptions( urlScheme: "{url scheme}", // e.g. primer://, yourscheme:// ), // ...)
Handle redirects
When the user is redirected back to the main app, the function application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool
is automatically called by iOS. Make sure to call Primer.shared.application...
to forward this information to the SDK so that Universal Checkout can continue the flow.
123456789101112
import PrimerSDKimport UIKit @UIApplicationMainclass AppDelegate: UIResponder, UIApplicationDelegate { // ... func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool { return Primer.shared.application(application, continue: userActivity, restorationHandler: restorationHandler) }}
Handle payment method
PayPal requires a Native UI Manager in order to be presented to the user:
12345
// 👇 Create the payment method managerlet nativeUIPaymentMethodManager = try PrimerHeadlessUniversalCheckout.NativeUIManager(paymentMethodType: "PAYPAL") // 👇 Show the payment methodtry nativeUIPaymentMethodManager.showPaymentMethod(intent: .checkout)
This code is intended solely for illustrative purposes. As many payment methods share a common approach, it is recommended to centralize the implementation of these methods within your codebase. For a practical demonstration of how to achieve this, please refer to the guide on how to handle Native UI payment methods.
Vaulting
Vaulting PayPal requires the Billing Agreement API to be activated on your account. Get in touch with your account manager at PayPal to activate this feature.
In order to be approved by PayPal for Billing Agreements, you may be required to collect device data using their Fraudnet/Magnes library and pass a user session identifier to PayPal during the transaction. This can be done by passing this as metadata.paypal_client_metadata_id in the Primer Client Session/Payment API.
In order to vault PayPal accounts, pass the following data in the Client Session:
Parameter Name | Required | Description |
---|---|---|
A unique identifier for your customer |
Prepare the SDK for vaulting
PayPal requires a Native UI Manager in order to be presented to the user:
12345
// 👇 Create the payment method managerlet nativeUIPaymentMethodManager = try PrimerHeadlessUniversalCheckout.NativeUIManager(paymentMethodType: "PAYPAL") // 👇 Show the payment methodtry nativeUIPaymentMethodManager.showPaymentMethod(intent: .vault)
- After the user accepts PayPal's billing agreement, Primer will return tokenized data to the primerHeadlessUniversalCheckoutDidTokenizePaymentMethod listener method.
- This data will include PayPal's externalPayerInfo information within the
PaymentInstrumentData
. - For a more comprehensive understanding, refer to the documentation available for the PrimerHeadlessUniversalCheckoutDelegate interface.
This code is intended solely for illustrative purposes. As many payment methods share a common approach, it is recommended to centralize the implementation of these methods within your codebase. For a practical demonstration of how to achieve this, please refer to the guide on how to handle Native UI payment methods.
Go live
You don’t need to do anything particular to go live — just make sure to use production credentials.