UNPKG

@paypal/paypal-js

Version:

Loading wrapper and TypeScript types for the PayPal JS SDK

18 lines (17 loc) 1.95 kB
/*! * paypal-js v9.0.1 (2025-10-03T16:05:19.915Z) * Copyright 2020-present, PayPal, Inc. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ function e(e){var o=e.url,n=e.attributes,r=e.onSuccess,t=e.onError,a=function(e,o){void 0===o&&(o={});var n=document.createElement("script");return n.src=e,Object.keys(o).forEach((function(e){n.setAttribute(e,o[e]),"data-csp-nonce"===e&&n.setAttribute("nonce",o["data-csp-nonce"])})),n}(o,n);a.onerror=t,a.onload=r,document.head.insertBefore(a,document.head.firstElementChild)}"function"==typeof SuppressedError&&SuppressedError;var o="9.0.1";function n(o){void 0===o&&(o={}),function(e){if("object"!=typeof e||null===e)throw new Error("Expected an options object");var o=e.environment;if(o&&"production"!==o&&"sandbox"!==o)throw new Error('The "environment" option must be either "production" or "sandbox"')}(o);var n=o.environment,r=o.debug,t=new URL("/web-sdk/v6/core","production"===n?"https://www.paypal.com":"https://www.sandbox.paypal.com");return r&&t.searchParams.append("debug","true"),new Promise((function(o,n){e({url:t.toString(),onSuccess:function(){return window.paypal?o(window.paypal):n("The window.paypal global variable is not available")},onError:function(){var e=new Error('The script "'.concat(t,'" failed to load. Check the HTTP status code and response body in DevTools to learn more.'));return n(e)}})}))}export{n as loadCoreSdkScript,o as version};