JS SDK Reference for Payment Fields

DOCSCurrent

Last updated: Sept 19th, 7:28pm

Query param Default Description
client-id n/a Your PayPal REST client ID. This identifies your PayPal account and determines where transactions are paid.
components buttons A comma-separated list of components to enable. The buttons, payment-fields, marks, and funding-eligibility components are required for payment fields components.
enable-funding none Funding 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:

currency USD Currency of the transaction.
locale automatic By 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.
intent capture The funds are captured immediately, while the buyer is present on your site.
commit true This indicates that the final amount won't change after the buyer returns from PayPal to your site.
vault false Displays all funding sources including those that don’t support vaulting.

paypal.Buttons(options)

style

Customize your buttons by passing in the style option.

    1paypal.Buttons({
    2 style: {
    3 layout: 'vertical',
    4 label: 'paypal'
    5 }
    6}).render('#paypal-button-container');

    See additional, optional parameters.

    createOrder

    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.

      1<script>
      2 paypal.Buttons({
      3 // Order is created on the server and the order id is returned
      4 createOrder() {
      5 return fetch("/my-server/create-paypal-order", {
      6 method: "post",
      7 headers: {
      8 "Content-Type": "application/json",
      9 },
      10 // use the "body" param to optionally pass additional order information
      11 // like product skus and quantities
      12 body: JSON.stringify({
      13 cart: [
      14 {
      15 sku: "YOUR_PRODUCT_STOCK_KEEPING_UNIT",
      16 quantity: "YOUR_PRODUCT_QUANTITY",
      17 },
      18 ],
      19 }),
      20 })
      21 .then((response) => response.json())
      22 .then((order) => order.id);
      23 },
      24 }).render('#paypal-button-container');
      25</script>

      onApprove

      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.

      onCancel

      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.

        1paypal.Buttons({
        2 onCancel: function (data) {
        3 // Show a cancel page, or return to cart
        4 }
        5}).render('#paypal-button-container');

        onError

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

          1paypal.Buttons({
          2 onError: function (err) {
          3 // For example, redirect to a specific error page
          4 window.location.href = "/your-error-page-here";
          5 }
          6}).render('#paypal-button-container');

          paypal.Buttons().isEligible

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

            1// Loop over each funding source / payment method
            2paypal.getFundingSources().forEach(function(fundingSource) {
            3
            4 // Initialize the buttons
            5 var button = paypal.Buttons({
            6 fundingSource: fundingSource
            7 });
            8
            9 // Check if the button is eligible
            10 if (button.isEligible()) {
            11
            12 // Render the standalone button for that funding source
            13 button.render('#paypal-button-container');
            14 }
            15});

            Funding

            This table includes the available alternative payment methods.

            Funding source Payment button
            paypal.FUNDING.BANCONTACT Bancontact
            paypal.FUNDING.EPS eps
            paypal.FUNDING.GIROPAY giropay
            paypal.FUNDING.IDEAL iDEAL
            paypal.FUNDING.BLIK BLIK
            paypal.FUNDING.MYBANK MyBank
            paypal.FUNDING.P24 Przelewy24
            paypal.FUNDING.SOFORT Sofort (Legacy) *
            paypal.FUNDING.APPLEPAY ApplePay

            We use cookies to improve your experience on our site. May we use marketing cookies to show you personalized ads? Manage all cookies