Integrate Fastlane
Last updated: August 1st 2024, @ 11:23:55 am
Fastlane is PayPal’s quick guest checkout solution. It securely saves and retrieves payment and shipping information for Fastlane members. Fastlane members enter their email and receive prefilled checkout forms.
Availability
Fastlane is available:
- In the US only.
- For both desktop and mobile web.
Prerequisites
- If you're processing payments on legacy PayPal APIs, you'll need to upgrade to Orders v2.
- Make sure you've completed the steps in Getting started.
- You must process card payments with PayPal.
- You must present PayPal as a payment option alongside a field for Fastlane email collection. Email collection is the first step in Fastlane checkout.
- You must collect a billing address during checkout.
1. Integrate front-end
Set up your client side to integrate Fastlane.
Initialize the SDK through the following script tag on your HTML page.
1<script>2 src="https://www.paypal.com/sdk/js?client-id=<CLIENT_ID>>&components=buttons,fastlane"3 data-sdk-client-token="<SDK_CLIENT_TOKEN>"4</script>
Fastlane is initialized with a call to paypal.Fastlane
. You must pass a configuration object passed during initialization.
The following fields are required to initialize the SDK:
client-id
data-sdk-client-token
from setting up your server.
1// instantiates the Fastlane module2const fastlane = await window.paypal.Fastlane({3 FastlanePaymentComponent, // used for quick start integration4 FastlaneCardComponent, // used for flexible integration5 FastlaneWatermarkComponent6// For more details about available options parameters, see the Reference section.7});8910// Convenience parameters for calling later on11const { identity, profile } = fastlane;
You can specify the language in which the Fastlane components are rendered. After you initialize the Fastlane
component, you can set the locale.
1fastlane.setLocale("en_us"); // en_us is the default value
Fastlane supports the following languages:
en_us
- English, defaultes_us
- Spanishfr_us
- Frenchzh_us
- Mandarin
You'll need to render your own email field to capture the payer's email address.
Because the email address is shared with PayPal, it is crucial to inform the payer. We recommend displaying the Fastlane watermark below the email field.
After collecting the email address, PayPal determines whether the email is associated with a Fastlane profile or if it belongs to a PayPal member. Use the following code snippet to look up the customer's email.
1const {2 customerContextId3} = await identity.lookupCustomerByEmail( /* email address */ );
If the user is identified with a Fastlane profile, they need to authenticate before Fastlane retrieves their saved payment and address information. The user is presented with a screen to authenticate themselves by entering a one-time password sent to their registered mobile number.
You can use the following code to trigger the authentication flow and handle the response:
1const {2 customerContextId3} = await identity.lookupCustomerByEmail(document.getElementById("email").value);45//this variable will turn to True if user authenticates successfully with OTP6//will remain False by default78 let renderFastlaneMemberExperience = false;910if (customerContextId) {11 // Email is associated with a Fastlane member or a PayPal member,12 // send customerContextId to trigger the authentication flow.13 const {14 authenticationState,15 profileData16 } = await identity.triggerAuthenticationFlow(customerContextId);1718 if (authenticationState === "succeeded") {19 // Fastlane member successfully authenticated themselves20 // profileData contains their profile details2122 renderFastlaneMemberExperience = true;2324 const name = profileData.name;25 const shippingAddress = profileData.shippingAddress;26 const card = profileData.card;27} else {28 // Member failed or canceled authentication. Treat them as a guest payer29 renderFastlaneMemberExperience = false;30 }31} else {32 // No profile found with this email address. This is a guest payer33 renderFastlaneMemberExperience = false;34}
The triggerAuthenticationFlow()
method returns an AuthenticatedCustomerResult
object. Use the authenticationState
property in the AuthenticatedCustomerResult
object to check if the payer has been authenticated.
On authentication:
- The Fastlane member's card details and default shipping address are returned with the
profileData
object contents. - The
renderFastlaneMemberExperience
is set toTrue
.
If a user fails or declines to authenticate, render the same experience as you would for a guest payer.
This step is not required for:
- Fastlane members without a shipping address.
- Fastlane members with a shipping address in a region you don't support.
- Guest payers.
For Fastlane members with a shipping address, you'll need to render:
- Shipping address returned from profile data on authentication.
- Fastlane watermark.
- Fastlane by PayPal logo.
- Change address button that invokes
showShippingAddressSelector()
. This helps the payer change or add a new address as needed.
If the user addes a new address to their Fastlane profile, send the new address in the Orders v2 server-side request.
The following code renders a shipping address for Fastlane members and guest users:
1// Code to execute when a user clicks on changeAddressButton2if (renderFastlaneMemberExperience) {3 if (profileData.shippingAddress) {4 // Render shipping address from the profile5 const {6 selectedAddress,7 selectionChanged8 } = await profile.showShippingAddressSelector();9 if (selectionChanged) {10 // selectedAddress contains the new address11 } else {12 // Selection modal was dismissed without selection13 }14 } else {15 // Render your shipping address form16 }17} else {18 // Render your shipping address form19}
Fastlane offers two different integration patterns to accept payments; quick start and flexible.
The quick start payment integration loads a pre-built template form to collect payments, requiring less integration effort. It is also PCI DSS compliant, ensuring that customer payment information is handled securely.
The pre-built payment UI component automatically renders the following:
- Selected card for the Fastlane member.
- "Change card" link which allows payers to change the selection or add a new card.
- Card fields for guest users or for Fastlane members who don't have a card in their profile.
- Billing address fields.
1<!-- Div container for the Payment Component -->2<div id="payment-container"></div>3<!-- Submit Button -->4<button id="submit-button">Submit Order</button>
1const shippingAddress = {2 firstName: "Jen",3 lastName: "Smith",4 company: "Braintree",5 streetAddress: "1 E 1st St",6 extendedAddress: "5th Floor",7 locality: "Bartlett",8 region: "IL", // must be sent in 2-letter format9 postalCode: "60103",10 countryCodeAlpha2: "US",11 phoneNumber: "14155551212"12}1314const options = {15 fields: {16 phoneNumber: {17 // Example of how to prefill the phone number field in the FastlanePaymentComponent18 prefill: "4026607986"19 }20 },21 styles: {22 root: { //specify styles here23 backgroundColorPrimary: "#ffffff"24 }25 }26};2728const fastlanePaymentComponent = await fastlane.FastlanePaymentComponent({29 options,30 shippingAddress31 });32 await fastlanePaymentComponent.render("#payment-container");3334// event listener when the user clicks to place the order35const submitButton = document.getElementById("submit-button");36submitButton.addEventListener("click", async ()=> {37 const { id } = await fastlanePaymentComponent.getPaymentToken();3839 // Send the paymentToken and previously captured device data to server40 // to complete checkout41});
After you receive the paymentTokenId
from the paymentToken
object, send the paymentTokenId
to your server to create a transaction with it.
For more information on the options you can pass to the functions in the previous code sample, see Customize your integration.
When displaying the card from the payer's Fastlane profile, you must inform them by displaying the Fastlane watermark below the card.
For a better payer experience of Fastlane, preload the watermark asset by adding the following code to the <head>
section of the page:
1<link rel="preload" href="https://www.paypalobjects.com/fastlane-v1/assets/fastlane-with-tooltip_en_sm_light.0808.svg" as="image" type="image/avif" />2<link rel="preload" href="https://www.paypalobjects.com/fastlane-v1/assets/fastlane_en_sm_light" />
2. Integrate back end
On your server, create an order by calling the Orders API and passing the single-use token, along with the item details and the shipping address.
Provide detailed item descriptions and product images for each item to:
- Create a better user experience for email communications.
- Streamline any potential dispute resolution.
1curl -v -k -X POST 'https://api-m.sandbox.paypal.com/v2/checkout/orders' \2 -H 'PayPal-Request-Id: UNIQUE_ID' -H 'PayPal-Partner-Attribution-ID: BN-CODE'\3 -H 'PayPal-Auth-Assertion: AUTH-ASSERTION-TOKEN' \4 -H 'Authorization: Bearer PAYPAL_ACCESS_TOKEN' \5 -H 'Content-Type: application/json' \6 -H 'PayPal-Client-Metadata-Id: <CM_ID>' \7 -d '{8 "intent": "CAPTURE",9 "payment_source": {10 "card": {11 "single_use_token": "1h371660pr490622k" //paymentToken from the client12 }13 },14 "purchase_units": [15 {16 "amount": {17 "currency_code": "USD",18 "value": "50.00",19 "breakdown": {20 "item_total": {21 "currency_code": "USD",22 "value": "40.00"23 },24 "shipping": {25 "currency_code": "USD",26 "value": "10.00"27 }28 }29 },30 "items": [31 {32 "name": "Coffee",33 "description": "1 lb Kona Island Beans",34 "sku": "sku03",35 "unit_amount": {36 "currency_code": "USD",37 "value": "40.00"38 },39 "quantity": "1",40 "category": "PHYSICAL_GOODS",41 "image_url": "https://example.com/static/images/items/1/kona_coffee_beans.jpg",42 "url": "https://example.com/items/1/kona_coffee_beans",43 "upc": {44 "type": "UPC-A",45 "code": "987654321015"46 }47 }48 ],49 "shipping": {50 "type": "SHIPPING",51 "name": {52 "full_name": "Lawrence David"53 },54 "address": {55 "address_line_1": "585 Moreno Ave",56 "admin_area_2": "Los Angeles",57 "admin_area_1": "CA", //must be sent in 2-letter format58 "postal_code": "90049",59 "country_code": "US"60 },61 "phone_number": {62 "country_code": "1",63 "national_number": "5555555555"64 }65 }66 }67 ]68}'
Store pick-up: If the buyer is picking up the item from a storefront, modify the shipping type parameter in the call and ensure the shipping method is set to PICKUP_IN_STORE
. This ensures that buyer profiles aren't created with the address of your store as their shipping address.
Vaulting: You can save a payment method with or without a transaction.
- Vault with transaction: If you want to save the
paymentToken
returned by the Fastlane SDK at the time of transaction, you can do so only when using thestore_in_vault
attribute in the request to/v2/orders
on your server. This returns a payment token, which can be vaulted before or after a transaction and used for future transactions. See the Orders v2 documentation for more details. - Vault without transaction: If you want to save the
paymentToken
returned by the Fastlane SDK without completing the transaction, then the payment token is generated but the Fastlane profile is not created for the customer. The Fastlane profile is created only for vaulting customers if they also complete a transaction during checkout.
3. Test integration
You'll need to test your integration for guest payers and Fastlane members, with and without the consent toggle on. Testing varies depending on whether your integration is quick start or flexible.
Guest payers enter an email not associated with a PayPal account or Fastlane profile. Make sure you have the following before you start testing the guest payer flow:
- New email address: Provide a new email address not associated with a sandbox Fastlane account.
- Ensure opt-in toggle is ON: Go through the checkout process using one of the test card numbers. Be sure that the opt-in toggle is on.
- Phone number for sandbox: Enter any valid phone number. Make sure to pass a valid area code and prefix. A Fastlane profile is not created if you pass an invalid number such as
111-111-1111
. No SMS is sent in sandbox mode.
When you complete the transaction with the consent toggle on, a Fastlane profile is created. Use that profile to test transactions as a Fastlane member.
User flow | Result |
---|---|
The FastlanePaymentComponent renders card fields and the consent toggle. The buyer turns the consent toggle off and completes the order. | The payment is completed successfully and no Fastlane profile is created. |
User flow | Result |
---|---|
The FastlanePaymentComponent renders card fields and the consent toggle. The buyer completes the order with the consent toggle on. | The payment is completed successfully and a Fastlane profile is created for the email the guest entered. |
A Fastlane member enters a recognized email at checkout.
Make sure you have the following before you start testing the member flow:
- A Fastlane member profile: Go through the previous step and register a new Fastlane account. Be sure to remember the email address used when you created the account so that you can use it for additional testing.
- OTP for testing: When the authentication modal appears and you are prompted for a one-time password (OTP) use
111111
to trigger a successful authentication and any other 6-digit number to simulate a failed authentication.
Scenario | User flow | Result |
---|---|---|
Happy path |
| The buyer completes the order. |
OTP failed or cancelled |
|
|
New address |
|
|
New card |
|
|
Change address |
| The buyer completes the order with changed address. |
Change card |
| The buyer completes the order with selected card. |
No card or unsupported card |
|
|
No address or address in unsupported region |
|
|
PayPal members who choose not to save their profile are treated as guest users.
PayPal members who choose to save their profile are treated as returning Fastlane members for future transactions.
PayPal members do not require any additional handling within your integration because our client SDK handles this use case for you in the following ways:
- After performing the
lookupCustomerByEmail
method, we return acustomerContextId
as if this were a Fastlane member. - When you call the
triggerAuthenticationFlow
method, our SDK displays a call to action to the buyer explaining that they can create a Fastlane profile populated with information from their PayPal account with one click. - If the consumer clicks yes, PayPal returns
profileData
exactly as we would for a Fastlane member. - If the consumer closes the dialog, PayPal returns an empty
profileData
object and you would handle this as you would any Fastlane guest member.
Use the following test card numbers for sandbox transactions:
Brand | Card number |
---|---|
Visa | 4005 5192 0000 0004 |
Visa | 4012 0000 3333 0026 |
Visa | 4012 0000 7777 7777 |
Mastercard | 5555 5555 5555 4444 |
American Express | 3782 822463 10005 |
4. Go live
If you have fulfilled the requirements for accepting card payments via Fastlane for your business account, review Move your app to production to test and go live.
If this is your first time testing in a live environment, follow these steps:
- Log into the PayPal Developer Dashboard with your PayPal business account.
- Complete production onboarding so you can process card payments with your live PayPal business account.
Select Advanced Credit and Debit Card Payments on your REST app. The merchant will be signed up for advanced credit and debit after onboarding through the Partner Referral API.
Next step
Optionally customize your Fastlane integration.
Troubleshooting, FAQs, and how to customize your integration.