PayPal Button is a JavaScript library from Datatrans that facilitates the setup, rendering, and usage of PayPal buttons (PayPal, PayPal Pay Later). It acts as a wrapper of both the Datatrans PayPal integration and the PayPal JS SDK and implements all required operations for checkout with PayPal directly from the merchant checkout page.
Process overview
To start a transaction via our Payment Button Integration, you will need to initialize the Payment Button Javascript library and wait for your customer to hit the button provided by the library ¹. We will call your webhook once the transaction has been completed ² and inform your front end again once a transaction has been finalized ³.
PayPal Button integration
To get started, include our PayPal Button script on your web page.
Next, you'll want to initialize the PayPal button. Within PayPalButton.init(), you define various options for script initialization, including the merchantId, the currency, the amount, the settlement option, the option to enable PayPal Pay Later, and whether you want to save a PayPal wallet as a token or not.
You also need to configure various button options, such as the layout, color, shape, and label of your PayPal button. The full list of the available button options is documented here. Make sure to change the refno to a unique value for each transaction.
Handle the creation of the PayPal button by passing a HTML object and your previously defined configuration.
PayPalButton.on("init", function () {
PayPalButton.create(document.getElementById('paypalbutton'), configuration)
});
Success
Listen for the authorization event of the PayPalButton.on() call.
PayPalButton.on("authorization", function (data) {
// handle transaction result
});
Webhook
After processing any transaction via our PayPal Button integration, we will call your webhook with all relevant transaction information. You can define your webhook URL within your merchant configuration. Any server-to-server request to modify an existing transaction has to be made with our transactionId. Please refer to our page After The Payment for more information on actions you can make after a payment has been completed.
Within our Payment Button integration, your webhook will always be called asynchronously after completing a transaction. We only try to call your webhook once. If it fails, no additional calls will be performed.
Showcase & more
For a detailed sample, you can visit our PayPal Button showcase. All events and parameters are explained there in detail too.
Updated about 1 year ago
\n```\n\nNext, you'll want to initialize the PayPal button. Within `PayPalButton.init()`, you define various options for script initialization, including the merchantId, the currency, the amount, the settlement option, the option to enable PayPal Pay Later, and whether you want to save a PayPal wallet as a token or not. \n\nYou also need to configure various button options, such as the layout, color, shape, and label of your PayPal button. The full list of the available button options is documented [here](https://developer.paypal.com/sdk/js/reference/#buttons). Make sure to change the refno to a unique value for each transaction.\n\n```javascript PayPalButton init\nPayPalButton.init({\n merchantId: '{merchantId}',\n currencyCode: 'CHF',\n amount: '100',\n autoSettle: false,\n createAlias: false,\n reqType: 'CAA'\n});\n\nconst configuration = {\n paypaloptions: {\n button: {\n layout: 'vertical',\n color: 'blue',\n shape: 'rect',\n label: 'paypal'\n }\n }, \n transaction: { \n refno: {{reference}},\n authenticationOnly: false,\n returnAddress: true \n }\n}\n```\n\n# Placing the PayPal Button\n\nHandle the creation of the PayPal button by passing a HTML object and your previously defined configuration.\n\n```javascript PayPalButton on\nPayPalButton.on(\"init\", function () {\n PayPalButton.create(document.getElementById('paypalbutton'), configuration)\n});\n```\n\n# Success\n\nListen for the `authorization` event of the `PayPalButton.on()` call.\n\n```javascript\nPayPalButton.on(\"authorization\", function (data) {\n // handle transaction result\n});\n```\n\n# Webhook\n\nAfter processing any transaction via our PayPal Button integration, we will call your webhook with all relevant transaction information. You can define your webhook URL within your merchant configuration. Any server-to-server request to modify an existing transaction has to be made with our `transactionId`. Please refer to our page [After The Payment](doc:after-the-payment) for more information on actions you can make after a payment has been completed. \n\nWithin our Payment Button integration, your webhook will always be called asynchronously after completing a transaction. We only try to call your webhook once. If it fails, no additional calls will be performed.\n\n# Showcase & more\n\nFor a detailed sample, you can visit our [PayPal Button showcase](https://datatrans.github.io/datatrans-paypal-button). All events and parameters are explained there in detail too.","dehydrated":{"toc":"","body":"
PayPal Button is a JavaScript library from Datatrans that facilitates the setup, rendering, and usage of PayPal buttons (PayPal, PayPal Pay Later). It acts as a wrapper of both the Datatrans PayPal integration and the PayPal JS SDK and implements all required operations for checkout with PayPal directly from the merchant checkout page.
\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n
Process overview
\n
To start a transaction via our Payment Button Integration, you will need to initialize the Payment Button Javascript library and wait for your customer to hit the button provided by the library ¹. We will call your webhook once the transaction has been completed ² and inform your front end again once a transaction has been finalized ³.
\n
\n
PayPal Button integration
\n
To get started, include our PayPal Button script on your web page.
Next, you'll want to initialize the PayPal button. Within PayPalButton.init(), you define various options for script initialization, including the merchantId, the currency, the amount, the settlement option, the option to enable PayPal Pay Later, and whether you want to save a PayPal wallet as a token or not.
\n
You also need to configure various button options, such as the layout, color, shape, and label of your PayPal button. The full list of the available button options is documented here. Make sure to change the refno to a unique value for each transaction.
Handle the creation of the PayPal button by passing a HTML object and your previously defined configuration.
\n
PayPalButton.on("init", function () {\n PayPalButton.create(document.getElementById('paypalbutton'), configuration)\n});\n
\n
Success
\n
Listen for the authorization event of the PayPalButton.on() call.
\n
PayPalButton.on("authorization", function (data) {\n // handle transaction result\n});\n
\n
Webhook
\n
After processing any transaction via our PayPal Button integration, we will call your webhook with all relevant transaction information. You can define your webhook URL within your merchant configuration. Any server-to-server request to modify an existing transaction has to be made with our transactionId. Please refer to our page After The Payment for more information on actions you can make after a payment has been completed.
\n
Within our Payment Button integration, your webhook will always be called asynchronously after completing a transaction. We only try to call your webhook once. If it fails, no additional calls will be performed.
\n
Showcase & more
\n
For a detailed sample, you can visit our PayPal Button showcase. All events and parameters are explained there in detail too.
"},"mdx":false,"opts":{"alwaysThrow":false,"compatibilityMode":false,"copyButtons":true,"correctnewlines":false,"markdownOptions":{"fences":true,"commonmark":true,"gfm":true,"ruleSpaces":false,"listItemIndent":"1","spacedTable":true,"paddedTable":true},"normalize":true,"lazyImages":true,"reusableContent":{"tags":{}},"safeMode":false,"settings":{"position":true},"theme":"light","customBlocks":{},"resourceID":"6380d7490916b5083219663d","resourceType":"page","baseUrl":"/","terms":[{"_id":"5af0288f47537800035e5851","term":"uppTransactionId","definition":"The transactionId parameter returned after a payment/registration."},{"_id":"5af029abdf4a8800031c71e8","term":"aliasCC","definition":"An alias of a payment method."},{"_id":"5c6d11162f76cb00139600df","term":"CIT","definition":"Cardholder initiated transaction"},{"_id":"5c6d112fa96ba90033cb426b","term":"MIT","definition":"Merchant initiated transaction"}],"variables":{"user":{},"defaults":[{"_id":"5bbf565ceb416300039a2529","name":"apiReferenceUrl","default":"https://admin.sandbox.datatrans.com/d3574c10-d317-4f6b-82f5-ebc7c2d685af/api-reference/","source":"","type":""},{"_id":"5bbf565ceb416300039a2528","name":"","default":"","source":"","type":""}]}},"terms":[{"_id":"5af0288f47537800035e5851","term":"uppTransactionId","definition":"The transactionId parameter returned after a payment/registration."},{"_id":"5af029abdf4a8800031c71e8","term":"aliasCC","definition":"An alias of a payment method."},{"_id":"5c6d11162f76cb00139600df","term":"CIT","definition":"Cardholder initiated transaction"},{"_id":"5c6d112fa96ba90033cb426b","term":"MIT","definition":"Merchant initiated transaction"}],"variables":{"user":{},"defaults":[{"_id":"5bbf565ceb416300039a2529","name":"apiReferenceUrl","default":"https://admin.sandbox.datatrans.com/d3574c10-d317-4f6b-82f5-ebc7c2d685af/api-reference/","source":"","type":""},{"_id":"5bbf565ceb416300039a2528","name":"","default":"","source":"","type":""}]}},"doc":{"metadata":{"image":[],"title":"","description":"","keywords":"","robots":"index"},"mdx":{"altBody":"","status":"rdmd"},"api":{"method":"get","url":"","auth":"required","results":{"codes":[{"status":200,"language":"json","code":"{}","name":""},{"status":400,"language":"json","code":"{}","name":""}]},"params":[],"examples":{"codes":[]}},"next":{"description":"","pages":[]},"algolia":{"publishPending":false,"recordCount":7,"updatedAt":"2024-05-08T12:45:32.526Z","translationFailure":false},"_id":"6380d7490916b5083219663d","title":"PayPal Button","icon":"","updates":[],"type":"basic","slug":"paypal-button","excerpt":"","body":"PayPal Button is a JavaScript library from Datatrans that facilitates the setup, rendering, and usage of PayPal buttons (PayPal, PayPal Pay Later). It acts as a wrapper of both the Datatrans PayPal integration and the [PayPal JS SDK](https://developer.paypal.com/sdk/js/) and implements all required operations for checkout with PayPal directly from the merchant checkout page.\n\n| | | | |\n| :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n|
|
|
|
|\n\n# Process overview\n\nTo start a transaction via our Payment Button Integration, you will need to _initialize the Payment Button Javascript library_ and wait for your customer to hit the button provided by the library ¹. We will _call your webhook_ once the transaction has been completed ² and _inform your front end_ again once a transaction has been finalized ³.\n\n[block:html]\n{\n \"html\": \"\"\n}\n[/block]\n\n\n# PayPal Button integration\n\nTo get started, include our PayPal Button script on your web page.\n\n```javascript Link our script\n\n```\n\nNext, you'll want to initialize the PayPal button. Within `PayPalButton.init()`, you define various options for script initialization, including the merchantId, the currency, the amount, the settlement option, the option to enable PayPal Pay Later, and whether you want to save a PayPal wallet as a token or not. \n\nYou also need to configure various button options, such as the layout, color, shape, and label of your PayPal button. The full list of the available button options is documented [here](https://developer.paypal.com/sdk/js/reference/#buttons). Make sure to change the refno to a unique value for each transaction.\n\n```javascript PayPalButton init\nPayPalButton.init({\n merchantId: '{merchantId}',\n currencyCode: 'CHF',\n amount: '100',\n autoSettle: false,\n createAlias: false,\n reqType: 'CAA'\n});\n\nconst configuration = {\n paypaloptions: {\n button: {\n layout: 'vertical',\n color: 'blue',\n shape: 'rect',\n label: 'paypal'\n }\n }, \n transaction: { \n refno: {{reference}},\n authenticationOnly: false,\n returnAddress: true \n }\n}\n```\n\n# Placing the PayPal Button\n\nHandle the creation of the PayPal button by passing a HTML object and your previously defined configuration.\n\n```javascript PayPalButton on\nPayPalButton.on(\"init\", function () {\n PayPalButton.create(document.getElementById('paypalbutton'), configuration)\n});\n```\n\n# Success\n\nListen for the `authorization` event of the `PayPalButton.on()` call.\n\n```javascript\nPayPalButton.on(\"authorization\", function (data) {\n // handle transaction result\n});\n```\n\n# Webhook\n\nAfter processing any transaction via our PayPal Button integration, we will call your webhook with all relevant transaction information. You can define your webhook URL within your merchant configuration. Any server-to-server request to modify an existing transaction has to be made with our `transactionId`. Please refer to our page [After The Payment](doc:after-the-payment) for more information on actions you can make after a payment has been completed. \n\nWithin our Payment Button integration, your webhook will always be called asynchronously after completing a transaction. We only try to call your webhook once. If it fails, no additional calls will be performed.\n\n# Showcase & more\n\nFor a detailed sample, you can visit our [PayPal Button showcase](https://datatrans.github.io/datatrans-paypal-button). All events and parameters are explained there in detail too.","order":4,"isReference":false,"deprecated":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"pendingAlgoliaPublish":false,"previousSlug":"","slugUpdatedAt":"2022-11-25T10:34:27.027Z","revision":27,"createdAt":"2022-11-25T14:55:05.981Z","updatedAt":"2024-05-08T12:45:32.534Z","user":"5c2f4a200a4b2c0063a07426","category":{"_id":"62c8500880e0a700815c320f","project":"5a1288ecf49d120012dff9be","version":"62c8500880e0a700815c323c","isAPI":false,"reference":false,"createdAt":"2017-11-20T09:40:08.499Z","from_sync":false,"order":2,"slug":"integrations","title":"Integrations","__v":0,"type":"guide","id":"62c8500880e0a700815c320f"},"project":"5a1288ecf49d120012dff9be","version":{"pdfStatus":"","source":"readme","_id":"62c8500880e0a700815c323c","version":"2.1.0","version_clean":"2.1.0","codename":"New Design","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["62c8500880e0a700815c320d","62c8500880e0a700815c320e","62c8500880e0a700815c320f","5a12a302b57953001cecd09a","62c8500880e0a700815c3210","5a12a319b57953001cecd09d","5a12a31eb57953001cecd09e","62c8500880e0a700815c3211","5ae1da614ee4da0003c98b38","5ec3d8681838e900122691ad","5a12e180ca61dc001ea89591","5a12e1f6ca61dc001ea89592","5a1355fc22131e001204ac39","5a13562945769d002674f9d0","5a1358c522131e001204acc2","5a1358d54e5aed0012b4423d","5a1358e64e5aed0012b4423e","5ec3d8681838e900122691ae","62c8500880e0a700815c3212","5af01dc4df4a8800031c70ff","5b17991b53b0b90003f68b40","5ec3d8681838e900122691b0","5b6d81e0ebb22e0003051748","5b6d886f9218840003992b2b","5c0147688ab18f026df6a28f","5c66b3e4a06714004b3a25d7","5c66b4c2382d410124b9586f","5c6d48085cec4d0019246dd4","5c8a41989bf60e00147b4ac3","5c8f93cba67e3a00fe4c6eeb","5c8fa03a2b8eef00458a6e89","5c98d9f3c17f390167bd4d50","5c993fc486b321000e2c87c3","5c99404714c076002e0bda16","62c8500880e0a700815c3213","6376b41d081e400003bac19e"],"project":"5a1288ecf49d120012dff9be","__v":0,"forked_from":"5ec3d8681838e90012269216","createdAt":"2017-11-20T07:49:01.029Z","releaseDate":"2017-11-20T07:49:01.029Z","apiRegistries":[]},"__v":1,"parentDoc":null,"lastUpdatedHash":"a56a6aeed1da33b2e5cef237b16dafa875197b69","reusableContent":[],"isApi":false,"tutorials":[],"id":"6380d7490916b5083219663d"},"hideTOC":true,"meta":{"_id":"6380d7490916b5083219663d","description":"PayPal Button is a JavaScript library from Datatrans that facilitates the setup, rendering, and usage of PayPal buttons (PayPal, PayPal Pay Later). It acts as a wrapper of both the Datatrans PayPal integration and the PayPal JS SDK and implements all required operations for checkout with PayPal dire...","hidden":false,"image":[],"keywords":"","metaTitle":"PayPal Button","parent":null,"robots":"index","slug":"paypal-button","title":"PayPal Button","type":"docs"},"slugUrl":"/docs/paypal-button","config":{"algoliaIndex":"readme_search_v2","amplitude":{"apiKey":"dc8065a65ef83d6ad23e37aaf014fc84","enabled":true},"asset_url":"https://cdn.readme.io","domain":"readme.io","domainFull":"https://dash.readme.com","encryptedLocalStorageKey":"ekfls-2025-03-27","fullstory":{"enabled":true,"orgId":"FSV9A"},"liveblocks":{"copilotId":"co_11Q0l0JJlkcBhhAYUFh8s"},"metrics":{"billingCronEnabled":"true","dashUrl":"https://m.readme.io","defaultUrl":"https://m.readme.io","exportMaxRetries":12,"wsUrl":"wss://m.readme.io"},"proxyUrl":"https://try.readme.io","readmeRecaptchaSiteKey":"6LesVBYpAAAAAESOCHOyo2kF9SZXPVb54Nwf3i2x","releaseVersion":"5.421.0","sentry":{"dsn":"https://3bbe57a973254129bcb93e47dc0cc46f@o343074.ingest.sentry.io/2052166","enabled":true},"shMigration":{"promoVideo":"","forceWaitlist":false,"migrationPreview":false},"sslBaseDomain":"readmessl.com","sslGenerationService":"ssl.readmessl.com","stripePk":"pk_live_5103PML2qXbDukVh7GDAkQoR4NSuLqy8idd5xtdm9407XdPR6o3bo663C1ruEGhXJjpnb2YCpj8EU1UvQYanuCjtr00t1DRCf2a","superHub":{"newProjectsEnabled":true},"wootric":{"accountToken":"NPS-122b75a4","enabled":true}},"context":{"labs":{},"user":{},"terms":[{"_id":"5af0288f47537800035e5851","term":"uppTransactionId","definition":"The transactionId parameter returned after a payment/registration."},{"_id":"5af029abdf4a8800031c71e8","term":"aliasCC","definition":"An alias of a payment method."},{"_id":"5c6d11162f76cb00139600df","term":"CIT","definition":"Cardholder initiated transaction"},{"_id":"5c6d112fa96ba90033cb426b","term":"MIT","definition":"Merchant initiated transaction"}],"variables":{"user":{},"defaults":[{"_id":"5bbf565ceb416300039a2529","name":"apiReferenceUrl","default":"https://admin.sandbox.datatrans.com/d3574c10-d317-4f6b-82f5-ebc7c2d685af/api-reference/","source":"","type":""},{"_id":"5bbf565ceb416300039a2528","name":"","default":"","source":"","type":""}]},"project":{"_id":"5a1288ecf49d120012dff9be","appearance":{"nextStepsLabel":"","hideTableOfContents":true,"showVersion":false,"html_hidelinks":false,"html_footer_meta":"","html_head":"","html_footer":"","html_body":"","html_promo":"","javascript_hub2":"var paramsBlackList = [\"$formController\",\"version\",\"uppWebResponseMethod\", \"uppMsgType\", \"uppReturnTarget\", \"uppWebResponseMethod\", \"returnCustomerCountry\",\"utm_source\",\"utm_medium\",\"utm_campaign\",\"utm_content\",\"utm_term\",\"merchantId\",\"authorizationCode\", \"responseCode\",\"expy\",\"acqAuthorizationCode\",\"reqtype\",\"expm\",\"pmethod\",\"theme\",\"testOnly\"];\nfunction getQueryParameters(str) {\n \tif(document.location.search == \"\"){\n return (document.location.href).substring(document.location.href.indexOf(\"?\"),document.location.href.length)\n .replace(/(^\\?)/,'')\n .split(\"&\")\n .reduce(function(p,n) {\n return n = n.split(\"=\"), p[n[0]] = n[1], p;\n }, {} );\n }else{\n return (document.location.search)\n .replace(/(^\\?)/,'') \n .split(\"&\")\n .reduce(function(p,n) {\n return n = n.split(\"=\"), p[n[0]] = n[1], p;\n }, {} );\n }\n \n}\n \nfunction hasReturnParams(){\n\tif(window.location.toString().indexOf(\"?\") > 0){\n if(!window.location.toString().includes(\"utm_source\")|| !window.location.toString().includes(\"utm_campaign\") || !window.location.toString().includes(\"utm_content\") || !window.location.toString().includes(\"utm_term\")){\n \treturn true;\n }\n \n }\n \n return false;\n}\n\nfunction escapeHtml(unsafe) {\n return unsafe\n .replace(/&/g, \"&\")\n .replace(//g, \">\")\n .replace(/\"/g, \""\")\n .replace(/'/g, \"'\");\n }\n\nfunction addParamsToForm(params, formId){\n $.each( params, function( key, value ) {\n $('').attr({\n type: 'hidden',\n name: key,\n value: value\n \t}).appendTo(\"#\"+formId);\n\t});\n \n $.each($(\"#paymentForm\").data(),function(key,value){\n $('').attr({\n type: 'hidden',\n name: key,\n value: value\n \t}).appendTo(\"#\"+formId);\n });\n}\nif (window.location.href.indexOf(\"docs/redirect-lightbox\") > -1) { \n $(window).on('pageLoad',function(){\n \t\tif(hasReturnParams()){\n var successParams = \"\";\n var params = getQueryParameters();\n var typeClass = \"type-danger\"\n var message = \" Your transaction failed.\"\n var titleIcon = \"Danger\";\n var iconClass = \"fa-exclamation-triangle\"\n for (var key in params) {\n if(key == \"status\"){\n \tif(params[key] == \"success\"){\n \ttypeClass =\"type-success\";\n titleIcon =\"Success\"\n iconClass =\"fa-check-square\"\n \t\t\tmessage = \" Your transaction was successful.\"\n }\n }\n if(key == \"status\"){\n \tif(params[key] == \"cancel\"){\n \t\t\tmessage = \" Your transaction was canceled.\"\n }\n }\n if(paramsBlackList.indexOf(key) < 0){\n \t\t\t\t \tsuccessParams += key +\"=\"+ escapeHtml(decodeURIComponent(params[key])) + \" \";\n\t\t\t\t }\n }\n if(successParams.length > 1){\n $(\"