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.
Load and use JavaScript SDK v6 along with v5
If you have an existing JavaScript SDK v5 integration and want to integrate JavaScript SDK v6 on the same page, add thedata-namespace attribute to your existing v5 <script> tag.
- You access the v5 SDK via
window.paypal_v5instead ofwindow.paypal. - JavaScript SDK v6 can attach to
window.paypalwithout naming collisions.
Initialize JavaScript SDK and create SDK instance
Get a client token and create an instance with the following code sample:client-side - app.js
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.
- Merchants
- Partners
Call
Response: Contains an object with the
findEligibleMethods() with an input options object containing the following parameters:| Parameter | Action |
|---|---|
currencyCode | Set to the three-letter currency code. Example: USD. |
paymentFlow | Set to ONE_TIME_PAYMENT. JavaScript SDK retrieves all payment methods through which the merchant is eligible to accept one-time payments. |
amount | Set to the total order amount that includes item cost, applicable taxes, shipping costs, handling cost, insurance cost, and discounts if any. Example: 100.00. |
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 payment session: Use
sdkInstance.createBankAchOneTimePaymentSession()to create a payment session and register theonApprove(),onCancel(), 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.
Create order and start authentication flow
- Merchants
- Partners
In your client-side code:
In your server-side code, include the code to:
- Include an event-handler function that is triggered when the user clicks the Pay with Bank - ACH button. The function calls the
createOrder()function, receives the order ID from the server-side code, passes it to the JavaScript SDK, and starts the authentication (account verification) flow.
JavaScript SDK uses the order ID to confirm the payment source as
bank.ach_debit to PayPal servers.- Include the
createOrder()function that constructs a payload, calls the server-side code to create an order, and passes the payload. Include the following parameters in the payload:
| Parameter | Action |
|---|---|
intent | Set to CAPTURE to capture payment immediately after approval. |
purchase_units[].amount.currency_code | Set to the three-letter currency code. Example: USD. |
purchase_units[].amount.value | Set to the total order amount that includes item cost, applicable taxes, shipping costs, handling cost, insurance cost, and discounts if any. Example: 100.00.If there is a mismatch between purchase_units[].amount.value and the amount specified in the findEligibleMethods() method, PayPal considers purchase_units[].amount.value as the total order amount. |
- Use a valid full-scope
Beareraccess token, make a POST call to the/v2/checkout/ordersendpoint, and pass the payload received from client-side. - Receive the response to the Create Order call. The response contains the order ID.
- Pass the order ID to the client-side code.
Handle events
Event handlers manage the different outcomes when your customers attempt to make ACH payments. In your code, create event-handler functions that handle customer approval for payment, payment cancellation, error scenarios, and payment capture completion.a. Handle approval, get buyer’s authorization, and capture payment
In your client-side code:- Include the
onApprove()event-handler function that receives the order ID after the customer successfully verifies their bank account, calls thegetOrderDetails()function, and passes the order ID. - Include the
getOrderDetails()function that receives the order ID from theonApprove()event and calls the server-side code to get order details.
- Use a valid full-scope
Beareraccess token and make a GET call to/v2/checkout/orders/{order_id}/. - Receive the order details and render a debit authorization screen to get consent from the buyer.
“I authorize [Merchant business name] to initiate a one-time ACH/electronic debit to my account as follows: Amount: [insert amount], Authorization Date: [insert date], Account holder: [insert full name], Bank: [insert bank name], [Checking / Savings] Account Number: [insert account number], Routing Number: [insert routing number]. I agree that ACH transactions I authorize comply with all applicable laws.” [CTA: Agree and Continue]
APPROVED.
In your client-side code:
- Include an event-handler function (for example,
handleCapture) that receives the order ID after the customer authorizes the debit, calls thecaptureOrder()function, and passes the order ID. - Include the
captureOrder()function that calls the server-side code to capture the payment and displays the transaction results to the customer.
/v2/checkout/orders/{order_id}/capture and pass the captured order details to the client-side code.
- Merchants
- Partners
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 payment processing. JavaScript SDK passes the cancellation details including the order ID 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 payment process. JavaScript SDK passes error message and error details to the function’s data parameter.
Test and go live
Test the end-to-end flow, test error handling, and then switch to production environment by changing the API endpoints and credentials.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 order is created successfully when the authentication flow begins as documented in the Create order and start authentication flow section.
-
Complete the authentication flow and verify the
onApprovecallback receives the order ID as documented in the Handle approval, get buyer’s authorization, and capture payment section. When the bank selection popup appears, use the following sandbox test credentials:- Bank selection: Select Open Finance Bank OAUTH from the list of available banks.
- Username:
john_surname - Password:
ob_user
- Confirm your server successfully captures the payment using the order ID as documented in the Handle approval, get buyer’s authorization, and capture payment section.
- Verify the authentication flow starts correctly with order creation as documented in the Create order and start authentication flow section.
Test error handling
- Cancel the authentication process and verify the
onCancelcallback executes with the order ID as documented in the Handle cancellation section. - Test error scenarios and verify the
onErrorcallback handles failures appropriately as documented in the Handle errors section. - Test idempotent retry logic for 5xx errors during order capture as documented in the Handle approval, get buyer’s authorization, and capture payment section.
Go live
-
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.