UNPKG

6.94 kBJavaScriptView Raw
1!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("react"));else if("function"==typeof define&&define.amd)define(["react"],t);else{var n="object"==typeof exports?t(require("react")):t(e.React);for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(self,(function(e){return function(){"use strict";var t={787:function(t){t.exports=e}},n={};function r(e){var o=n[e];if(void 0!==o)return o.exports;var i=n[e]={exports:{}};return t[e](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return function(){r.r(o),r.d(o,{ButtonType:function(){return S},DigitalRiverJS:function(){return s},DropIn:function(){return j},Flow:function(){return b},Usage:function(){return h},useDrjsContext:function(){return d}});var e=r(787),t=r.n(e);function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var i,u,l,c="https://js.digitalriverws.com/v1/DigitalRiver.js",a="https://js.digitalriverws.com/v1/css/DigitalRiver.css",f=(0,e.createContext)({});function s(r){var o,s,d=r.APIKey,v=r.locale,p=void 0===v?"en-us":v,y=r.debug,m=void 0!==y&&y,g=r.children,b=(o=(0,e.useState)(),s=2,function(e){if(Array.isArray(e))return e}(o)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,u,l=[],c=!0,a=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=i.call(n)).done)&&(l.push(r.value),l.length!==t);c=!0);}catch(e){a=!0,o=e}finally{try{if(!c&&null!=n.return&&(u=n.return(),Object(u)!==u))return}finally{if(a)throw o}}return l}}(o,s)||function(e,t){if(e){if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?n(e,t):void 0}}(o,s)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),h=b[0],S=b[1],w=function(e){!1!==m&&window.console.log(e)},O=function(){w("Calling initDRJS"),!h&&window.DigitalRiver&&d&&(w("Initializing DR.JS with"),i=new window.DigitalRiver(d,{locale:p}),S(i))},j=function(){S(null)};(0,e.useEffect)((function(){return function(){u&&(w("Removing JS Script from DOM"),document.head.removeChild(u),u=null),l&&(w("Removing CSS from DOM"),document.head.removeChild(l),l=null)}}),[]),(0,e.useEffect)((function(){if(null===h){if(!u)return w("Downloading JS Script. Adding to Head."),(u=document.createElement("script")).src=c,u.async=!0,u.onload=function(){return O()},document.head.appendChild(u),w("Downloading CSS. Adding to Head."),(l=document.createElement("link")).rel="stylesheet",l.type="text/css",l.href=a,document.head.appendChild(l),function(){};O()}}),[h]),(0,e.useEffect)((function(){j()}),[d,p]);var R={digitalRiver:h,clearDigitalRiver:j,log:w};return w("DR.js RENDER"),t().createElement(f.Provider,{value:R},g)}function d(){return(0,e.useContext)(f)}function v(e){return v="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},v(e)}function p(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function y(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?p(Object(n),!0).forEach((function(t){m(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function m(e,t,n){return(t=function(e){var t=function(e,t){if("object"!==v(e)||null===e)return e;var n=e[Symbol.toPrimitive];if(void 0!==n){var r=n.call(e,"string");if("object"!==v(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"===v(t)?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var g="dr-dropin",b={Checkout:"checkout",ManagePaymentMethods:"managePaymentMethods"},h={Default:"",Subscription:"subscription",Convenience:"convenience",Unscheduled:"unscheduled"},S={PayNow:"payNow",BuyNow:"buyNow",CompleteOrder:"completeOrder",SubmitOrder:"submitOrder",Custom:"custom"},w=null;function O(e){return g+"-"+e}function j(n){var r,o=n.sessionId,i=n.flow,u=void 0===i?b.Checkout:i,l=n.showSavePaymentAgreement,c=void 0!==l&&l,a=n.showComplianceSection,f=void 0===a||a,s=n.showTermsOfSaleDisclosure,v=void 0!==s&&s,p=n.usage,m=void 0===p?h.Default:p,g=n.buttonType,j=void 0===g?S.PayNow:g,R=n.buttonText,D=void 0===R?"":R,C=n.onSuccess,P=void 0===C?function(e){}:C,E=n.onCancel,x=void 0===E?function(){}:E,A=n.onError,I=void 0===A?function(){}:A,T=n.onReady,M=void 0===T?function(){}:T,N=n.options,k=void 0===N?{}:N,J=n.paymentMethodConfiguration,U=void 0===J?{}:J,B=n.billingAddress,H=n.className,_=d();return _.log("app useDrjsContext",_),(0,e.useEffect)((function(){_.log("useEffect app.digitalRiver",_.digitalRiver),_.digitalRiver&&function(){var e=document.getElementById(O(_.digitalRiver.key));if(_.digitalRiver&&e&&null===w){w="LOADING";try{var t={sessionId:o,options:y({flow:u,showSavePaymentAgreement:c,showComplianceSection:f,showTermsOfSaleDisclosure:v,button:{}},k),billingAddress:B,paymentMethodConfiguration:U,onSuccess:function(e){P(e)},onCancel:x,onError:I,onReady:M};m&&(null==m?void 0:m.length)>0&&(t.options.usage=m),t.options.button.type=j,j===S.Custom&&j&&(t.options.button.buttonText=D),_.log("CREATE DROP IN WITH",t),(w=_.digitalRiver.createDropin(t)).mount(e)}catch(e){console.error("An error occurred while mounting Drop In - ",e.message),w=null}}}()}),[_.digitalRiver]),(0,e.useEffect)((function(){return function(){var e,t;_.log("UNMOUNTING.....",null==_||null===(e=_.digitalRiver)||void 0===e?void 0:e.key),function(e){_.log("Clearing DR.JS");var t=document.getElementById(e);_.log("Clearing placeholder...",t),t&&(t.innerHTML=""),w=null}(O(null==_||null===(t=_.digitalRiver)||void 0===t?void 0:t.key))}}),[]),_.log("Rendering with billingAddress",B),t().createElement("div",{className:H,id:O(null==_||null===(r=_.digitalRiver)||void 0===r?void 0:r.key)})}}(),o}()}));
\No newline at end of file