Prerequisites
- Ensure you have PayPal business account approved for Expanded Checkout.
- Ensure you set up developer, sandbox, and production environment accounts.
Load PayPal JS SDK
PayPal’s JavaScript SDK provides the necessary pre-built tools to render the 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.
For production environment:
Create browser-safe client token
The browser-safe token is a client-side access token that authorizes the app to use the JavaScript SDK resources. Configure your server to call PayPal’s OAuth API and parse theaccess_token
from the response for your client-side application.
In the server-side call to the /v1/oauth2/token
endpoint:
- Encode app credentials
Client ID : Secret
in Base64 format and use it in theAuthorization
header. - Include the following data parameters:
grant_type
: Set the parameter value toclient_credentials
to specify that the app is requesting to exchange client ID and secret for an access token.response_type
: Set the parameter value toclient_token
to request for a client-side access token.intent
: Set the parameter value tosdk_init
to specify that the purpose for the request is SDK initialization.
access_token
response parameter.
Initialize JS SDK and create SDK instance
Use thewindow.paypal.createInstance()
method to create a PayPal SDK instance and include the following parameters:
clientToken
: The browser-safe client token.components
: Set to["bank-ach-payments"]
to load and render ACH components.
createBankAchSavePaymentSession()
for creating ACH payment sessions and findEligibleMethods()
for checking payment method availability.
Verify eligibility
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
- Boolean method that determines if ACH is an eligible payment method.
findEligibleMethods()
with an options
object containing the following:
apiCode
: Set torestApi
to specify the API methodology.countryCode
: Set to the two-letter country code. Example:US
.currencyCode
: Set to the three-letter currency code. Example:USD
.paymentFlow
: Set toVAULT_WITHOUT_PAYMENT
to vault without an initial payment.paymentMethods
: Set to["ACH"]
to check ACH payment eligibility.
paymentMethods
object with isEligible()
method to check if ACH is eligible.
Render Bank ACH button
After confirming eligibility, render the Bank ACH button on your webpage. To render the Bank ACH button:- Define the container for the Bank ACH button: In the HTML file corresponding to the webpage where you want to render the button, include a container element as shown in the sample code:
-
Add the Bank ACH button element: Dynamically insert the Bank ACH button HTML element into the container. The
<bank-ach-button>
web component supportsid
, a unique identifier for the button element. -
Create vault setup token and payment session: After rendering the button, call
createVaultSetupToken()
to get the vault setup token, then usesdkInstance.createBankAchSavePaymentSession()
to create the payment session with the event handlers. See Create vault setup token function for the complete client and server implementation code. -
Attach the event handler: Use
addEventListener()
to register theonClick
callback handler that executes when customers select the Bank ACH button.
- Sets up the Bank ACH button on your webpage.
- Creates the vault setup token and payment session.
- Defines the on-click flow for your button.
Create vault setup token
ThecreateVaultSetupToken()
function creates a vault setup token for saving payment methods without an initial payment. This token is different from the browser-safe client token and is used to configure the payment session.
In the server-side call to the /v3/vault/setup-tokens
endpoint:
- Use a Bearer token with full-scope access token in the
Authorization
header. - Include the following in the request body:
payment_source.bank.ach_debit.billing_address.country_code
: Set to the two-letter country code. Example:US
.payment_source.bank.ach_debit.experience_context.cancel_url
: Set to the URL where customers are redirected if they cancel. Example:https://example.com/cancel
.payment_source.bank.ach_debit.experience_context.locale
: Set to the locale code. Example:en-US
.payment_source.bank.ach_debit.experience_context.return_url
: Set to the URL where customers are redirected after completion. Example:https://example.com/return
.payment_source.bank.ach_debit.verification.paypal.method
: Set toINSTANT_ACCOUNT_VERIFICATION
for the verification method.
id
response parameter.
Define on-click event handler function
Create an event handler to process Bank ACH button clicks and start the authentication session. Since the vault setup token and payment session are already created, this function only needs to start the authentication flow.Set up event handlers
Event handlers manage the different outcomes when your customers attempt to save ACH payment methods. Configure event handlers for the Bank ACH session lifecycle.a. Handle approval
In your app code, include the logic to handle when the customer successfully authenticates their bank account. Use thecreatePaymentToken()
method to convert the vault setup token to a reusable payment token and include setupToken
, the vault setup token received from the approval event (from data.vaultSetupToken
).
Response: Contains paymentToken
- the reusable payment token ID for future transactions.
Create payment method token
Convert the setup token to a reusable payment token for future transactions. This process is triggered when the customer successfully authenticates their bank account. In the server-side call to the/v3/vault/payment-tokens
endpoint:
- Use a Bearer token with full-scope access token in the
Authorization
header. - Include the following in the request body:
payment_source.token.id
: Set to thevaultSetupToken
received from the client.payment_source.token.type
: Set toSETUP_TOKEN
to specify the token type.
id
response parameter, which is the permanent token for future transactions.
b. Handle cancellation
In your app code, include the logic to handle when the customer cancels the bank account linking process. Use theonCancel()
callback function to handle the cancellation event. This function accepts the optional data
parameter containing cancellation details.
Response: Handles cancellation events when the customer exits the bank account linking process without completing it.
c. Handle errors
In your app code, include the logic to handle errors that occur during the bank account authentication process. Use theonError()
callback function to process error events and include the data
parameter containing error message and details.
Response: Processes error events and provides error details for troubleshooting authentication failures.
d. Handle completion
In your app code, include the logic to handle when the authentication flow finishes. Use theonComplete()
callback function to perform cleanup operations and finalize the ACH flow. This function accepts the optional data
parameter containing completion status and details.
Response: Performs any necessary cleanup and resets the payment flow state.
Test and go live
Test
Test your Save ACH integration in the PayPal sandbox environment. Test the integration flow:- Load your integration page and verify ACH eligibility checking works correctly.
- Click the Bank ACH button to start the bank account authentication process.
- Complete the authentication flow and verify the
onApprove
callback receives the vault setup token as documented in the Set up event handlers section. - Confirm your server successfully creates a payment method token using the vault setup token as documented in the Create payment method token section.
- Verify the authentication flow starts correctly when clicking the button as documented in the Define on-click event handler function section.
- Cancel the authentication process and verify the
onCancel
callback executes as documented in the Set up event handlers section. - Test error scenarios and verify the
onError
callback handles failures appropriately as documented in the Set up event handlers section. - Confirm the
onComplete
callback executes when the flow finishes as documented in the Set up event handlers section.
Go live
Update to production environment:-
Switch from sandbox to production API endpoints:
- Change SDK URL from
https://www.sandbox.paypal.com/web-sdk/v6/core
tohttps://www.paypal.com/web-sdk/v6/core
. - Update API base URL from
https://api-m.sandbox.paypal.com
tohttps://api-m.paypal.com
.
- Change SDK URL from
-
Replace sandbox credentials with production credentials:
- Use your production Client ID and Client 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.