Prerequisites
- Ensure you have a PayPal business account approved for Expanded Checkout.
- Ensure to set up developer, sandbox, and production environment accounts.
- Ensure to complete the account provisioning process to enable ACH payments.
Load PayPal JavaScript SDK
PayPal’s JavaScript SDK provides the necessary pre-built tools to render the Pay with Bank (ACH) button on your webpage and handle payment authorization. Include the JavaScript SDK as a<script> tag in the HTML file that renders your webpage.
Create browser-safe client token
The browser-safe token is a client-side access token that authorizes an app to use the JavaScript SDK resources. A browser-safe token is not the same as a server-side access token. The server-side access token helps PayPal authenticate an app when the app accesses PayPal REST API resources.
/v1/oauth2/token endpoint and include the following:
- Encoded app credentials Client ID : Secret in Base64 format, in the Authorization header.
- Data parameters:
Response: Contains the browser-safe client token in the
access_token response parameter.
Initialize JavaScript SDK and create SDK instance
In your client-side code, use thewindow.paypal.createInstance() method with the following parameters to create a PayPal SDK instance:
Response: Contains an SDK instance object with the
createBankAchSavePaymentSession() method for creating ACH payment sessions and the findEligibleMethods() method for checking payment method availability.
Verify eligibility
In your client-side code, use the following methods to determine if you are eligible to offer ACH as a payment method:findEligibleMethods(): Returns all the eligible payment methods.isEligible(): Indicates if ACH is an eligible payment method.
findEligibleMethods() with an input options object containing the following parameters:
Response: Contains an object with the
isEligible() method. Use the method to verify if the eligible payment methods include ACH.
Render Pay with Bank button
After confirming eligibility, render the Pay with Bank - ACH button on your webpage:- Define the container for the ACH button: In the HTML file corresponding to the webpage where you want to render the button, include a container element.
-
Create vault setup token: Call
createVaultSetupToken()to get the vault setup token. A vault setup token is a temporary token that is later exchanged for a payment method token. -
Create payment session: Use
sdkInstance.createBankAchSavePaymentSession()to create a payment session and register theonApprove(),onCancel(),onComplete(), andonError()event handlers. -
Attach the onClick event handler and display the button: Use
addEventListener()to attach theonClickevent handler that triggers theonClickfunction when customers select the Pay with Bank - ACH button.
Define createVaultSetupToken function
ThecreateVaultSetupToken() function creates a vault setup token for saving payment methods without an initial payment.
In your client-side code, include the createVaultSetupToken() function that calls the server-side code to create a vault setup token.
In your server-side code, include the code to make a POST call to the /v3/vault/setup-tokens endpoint:
- Use a Bearer token with full-scope access token in the
Authorizationheader. - Include the following parameters:
Response: Contains the vault setup token in the
id response parameter.
Define onClick event handler function
Create anonClick event-handler function that starts the authentication flow.
In your client-side code, include an event-handler function that is triggered when the user clicks the Pay with Bank - ACH button and starts the authentication (account verification) flow.
Handle events
Event handlers manage the different outcomes when your customers attempt to save ACH payment methods. In your code, create event-handler functions that handle customer approval, payment cancellation, error scenarios, and completion.a. Handle approval and create payment token
In your client-side code, include theonApprove() event-handler function that receives the vault setup token after the customer successfully verifies their bank account, calls the createPaymentToken() function, and passes the vault setup token.
/v3/vault/payment-tokens endpoint:
- Use a valid full-scope
Beareraccess token and make a POST call to the/v3/vault/payment-tokensendpoint with the vault setup token received from client-side. - Receive the payment token details from the PayPal server and pass them to the client-side code.
b. Handle cancellation
In your app code, include theonCancel() event-handler function that handles payment cancellation. Payment cancellation can occur when the customer cancels account verification or the saving process. JavaScript SDK passes the cancellation details to the function’s data parameter.
c. Handle errors
In your app code, include theonError(data) event-handler function to process errors that occur during bank account verification or the saving process. JavaScript SDK passes error message and error details to the function’s data parameter.
d. [Optional] Handle completion
In your app code, you can include theonComplete(data) event-handler function to perform necessary clean-up operations.
Test and go live
Test the end-to-end integration flow- Load your integration page and verify ACH eligibility checking works correctly.
- Click the Pay with Bank button to start the bank account authentication process.
- Verify the vault setup token is created successfully when the authentication flow begins as documented in the Define createVaultSetupToken function section.
-
Complete the authentication flow and verify the
onApprovecallback receives the vault setup token as documented in the Handle approval and create payment token section. When the bank selection popup appears, use the following sandbox test credentials:- Bank selection: Select Demo Bank from the list of available banks.
- Username:
pyplopenbankingubsb.site16441.2credential - Password:
site16441.2
- Confirm your server successfully creates a payment method token using the vault setup token as documented in the Handle approval and create payment token section.
- Verify the authentication flow starts correctly when clicking the button as documented in the Define onClick event handler function section.
- Cancel the authentication process and verify the
onCancelcallback executes as documented in the Handle cancellation section. - Test error scenarios and verify the
onErrorcallback handles failures appropriately as documented in the Handle errors section. - Confirm the
onCompletecallback executes when the flow finishes as documented in the Handle completion section.
-
Switch from sandbox to production API endpoints:
- Change SDK URL from
https://www.sandbox.paypal.com/web-sdk/v6/coretohttps://www.paypal.com/web-sdk/v6/core. - Update API base URL from
https://api-m.sandbox.paypal.comtohttps://api-m.paypal.com.
- Change SDK URL from
-
Replace sandbox credentials with production credentials:
- Use your production client ID and secret.
- Ensure your production PayPal business account is approved for Expanded Checkout and ACH payments.
- Deploy and test your production integration to confirm everything works correctly.