JS SDK Reference for Payment Fields

DocsCurrentLast updated: November 17th 2023, @ 4:51:27 pm

Query paramDefaultDescription
client-idn/aYour PayPal REST client ID. This identifies your PayPal account and determines where transactions are paid.
componentsbuttonsA comma-separated list of components to enable. The buttons, payment-fields, marks, and funding-eligibility components are required for payment fields components.
enable-fundingnoneFunding sources to allow from showing in the buttons and marks.

By default, PayPal JavaScript SDK provides smart logic to display only appropriate marks and buttons for the current buyer. This optional parameter bypasses the buyer country check for desired payment methods.

For example:


currencyUSDCurrency of the transaction.
localeautomaticBy default, PayPal detects the preferred locale for the buyer based on their geolocation and browser preferences. It is recommended to pass this parameter with a supported locale if you would like the payment fields components to render in the same language as the rest of your site.
intentcaptureThe funds are captured immediately, while the buyer is present on your site.
committrueThis indicates that the final amount won't change after the buyer returns from PayPal to your site.
vaultfalseDisplays all funding sources including those that don’t support vaulting.



Customize your buttons by passing in the style option.

  style: {
    layout: 'vertical',
    label:  'paypal'

Note: Alternative payment methods supports only vertical layout.

See additional, optional parameters.


The createOrder parameter sets up the details of the transaction. It's called when the buyer clicks the PayPal button, which launches the PayPal Checkout window where the buyer logs in and approves the transaction on the paypal.com website.

    // Order is created on the server and the order id is returned
    createOrder() {
      return fetch("/my-server/create-paypal-order", {
        method: "post",
        headers: {
          "Content-Type": "application/json",
        // use the "body" param to optionally pass additional order information
        // like product skus and quantities
        body: JSON.stringify({
          cart: [
              quantity: "YOUR_PRODUCT_QUANTITY",
      .then((response) => response.json())
      .then((order) => order.id);


The onApprove function is called after the buyer approves the transaction.

Make the capture call from your server to capture the funds from the transaction and show a message to the buyer to let them know the transaction is successful.


When a buyer cancels a payment, they typically return to the parent page. You can instead use the onCancel function to show a cancellation page or return to the shopping cart.

Data attributes

orderId ID of the order.

  onCancel: function (data) {
    // Show a cancel page, or return to cart


If an error prevents buyer checkout, alert the user that an error has occurred with the buttons using the onError callback:

  onError: function (err) {
    // For example, redirect to a specific error page
    window.location.href = "/your-error-page-here";

Note: This error handler is a catch-all. Errors at this point are not expected to be handled beyond showing a generic error message or page.


Before rendering marks and payment fields, you can use paypal.Buttons().isEligible to check if the funding source is eligible.

// Loop over each funding source / payment method
paypal.getFundingSources().forEach(function(fundingSource) {

  // Initialize the buttons
  var button = paypal.Buttons({
    fundingSource: fundingSource

  // Check if the button is eligible
  if (button.isEligible()) {

    // Render the standalone button for that funding source


This table includes the available alternative payment methods.

Funding sourcePayment button

* Important: The SOFORT payment method will be deprecated by the end of September 2024. New integrations can't accept SOFORT payments as of October 20th, 2023.