JS SDK Reference
Last updated: Sept 19th, 3:15am
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.
Because this is a client-side call, PayPal calls the Orders API on your behalf, so you don't need to provide the headers and body.
Actions
order
— exposes the create action for creating the order.
1<script>2 paypal.Buttons({3 createOrder: function(data, actions) {4 // Set up the transaction5 return actions.order.create({6 purchase_units: [{7 amount: {8 value: '0.01'9 }10 }]11 });12 }13 }).render('#paypal-button-container');14</script>
actions.order.create
options:
-
intent
— The intent to either capture the payment immediately or authorize a payment for an order after order creation. The values are:CAPTURE
— Default. The merchant intends to capture payment immediately after the customer makes a payment.AUTHORIZE
— Alternative Payment Methods do not support intentAUTHORIZE
-
payer
— The customer who approves and pays for the order. The customer is also known as the payer and buyer. See payer object definition for additional information. -
purchase_units
— Required. An array of purchase units. Each purchase unit establishes a contract between a payer and the payee. Each purchase unit represents either a full or partial order that the payer intends to purchase from the payee. See purchase unit request object definition for additional information. -
application_context
— Customize the payer experience during the approval process for the payment with PayPal. Seeorder_application_context
object definition for additional information.
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 cart4 }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 page4 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 method2paypal.getFundingSources().forEach(function(fundingSource) {34 // Initialize the buttons5 var button = paypal.Buttons({6 fundingSource: fundingSource7 });89 // Check if the button is eligible10 if (button.isEligible()) {1112 // Render the standalone button for that funding source13 button.render('#paypal-button-container');14 }15});
Funding
This table includes the available alternative payment methods.
Funding source | Description |
---|---|
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 |