@paynext/sdk 0.0.64 → 0.0.66

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -482,5 +482,5 @@ React keys must be passed directly to JSX without using spread:
482
482
  <path fill-rule="evenodd" clip-rule="evenodd" d="M133.906 16.9841C136.881 14.9131 139.69 13.765 143.563 13.765C148.897 13.765 150.753 16.3845 150.753 20.3142C150.753 21.4052 150.583 22.9875 150.413 24.0216L147.216 43.6622H136.825L139.801 25.2774C139.855 24.786 139.971 24.1865 139.971 23.8063C139.971 22.3317 139.128 22.0047 138.115 22.0047C136.824 22.0047 135.535 22.5501 134.577 23.0418L131.266 43.6625H120.878L123.854 25.2777C123.908 24.7863 124.02 24.1868 124.02 23.8065C124.02 22.332 123.177 22.0049 122.167 22.0049C120.819 22.0049 119.473 22.6045 118.574 23.0421L115.26 43.6628H104.817L109.589 14.2573H118.52L118.8 16.7122C120.878 15.241 123.684 13.7662 127.446 13.7662C130.704 13.765 132.837 15.129 133.906 16.9841Z" fill="white"/>
483
483
  <path fill-rule="evenodd" clip-rule="evenodd" d="M171.426 25.5502C171.426 23.1496 170.808 21.513 168.956 21.513C164.857 21.513 164.015 28.55 164.015 32.1498C164.015 34.8807 164.802 36.5709 166.653 36.5709C170.528 36.5709 171.426 29.1497 171.426 25.5502ZM153.458 31.7152C153.458 22.442 158.511 13.765 170.136 13.765C178.896 13.765 182.098 18.7854 182.098 25.7148C182.098 34.8805 177.099 44.3723 165.194 44.3723C156.378 44.3723 153.458 38.7525 153.458 31.7152Z" fill="white"/>
484
484
  </svg>`,h="Tap cancel payment to cancel and return to the business. Continue payment will relaunch the payment window.",p=400,m=570,y={backdrop:"venmo-desktop-web-backdrop",backdropHidden:"venmo-desktop-web-backdrop.hidden",backdropContainer:"venmo-backdrop-container",cancelButton:"venmo-popup-cancel-button",continueButton:"venmo-popup-continue-button",message:"venmo-message",instructions:"venmo-instructions",venmoLogo:"venmo-full-logo"};o.suppressUnhandledPromiseMessage=!0;function f(x){var L=x.frameServiceInstance,U=x.venmoUrl,G=x.checkForStatusChange,Y=x.cancelTokenization,j=x.checkPaymentContextStatus,F=new o;return document.getElementById(y.continueButton).addEventListener("click",function(){L.focus()}),document.getElementById(y.cancelButton).addEventListener("click",function(){L.close(),Y(),E()}),L.open({},function(B){var J=1;B?F.reject(B):G(J).then(function(z){F.resolve(z)}).catch(function(z){j().then(function(W){W.status==="CREATED"?F.reject(new d(l.VENMO_CUSTOMER_CANCELED)):F.reject(z)})}),L.close(),E()}),L.redirect(U),F}function g(){var x=Math.round((window.outerHeight-m)/2)+window.screenTop,L=Math.round((window.outerWidth-p)/2)+window.screenLeft;return{top:x,left:L}}function E(){document.getElementById("venmo-desktop-web-backdrop").classList.add("hidden")}function N(){var x=["#"+y.backdropHidden+" {","display: none;","}","#"+y.backdrop+" {","z-index: 3141592632;","cursor: pointer;","position: fixed;","top: 0;","left: 0;","bottom: 0;","width: 100%;","background: rgba(0, 0, 0, 0.8);","}"],L=["#"+y.backdropContainer+" {","display: flex;","align-content: center;","justify-content: center;","align-items: center;","width: 100%;","height: 100%;","flex-direction: column;","}"],U=["#"+y.cancelButton+" {","height: 24px;","width: 380px;","font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;","font-style: normal;","font-weight: 700;","font-size: 18px;","line-height: 24px;","text-align: center;","background-color: transparent;","border: none;","color: #FFFFFF;","margin-top: 28px;","}"],G=["#"+y.continueButton+" {","width: 400px;","height: 50px;","background: #0074DE;","border-radius: 24px;","border: none;","font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;","font-style: normal;","font-weight: 700;","font-size: 18px;","color: #FFFFFF;","margin-top: 44px;","}"],Y=["#"+y.message+" {","font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;","font-style: normal;","font-weight: 500;","font-size: 24px;","line-height: 32px;","text-align: center;","color: #FFFFFF;","margin-top: 32px;","}"],j=["#"+y.instructions+" {","font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;","font-style: normal;","font-weight: 400;","font-size: 16px;","line-height: 20px;","text-align: center;","color: #FFFFFF;","margin-top: 16px;","width: 400px;","}"],F=x.concat(L,U,G,Y,j);return F.join(`
485
- `)}function _(x){var L=document.getElementById(y.backdrop),U,G,Y,j,F,B,J,z;if(L){L.classList.remove("hidden");return}U=document.createElement("style"),G=document.createElement("div"),Y=document.createElement("div"),j=document.createElement("div"),F=document.createElement("div"),B=document.createElement("div"),J=document.createElement("button"),z=document.createElement("button"),x&&(U.nonce=x),U.id="venmo-desktop-web__injected-styles",U.innerHTML=N(),G.id=y.backdrop,Y.id=y.backdropContainer,j.id=y.venmoLogo,j.innerHTML=u,F.id=y.message,F.innerText="What would you like to do?",B.id=y.instructions,B.innerText=h,J.id=y.continueButton,J.innerText="Continue payment",z.id=y.cancelButton,z.innerText="Cancel payment",document.head.appendChild(U),Y.appendChild(j),Y.appendChild(F),Y.appendChild(B),Y.appendChild(J),Y.appendChild(z),G.appendChild(Y),document.body.appendChild(G),G.addEventListener("click",function(W){W.stopPropagation()})}function I(x){return _(x.styleCspNonce),f(x)}function R(x){var L=new o,U="venmoDesktopWebLogin",G=x.assetsUrl,Y=x.debug||!1,j=g(),F=G+"/web/"+c+"/html";return n.create({name:U,dispatchFrameUrl:F+"/dispatch-frame"+s(Y)+".html",openFrameUrl:F+"/venmo-landing-frame"+s(Y)+".html",top:j.top,left:j.left,height:m,width:p},function(B){L.resolve(B)}),L}r.exports={runWebLogin:I,openPopup:f,setupDesktopWebLogin:R,POPUP_WIDTH:p,POPUP_HEIGHT:m}},{"../../lib/braintree-error":59,"../../lib/frame-service/external":68,"../../lib/use-min":85,"../shared/errors":93,"@braintree/extended-promise":26}],98:[function(a,r,i){var n=a("../lib/analytics"),s=a("../lib/assign").assign,o=a("./shared/supports-venmo"),l=a("./shared/browser-detection"),d=a("./shared/constants"),c=a("./shared/errors"),u=a("../lib/querystring"),h=a("../lib/is-verified-domain"),p=a("../lib/methods"),m=a("../lib/convert-methods-to-error"),y=a("@braintree/wrap-promise"),f=a("../lib/braintree-error"),g=a("../lib/in-iframe"),E=a("@braintree/extended-promise"),N=a("./shared/get-venmo-url"),_=a("./shared/web-login-backdrop"),I=a("../lib/snake-case-to-camel-case"),R=a("../lib/url-params"),x=a("./external/"),L=a("./external/queries"),U="3.126.0",G=250,Y=3e5;E.suppressUnhandledPromiseMessage=!0;function j(k){var v=this;this._allowDesktopWebLogin=k.allowDesktopWebLogin||!1,this._mobileWebFallBack=k.mobileWebFallBack||!1,this._createPromise=k.createPromise,this._allowNewBrowserTab=k.allowNewBrowserTab!==!1,this._allowWebviews=k.allowWebviews!==!1,this._allowDesktop=k.allowDesktop===!0,this._useRedirectForIOS=k.useRedirectForIOS===!0,this._profileId=k.profileId,this._displayName=k.displayName,this._deepLinkReturnUrl=k.deepLinkReturnUrl,this._ignoreHistoryChanges=k.ignoreHistoryChanges,this._paymentMethodUsage=(k.paymentMethodUsage||"").toUpperCase(),this._shouldUseLegacyFlow=!this._paymentMethodUsage,this._requireManualReturn=k.requireManualReturn===!0,this._useDesktopQRFlow=this._allowDesktop&&this._isDesktop()&&!this._allowDesktopWebLogin,this._useAllowDesktopWebLogin=this._allowDesktopWebLogin&&this._isDesktop(),this._cannotHaveReturnUrls=g()||this._requireManualReturn,this._allowAndroidRecreation=k.allowAndroidRecreation!==!1,this._maxRetryCount=3,this._collectCustomerBillingAddress=k.collectCustomerBillingAddress||!1,this._collectCustomerShippingAddress=k.collectCustomerShippingAddress||!1,this._isFinalAmount=k.isFinalAmount||!1,this._lineItems=k.lineItems,this._subTotalAmount=k.subTotalAmount,this._discountAmount=k.discountAmount,this._taxAmount=k.taxAmount,this._shippingAmount=k.shippingAmount,this._totalAmount=k.totalAmount,this._cspNonce=(this._mobileWebFallBack||this._allowDesktopWebLogin)&&(k.styleCspNonce||!1),this._shouldCreateVenmoPaymentContext=this._cannotHaveReturnUrls||!this._shouldUseLegacyFlow,n.sendEvent(this._createPromise,"venmo.desktop-flow.configured."+String(!!this._allowDesktop)),this.hasTokenizationResult()?n.sendEvent(this._createPromise,"venmo.appswitch.return-in-new-tab"):this._useDesktopQRFlow?this._createPromise=this._createPromise.then(function(O){var M=O.getConfiguration().gatewayConfiguration;return x({url:M.assetsUrl+"/web/"+U+"/html/venmo-desktop-frame.html",environment:M.environment==="production"?"PRODUCTION":"SANDBOX",profileId:v._profileId||M.payWithVenmo.merchantId,paymentMethodUsage:v._paymentMethodUsage,displayName:v._displayName,Promise,apiRequest:function(P,T){return O.request({api:"graphQLApi",data:{query:P,variables:T}}).then(function(b){return b.data})},sendEvent:function(P){n.sendEvent(v._createPromise,P)},verifyDomain:h}).then(function(P){return v._venmoDesktopInstance=P,n.sendEvent(v._createPromise,"venmo.desktop-flow.presented"),O}).catch(function(){return n.sendEvent(v._createPromise,"venmo.desktop-flow.setup-failed"),v._useDesktopQRFlow=!1,O})}):this._shouldCreateVenmoPaymentContext&&(this._mobilePollingInterval=G,this._mobilePollingExpiresThreshold=Y,this._createPromise=this._createPromise.then(function(O){var M,P,T=v._cannotHaveReturnUrls?"manual-return":"mobile-payment-context",b=O.getConfiguration();return P=_.setupDesktopWebLogin({assetsUrl:b.gatewayConfiguration.assetsUrl,debug:b.isDebug}).then(function(w){v._frameServiceInstance=w}).catch(function(w){return w}),v._mobilePollingContextEnvironment=b.gatewayConfiguration.environment.toUpperCase(),M=v._createVenmoPaymentContext(O).then(function(){return n.sendEvent(v._createPromise,"venmo."+T+".presented"),O}).catch(function(w){return n.sendEvent(v._createPromise,"venmo."+T+".setup-failed"),Promise.reject(new f({type:c.VENMO_MOBILE_PAYMENT_CONTEXT_SETUP_FAILED.type,code:c.VENMO_MOBILE_PAYMENT_CONTEXT_SETUP_FAILED.code,message:F(w)?w.details.originalError[0].message:c.VENMO_MOBILE_PAYMENT_CONTEXT_SETUP_FAILED.message,details:{originalError:w}}))}),E.all([P,M]).then(function(w){var S=w[1];return Promise.resolve(S)}).catch(function(w){return Promise.reject(w)})}))}function F(k){return k.details&&k.details.originalError&&k.details.originalError[0]&&k.details.originalError[0].extensions&&k.details.originalError[0].extensions.errorClass==="VALIDATION"&&k.details.originalError[0].extensions.errorType==="user_error"}j.prototype._createVenmoPaymentContext=function(k,v){var O=this,M,P,T=k.getConfiguration(),b=T.gatewayConfiguration.payWithVenmo,w=!1,S=O._useAllowDesktopWebLogin?"NATIVE_WEB":"MOBILE_WEB";if(!this._shouldCreateVenmoPaymentContext)return Promise.resolve();if(this._shouldUseLegacyFlow)M=k.request({api:"graphQLApi",data:{query:L.LEGACY_CREATE_PAYMENT_CONTEXT_QUERY,variables:{input:{environment:this._mobilePollingContextEnvironment,intent:"PAY_FROM_APP"}}}}).then(function(C){return C.data.createVenmoQRCodePaymentContext.venmoQRCodePaymentContext});else{if((this._collectCustomerBillingAddress||this._collectCustomerShippingAddress)&&!b.enrichedCustomerDataEnabled)return Promise.reject(new f(c.VENMO_ECD_DISABLED));this._lineItems&&this._lineItems.forEach(function(C){C.unitTaxAmount=C.unitTaxAmount||"0"}),P={subTotalAmount:this._subTotalAmount,discountAmount:this._discountAmount,taxAmount:this._taxAmount,shippingAmount:this._shippingAmount,totalAmount:this._totalAmount,lineItems:this._lineItems},w=Object.keys(P).some(function(C){return P[C]!==void 0}),M=k.request({api:"graphQLApi",data:{query:L.CREATE_PAYMENT_CONTEXT_QUERY,variables:{input:{paymentMethodUsage:this._paymentMethodUsage,intent:"CONTINUE",customerClient:S,isFinalAmount:this._isFinalAmount,displayName:this._displayName,paysheetDetails:{collectCustomerBillingAddress:this._collectCustomerBillingAddress,collectCustomerShippingAddress:this._collectCustomerShippingAddress,transactionDetails:w?P:void 0}}}}}).then(function(C){return C.data.createVenmoPaymentContext.venmoPaymentContext})}return M.then(function(C){var V=new Date(C.expiresAt)-new Date(C.createdAt),$=V*.6666;clearTimeout(O._refreshPaymentContextTimeout),O._refreshPaymentContextTimeout=setTimeout(function(){O._tokenizationInProgress||O._createVenmoPaymentContext(k,!0)},$),!(v&&O._tokenizationInProgress)&&(O._venmoPaymentContextStatus=C.status,O._venmoPaymentContextId=C.id)})},j.prototype._popupBridgeIsInstalled=function(){return window.popupBridge&&typeof window.popupBridge.open=="function"},j.prototype._venmoNativeAppIsInstalled=function(){return!!(window.popupBridge&&(window.parent&&window.parent.popupBridge.isVenmoInstalled||window.popupBridge.isVenmoInstalled))},j.prototype._handleDeepLinkAppSwitch=function(k){q()?this._handleIosWebviewDeepLink(k):this._popupBridgeIsInstalled()?this._handlePopupBridgeAppSwitch(k):(n.sendEvent(this._createPromise,"venmo.appswitch.start.webview"),this._venmoWindow=window.open(k))},j.prototype._handleIosWebviewDeepLink=function(k){n.sendEvent(this._createPromise,"venmo.appswitch.start.ios-webview"),g()?this._handleIosWebviewInIframe(k):!this._venmoNativeAppIsInstalled()&&this._popupBridgeIsInstalled()?this._handlePopupBridgeAppSwitch(k):window.location.href=k},j.prototype._handleIosWebviewInIframe=function(k){this._venmoNativeAppIsInstalled()?this._handleIFrameBreakout(k):this._popupBridgeIsInstalled()?this._handlePopupBridgeAppSwitch(k):this._handleIFrameBreakout(k)},j.prototype._handlePopupBridgeAppSwitch=function(k){n.sendEvent(this._createPromise,"venmo.appswitch.start.popup-bridge"),window.popupBridge.open(k)},j.prototype._handleBrowserAppSwitch=function(k){n.sendEvent(this._createPromise,"venmo.appswitch.start.browser"),l.doesNotSupportWindowOpenInIos()||this._shouldUseRedirectStrategy()||this._mobileWebFallBack&&l.isAndroid()&&l.isChrome()?window.location.href=k:this._venmoWindow=window.open(k)},j.prototype._handleIFrameBreakout=function(k){window.top.location.href=k},j.prototype.appSwitch=function(k){this._deepLinkReturnUrl?this._handleDeepLinkAppSwitch(k):this._handleBrowserAppSwitch(k)},j.prototype.getUrl=function(){return this._createPromise.then(function(k){var v=k.getConfiguration(),O={},M=this._deepLinkReturnUrl||window.location.href.replace(window.location.hash,""),P=v.gatewayConfiguration.payWithVenmo,T=v.analyticsMetadata,b=P.accessToken,w={_meta:{version:T.sdkVersion,integration:T.integration,platform:T.platform,sessionId:T.sessionId}};return this._isDebug=v.isDebug,this._assetsUrl=v.gatewayConfiguration.assetsUrl,M=M.replace(/#*$/,""),this._venmoPaymentContextId&&(this._shouldUseLegacyFlow?b+="|pcid:"+this._venmoPaymentContextId:O.resource_id=this._venmoPaymentContextId),this._shouldIncludeReturnUrls()||this._useAllowDesktopWebLogin?(this._useAllowDesktopWebLogin&&(M=this._assetsUrl+"/web/"+U+"/html/redirect-frame.html"),O["x-success"]=M+"#venmoSuccess=1",O["x-cancel"]=M+"#venmoCancel=1",O["x-error"]=M+"#venmoError=1"):(O["x-success"]="NOOP",O["x-cancel"]="NOOP",O["x-error"]="NOOP"),this._allowAndroidRecreation?O.allowAndroidRecreation=1:O.allowAndroidRecreation=0,O.ua=window.navigator.userAgent,O.braintree_merchant_id=this._profileId||P.merchantId,O.braintree_access_token=b,O.braintree_environment=P.environment,O.braintree_sdk_data=btoa(JSON.stringify(w)),N({useAllowDesktopWebLogin:this._useAllowDesktopWebLogin,mobileWebFallBack:this._mobileWebFallBack})+"?"+u.stringify(O)}.bind(this))},j.prototype.isBrowserSupported=function(){return o.isBrowserSupported({allowNewBrowserTab:this._allowNewBrowserTab,allowWebviews:this._allowWebviews,allowDesktop:this._allowDesktop,allowDesktopWebLogin:this._allowDesktopWebLogin})},j.prototype.hasTokenizationResult=function(){return this._hasTokenizationResult()},j.prototype._hasTokenizationResult=function(k){var v=B(k),O=R.getUrlParams();return O.resource_id?this._venmoPaymentContextId=O.resource_id:v.id&&(this._venmoPaymentContextId=v.id),typeof(v.venmoSuccess||v.venmoError||v.venmoCancel)!="undefined"},j.prototype._shouldIncludeReturnUrls=function(){return this._deepLinkReturnUrl?!0:!this._cannotHaveReturnUrls},j.prototype._isDesktop=function(){return!(l.isIos()||l.isAndroid())},j.prototype.tokenize=function(k){var v=this,O;return k=k||{},this._tokenizationInProgress===!0?Promise.reject(new f(c.VENMO_TOKENIZATION_REQUEST_ACTIVE)):(this._tokenizationInProgress=!0,this._useDesktopQRFlow?O=this._tokenizeForDesktopQRFlow(k):this._useAllowDesktopWebLogin?O=this._tokenizeWebLoginWithRedirect(k):this._cannotHaveReturnUrls?O=this._tokenizeForMobileWithManualReturn():O=this._tokenizeForMobileWithHashChangeListeners(k),O.then(function(M){return v._createPromise.then(function(P){return v._createVenmoPaymentContext(P)}).then(function(){return v._tokenizationInProgress=!1,v._venmoWindow=null,z(M)})}).catch(function(M){return v._createPromise.then(function(P){return v._createVenmoPaymentContext(P)}).then(function(){return v._tokenizationInProgress=!1,v._venmoWindow=null,Promise.reject(M)})}))},j.prototype.cancelTokenization=function(){return this._tokenizationInProgress?(this._removeVisibilityEventListener(),this._tokenizePromise&&this._tokenizePromise.reject(new f(c.VENMO_TOKENIZATION_CANCELED_BY_MERCHANT)),Promise.all([this._cancelMobilePaymentContext(),this._cancelVenmoDesktopContext()])):Promise.reject(new f(c.VENMO_TOKENIZATION_REQUEST_NOT_ACTIVE))},j.prototype._tokenizeWebLoginWithRedirect=function(){var k=this,v;return n.sendEventPlus(k._createPromise,"venmo.tokenize.web-login.start",{context_id:k._venmoPaymentContextId}),this._tokenizePromise=new E,this.getUrl().then(function(O){return v={checkForStatusChange:k._checkPaymentContextStatusAndProcessResult.bind(k),cancelTokenization:k.cancelTokenization.bind(k),frameServiceInstance:k._frameServiceInstance,venmoUrl:O,debug:k._isDebug,checkPaymentContextStatus:k._checkPaymentContextStatus.bind(k)},k._cspNonce&&(v=s({},v,{styleCspNonce:k._cspNonce})),_.runWebLogin(v).then(function(M){n.sendEventPlus(k._createPromise,"venmo.tokenize.web-login.success",{context_id:k._venmoPaymentContextId}),k._tokenizePromise.resolve({paymentMethodNonce:M.paymentMethodId,username:M.userName,payerInfo:M.payerInfo,id:k._venmoPaymentContextId})}).catch(function(M){n.sendEventPlus(k._createPromise,"venmo.tokenize.web-login.failure",{context_id:k._venmoPaymentContextId}),k._tokenizePromise.reject(M)}),k._tokenizePromise})},j.prototype._queryPaymentContextStatus=function(k){var v=this;return this._createPromise.then(function(O){var M=v._shouldUseLegacyFlow?L.LEGACY_VENMO_PAYMENT_CONTEXT_STATUS_QUERY:L.VENMO_PAYMENT_CONTEXT_STATUS_QUERY;return O.request({api:"graphQLApi",data:{query:M,variables:{id:k}}})}).then(function(O){return O.data.node})},j.prototype._checkPaymentContextStatusAndProcessResult=function(k){var v=this;return v._checkPaymentContextStatus().then(function(O){var M=O.status;if(M!==v._venmoPaymentContextStatus)switch(v._venmoPaymentContextStatus=M,n.sendEventPlus(v._createPromise,"venmo.tokenize.web-login.status-change",{context_id:v._venmoPaymentContextId}),M){case"APPROVED":return Promise.resolve(O);case"CANCELED":return Promise.reject(new f(c.VENMO_CUSTOMER_CANCELED));case"FAILED":return Promise.reject(new f(c.VENMO_TOKENIZATION_FAILED))}return new Promise(function(P,T){k<v._maxRetryCount?(k++,v._checkPaymentContextStatusAndProcessResult(k).then(P).catch(T)):T(new f(c.VENMO_TOKENIZATION_FAILED))})})},j.prototype._checkPaymentContextStatus=function(){var k=this;return k._queryPaymentContextStatus(k._venmoPaymentContextId).catch(function(v){return Promise.reject(new f({type:c.VENMO_NETWORK_ERROR.type,code:c.VENMO_NETWORK_ERROR.code,message:c.VENMO_NETWORK_ERROR.message,details:v}))}).then(function(v){return Promise.resolve(v)})},j.prototype._pollForStatusChange=function(){var k=this;return k._venmoPaymentContextId?Date.now()>k._mobilePollingContextExpiresIn?Promise.reject(new f(c.VENMO_MOBILE_POLLING_TOKENIZATION_TIMEOUT)):k._venmoWindow&&k._venmoWindow.closed&&k._venmoPaymentContextStatus==="CREATED"?(n.sendEvent(k._createPromise,"venmo.appswitch.browser-window.closed"),k._cancelMobilePaymentContext().then(function(){n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.canceled",{context_id:k._venmoPaymentContextId})}).catch(function(v){n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.canceled.error",{context_id:k._venmoPaymentContextId})}),Promise.reject(new f(c.VENMO_MOBILE_POLLING_TOKENIZATION_CANCELED))):this._queryPaymentContextStatus(this._venmoPaymentContextId).catch(function(v){return Promise.reject(new f({type:c.VENMO_MOBILE_POLLING_TOKENIZATION_NETWORK_ERROR.type,code:c.VENMO_MOBILE_POLLING_TOKENIZATION_NETWORK_ERROR.code,message:c.VENMO_MOBILE_POLLING_TOKENIZATION_NETWORK_ERROR.message,details:{originalError:v}}))}).then(function(v){var O=v.status;if(O!==k._venmoPaymentContextStatus)switch(k._venmoPaymentContextStatus=O,n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.status-change."+O.toLowerCase(),{context_id:k._venmoPaymentContextId}),O){case"EXPIRED":case"FAILED":case"CANCELED":return Promise.reject(new f(c["VENMO_MOBILE_POLLING_TOKENIZATION_"+O]));case"APPROVED":return Promise.resolve(v)}return new Promise(function(M,P){setTimeout(function(){k._pollForStatusChange().then(M).catch(P)},k._mobilePollingInterval)})}):Promise.reject(new f(c.VENMO_MOBILE_POLLING_TOKENIZATION_NO_CONTEXT_ID))},j.prototype._tokenizeForMobileWithManualReturn=function(){var k=this;return n.sendEventPlus(this._createPromise,"venmo.tokenize.manual-return.start",{context_id:k._venmoPaymentContextId}),this._mobilePollingContextExpiresIn=Date.now()+this._mobilePollingExpiresThreshold,this._tokenizePromise=new E,this._pollForStatusChange().then(function(v){n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.success",{context_id:k._venmoPaymentContextId}),k._tokenizePromise.resolve({paymentMethodNonce:v.paymentMethodId,username:v.userName,payerInfo:v.payerInfo,id:k._venmoPaymentContextId})}).catch(function(v){n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.failure",{context_id:k._venmoPaymentContextId}),k._tokenizePromise.reject(v)}),this.getUrl().then(function(v){return k.appSwitch(v),k._tokenizePromise})},j.prototype._shouldUseRedirectStrategy=function(){return l.isIos()?this._mobileWebFallBack===!0?!0:this._useRedirectForIOS:!1},j.prototype._tokenizeForMobileWithHashChangeListeners=function(k){var v=this,O,M;if(this.hasTokenizationResult())return this.processHashChangeFlowResults();n.sendEvent(this._createPromise,"venmo.tokenize.mobile.start"),this._tokenizePromise=new E,this._previousHash=window.location.hash;function P(T){var b;v.processHashChangeFlowResults(T).catch(function(w){b=w}).then(function(w){!v._ignoreHistoryChanges&&window.location.hash!==v._previousHash&&(window.location.hash=v._previousHash),v._removeVisibilityEventListener(),b?v._tokenizePromise.reject(b):v._tokenizePromise.resolve(w),delete v._tokenizePromise})}return this._onHashChangeListener=function(T){var b=T.newURL.split("#")[1];v._hasTokenizationResult(b)&&(O=!0,clearTimeout(M),P(b))},window.addEventListener("hashchange",this._onHashChangeListener,!1),this._visibilityChangeListener=function(){var T=k.processResultsDelay||d.DEFAULT_PROCESS_RESULTS_DELAY;window.document.hidden||(v._venmoWindow&&!v._venmoWindow.closed&&v._venmoWindow.close(),O||(M=setTimeout(P,T)))},this.getUrl().then(function(T){return v.appSwitch(T),setTimeout(function(){window.document.addEventListener(W(),v._visibilityChangeListener)},d.DOCUMENT_VISIBILITY_CHANGE_EVENT_DELAY),v._tokenizePromise})},j.prototype._tokenizeForDesktopQRFlow=function(){var k=this;return n.sendEvent(this._createPromise,"venmo.tokenize.desktop.start"),this._tokenizePromise=new E,this._createPromise.then(function(){return k._venmoDesktopInstance.launchDesktopFlow()}).then(function(v){k._venmoDesktopInstance.hideDesktopFlow(),n.sendEvent(k._createPromise,"venmo.tokenize.desktop.success"),k._tokenizePromise.resolve(v)}).catch(function(v){if(n.sendEvent(k._createPromise,"venmo.tokenize.desktop.failure"),k._venmoDesktopInstance&&k._venmoDesktopInstance.hideDesktopFlow(),v&&v.reason==="CUSTOMER_CANCELED"){k._tokenizePromise.reject(new f(c.VENMO_DESKTOP_CANCELED));return}k._tokenizePromise.reject(new f({type:c.VENMO_DESKTOP_UNKNOWN_ERROR.type,code:c.VENMO_DESKTOP_UNKNOWN_ERROR.code,message:c.VENMO_DESKTOP_UNKNOWN_ERROR.message,details:{originalError:v}}))}),this._tokenizePromise},j.prototype._cancelMobilePaymentContext=function(){var k=this;return this._createPromise.then(function(v){var O;return k._venmoPaymentContextId?(O=k._shouldUseLegacyFlow?L.LEGACY_UPDATE_PAYMENT_CONTEXT_QUERY:L.UPDATE_PAYMENT_CONTEXT_QUERY,v.request({api:"graphQLApi",data:{query:O,variables:{input:{id:k._venmoPaymentContextId,status:"CANCELED"}}}})):Promise.resolve()})},j.prototype._cancelVenmoDesktopContext=function(){var k=this;return this._createPromise.then(function(){return k._venmoDesktopInstance&&k._venmoDesktopInstance.updateVenmoDesktopPaymentContext("CANCELED"),Promise.resolve()})},j.prototype.teardown=function(){var k=this;return this._removeVisibilityEventListener(),this._createPromise.then(function(){k._venmoDesktopInstance&&k._venmoDesktopInstance.teardown(),clearTimeout(k._refreshPaymentContextTimeout),k._cancelMobilePaymentContext(),m(this,p(j.prototype))}.bind(this))},j.prototype._removeVisibilityEventListener=function(){window.removeEventListener("hashchange",this._onHashChangeListener),window.document.removeEventListener(W(),this._visibilityChangeListener),delete this._visibilityChangeListener,delete this._onHashChangeListener},j.prototype.processHashChangeFlowResults=function(k){var v=this,O=B(k);return new Promise(function(M,P){v._shouldUseLegacyFlow?O.venmoSuccess?(n.sendEvent(v._createPromise,"venmo.appswitch.handle.success"),window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:succeeded"),M(O)):O.venmoError?(n.sendEvent(v._createPromise,"venmo.appswitch.handle.error"),window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:failed"),P(new f({type:c.VENMO_APP_FAILED.type,code:c.VENMO_APP_FAILED.code,message:c.VENMO_APP_FAILED.message,details:{originalError:{message:decodeURIComponent(O.errorMessage),code:O.errorCode}}}))):O.venmoCancel?(n.sendEvent(v._createPromise,"venmo.appswitch.handle.cancel"),window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:canceled"),P(new f(c.VENMO_APP_CANCELED))):(n.sendEvent(v._createPromise,"venmo.appswitch.cancel-or-unavailable"),P(new f(c.VENMO_CANCELED))):v._pollForStatusChange().then(function(T){return n.sendEventPlus(v._createPromise,"venmo.appswitch.handle.payment-context-status-query.success",{context_id:v._venmoPaymentContextId}),window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:succeeded"),M({paymentMethodNonce:T.paymentMethodId,username:T.userName,payerInfo:T.payerInfo,id:v._venmoPaymentContextId})}).catch(function(T){T.code===c.VENMO_MOBILE_POLLING_TOKENIZATION_CANCELED.code?(window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:canceled"),P(T)):window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:failed"),n.sendEventPlus(v._createPromise,"venmo.process-results.payment-context-status-query-failed",{context_id:v._venmoPaymentContextId}),M(O)}),v._clearFragmentParameters()})},j.prototype._clearFragmentParameters=function(){this._ignoreHistoryChanges||typeof window.history.replaceState=="function"&&window.location.hash&&history.pushState({},"",window.location.href.slice(0,window.location.href.indexOf("#")))};function B(k){var v=(k||window.location.hash.substring(1)).split("&"),O=v.reduce(function(M,P){var T=P.split("="),b=decodeURIComponent(T[0]).replace(/\W/g,""),w=I(b),S=decodeURIComponent(T[1]);return M[w]=S,M},{});return O.resourceId&&(O.id=O.resourceId),O}function J(k){return k=k||"","@"+k.replace("@","")}function z(k){var v={nonce:k.paymentMethodNonce,type:"VenmoAccount",details:{username:J(k.username),paymentContextId:k.id}};return k.payerInfo&&(v.details.payerInfo=k.payerInfo,v.details.payerInfo.userName=J(k.payerInfo.userName)),v}function W(){var k;return typeof window.document.hidden!="undefined"?k="visibilitychange":typeof window.document.msHidden!="undefined"?k="msvisibilitychange":typeof window.document.webkitHidden!="undefined"&&(k="webkitvisibilitychange"),k}function q(){return window.navigator.platform&&/iPhone|iPad|iPod/.test(window.navigator.platform)}r.exports=y.wrapPrototype(j)},{"../lib/analytics":55,"../lib/assign":57,"../lib/braintree-error":59,"../lib/convert-methods-to-error":61,"../lib/in-iframe":78,"../lib/is-verified-domain":79,"../lib/methods":81,"../lib/querystring":82,"../lib/snake-case-to-camel-case":83,"../lib/url-params":84,"./external/":87,"./external/queries":88,"./shared/browser-detection":91,"./shared/constants":92,"./shared/errors":93,"./shared/get-venmo-url":95,"./shared/supports-venmo":96,"./shared/web-login-backdrop":97,"@braintree/extended-promise":26,"@braintree/wrap-promise":35}]},{},[90])(90)})}(xt)),xt.exports}var Qd=$d();const Zd=kt(Qd);class Xd{constructor(){A(this,"client",null);A(this,"venmoInstance",null);A(this,"deviceData",null)}init(e){return H(this,null,function*(){try{this.client=yield Hd.create({authorization:e.authorization});try{const a=yield Wd.create({client:this.client,paypal:!0});this.deviceData=a.deviceData||null}catch(a){console.warn("Braintree device data collection failed:",a),this.deviceData=null}}catch(a){throw console.error("Failed to initialize Braintree client:",a),a}})}createVenmo(e){return H(this,null,function*(){if(!this.client)throw new Error("Braintree client must be initialized before creating Venmo instance");try{return this.venmoInstance=yield Zd.create(K({client:this.client,allowDesktop:!0,mobileWebFallBack:!0,allowDesktopWebLogin:!0,paymentMethodUsage:"multi_use"},e)),this.venmoInstance}catch(a){throw console.error("Failed to create Venmo instance:",a),a}})}isBrowserSupported(){var e,a;return(a=(e=this.venmoInstance)==null?void 0:e.isBrowserSupported())!=null?a:!1}hasTokenizationResult(){var e,a;return(a=(e=this.venmoInstance)==null?void 0:e.hasTokenizationResult())!=null?a:!1}tokenize(){return H(this,null,function*(){if(!this.venmoInstance)throw new Error("Venmo instance not initialized");return new Promise((e,a)=>{this.venmoInstance.tokenize(void 0,(r,i)=>{if(r)a(r);else{const n=ee(K({},i),{device_data:this.deviceData||void 0}),s=i,o=(s==null?void 0:s.billingAddress)||(s==null?void 0:s.billing_address);if(o){const l={city:o.adminArea2,country:o.countryCode,line1:o.line1,line2:o.line2,postal_code:o.postalCode,state:o.adminArea1};n.billing_address=l}e(n)}})})})}}class Fn{constructor(){A(this,"ev",new ii);A(this,"paypal",new Ud);A(this,"braintree",new Xd);A(this,"state",{translate:new xd,checkout:new kd,transaction:new Ed,styles:new Cd});A(this,"checkout",new Pd({state:this.state,service:{ev:this.ev,paypal:this.paypal,braintree:this.braintree}}))}clearState(){Object.values(this.state).forEach(e=>e.clearState())}}class Jd{constructor(e){A(this,"parent");A(this,"core",new Fn);this.parent=e}mount(e){return H(this,null,function*(){const a=yield this.core.checkout.mount();this.parent.innerHTML="",this.parent.appendChild(a),this.core.state.checkout.setState(e)})}unmount(){return H(this,null,function*(){this.parent.innerHTML="",this.core.clearState()})}}re.Core=Fn,re.PayNextCheckout=Jd,re.PaymentMethod=te,Object.defineProperty(re,Symbol.toStringTag,{value:"Module"})});
485
+ `)}function _(x){var L=document.getElementById(y.backdrop),U,G,Y,j,F,B,J,z;if(L){L.classList.remove("hidden");return}U=document.createElement("style"),G=document.createElement("div"),Y=document.createElement("div"),j=document.createElement("div"),F=document.createElement("div"),B=document.createElement("div"),J=document.createElement("button"),z=document.createElement("button"),x&&(U.nonce=x),U.id="venmo-desktop-web__injected-styles",U.innerHTML=N(),G.id=y.backdrop,Y.id=y.backdropContainer,j.id=y.venmoLogo,j.innerHTML=u,F.id=y.message,F.innerText="What would you like to do?",B.id=y.instructions,B.innerText=h,J.id=y.continueButton,J.innerText="Continue payment",z.id=y.cancelButton,z.innerText="Cancel payment",document.head.appendChild(U),Y.appendChild(j),Y.appendChild(F),Y.appendChild(B),Y.appendChild(J),Y.appendChild(z),G.appendChild(Y),document.body.appendChild(G),G.addEventListener("click",function(W){W.stopPropagation()})}function I(x){return _(x.styleCspNonce),f(x)}function R(x){var L=new o,U="venmoDesktopWebLogin",G=x.assetsUrl,Y=x.debug||!1,j=g(),F=G+"/web/"+c+"/html";return n.create({name:U,dispatchFrameUrl:F+"/dispatch-frame"+s(Y)+".html",openFrameUrl:F+"/venmo-landing-frame"+s(Y)+".html",top:j.top,left:j.left,height:m,width:p},function(B){L.resolve(B)}),L}r.exports={runWebLogin:I,openPopup:f,setupDesktopWebLogin:R,POPUP_WIDTH:p,POPUP_HEIGHT:m}},{"../../lib/braintree-error":59,"../../lib/frame-service/external":68,"../../lib/use-min":85,"../shared/errors":93,"@braintree/extended-promise":26}],98:[function(a,r,i){var n=a("../lib/analytics"),s=a("../lib/assign").assign,o=a("./shared/supports-venmo"),l=a("./shared/browser-detection"),d=a("./shared/constants"),c=a("./shared/errors"),u=a("../lib/querystring"),h=a("../lib/is-verified-domain"),p=a("../lib/methods"),m=a("../lib/convert-methods-to-error"),y=a("@braintree/wrap-promise"),f=a("../lib/braintree-error"),g=a("../lib/in-iframe"),E=a("@braintree/extended-promise"),N=a("./shared/get-venmo-url"),_=a("./shared/web-login-backdrop"),I=a("../lib/snake-case-to-camel-case"),R=a("../lib/url-params"),x=a("./external/"),L=a("./external/queries"),U="3.126.0",G=250,Y=3e5;E.suppressUnhandledPromiseMessage=!0;function j(k){var v=this;this._allowDesktopWebLogin=k.allowDesktopWebLogin||!1,this._mobileWebFallBack=k.mobileWebFallBack||!1,this._createPromise=k.createPromise,this._allowNewBrowserTab=k.allowNewBrowserTab!==!1,this._allowWebviews=k.allowWebviews!==!1,this._allowDesktop=k.allowDesktop===!0,this._useRedirectForIOS=k.useRedirectForIOS===!0,this._profileId=k.profileId,this._displayName=k.displayName,this._deepLinkReturnUrl=k.deepLinkReturnUrl,this._ignoreHistoryChanges=k.ignoreHistoryChanges,this._paymentMethodUsage=(k.paymentMethodUsage||"").toUpperCase(),this._shouldUseLegacyFlow=!this._paymentMethodUsage,this._requireManualReturn=k.requireManualReturn===!0,this._useDesktopQRFlow=this._allowDesktop&&this._isDesktop()&&!this._allowDesktopWebLogin,this._useAllowDesktopWebLogin=this._allowDesktopWebLogin&&this._isDesktop(),this._cannotHaveReturnUrls=g()||this._requireManualReturn,this._allowAndroidRecreation=k.allowAndroidRecreation!==!1,this._maxRetryCount=3,this._collectCustomerBillingAddress=k.collectCustomerBillingAddress||!1,this._collectCustomerShippingAddress=k.collectCustomerShippingAddress||!1,this._isFinalAmount=k.isFinalAmount||!1,this._lineItems=k.lineItems,this._subTotalAmount=k.subTotalAmount,this._discountAmount=k.discountAmount,this._taxAmount=k.taxAmount,this._shippingAmount=k.shippingAmount,this._totalAmount=k.totalAmount,this._cspNonce=(this._mobileWebFallBack||this._allowDesktopWebLogin)&&(k.styleCspNonce||!1),this._shouldCreateVenmoPaymentContext=this._cannotHaveReturnUrls||!this._shouldUseLegacyFlow,n.sendEvent(this._createPromise,"venmo.desktop-flow.configured."+String(!!this._allowDesktop)),this.hasTokenizationResult()?n.sendEvent(this._createPromise,"venmo.appswitch.return-in-new-tab"):this._useDesktopQRFlow?this._createPromise=this._createPromise.then(function(O){var M=O.getConfiguration().gatewayConfiguration;return x({url:M.assetsUrl+"/web/"+U+"/html/venmo-desktop-frame.html",environment:M.environment==="production"?"PRODUCTION":"SANDBOX",profileId:v._profileId||M.payWithVenmo.merchantId,paymentMethodUsage:v._paymentMethodUsage,displayName:v._displayName,Promise,apiRequest:function(P,T){return O.request({api:"graphQLApi",data:{query:P,variables:T}}).then(function(b){return b.data})},sendEvent:function(P){n.sendEvent(v._createPromise,P)},verifyDomain:h}).then(function(P){return v._venmoDesktopInstance=P,n.sendEvent(v._createPromise,"venmo.desktop-flow.presented"),O}).catch(function(){return n.sendEvent(v._createPromise,"venmo.desktop-flow.setup-failed"),v._useDesktopQRFlow=!1,O})}):this._shouldCreateVenmoPaymentContext&&(this._mobilePollingInterval=G,this._mobilePollingExpiresThreshold=Y,this._createPromise=this._createPromise.then(function(O){var M,P,T=v._cannotHaveReturnUrls?"manual-return":"mobile-payment-context",b=O.getConfiguration();return P=_.setupDesktopWebLogin({assetsUrl:b.gatewayConfiguration.assetsUrl,debug:b.isDebug}).then(function(w){v._frameServiceInstance=w}).catch(function(w){return w}),v._mobilePollingContextEnvironment=b.gatewayConfiguration.environment.toUpperCase(),M=v._createVenmoPaymentContext(O).then(function(){return n.sendEvent(v._createPromise,"venmo."+T+".presented"),O}).catch(function(w){return n.sendEvent(v._createPromise,"venmo."+T+".setup-failed"),Promise.reject(new f({type:c.VENMO_MOBILE_PAYMENT_CONTEXT_SETUP_FAILED.type,code:c.VENMO_MOBILE_PAYMENT_CONTEXT_SETUP_FAILED.code,message:F(w)?w.details.originalError[0].message:c.VENMO_MOBILE_PAYMENT_CONTEXT_SETUP_FAILED.message,details:{originalError:w}}))}),E.all([P,M]).then(function(w){var S=w[1];return Promise.resolve(S)}).catch(function(w){return Promise.reject(w)})}))}function F(k){return k.details&&k.details.originalError&&k.details.originalError[0]&&k.details.originalError[0].extensions&&k.details.originalError[0].extensions.errorClass==="VALIDATION"&&k.details.originalError[0].extensions.errorType==="user_error"}j.prototype._createVenmoPaymentContext=function(k,v){var O=this,M,P,T=k.getConfiguration(),b=T.gatewayConfiguration.payWithVenmo,w=!1,S=O._useAllowDesktopWebLogin?"NATIVE_WEB":"MOBILE_WEB";if(!this._shouldCreateVenmoPaymentContext)return Promise.resolve();if(this._shouldUseLegacyFlow)M=k.request({api:"graphQLApi",data:{query:L.LEGACY_CREATE_PAYMENT_CONTEXT_QUERY,variables:{input:{environment:this._mobilePollingContextEnvironment,intent:"PAY_FROM_APP"}}}}).then(function(C){return C.data.createVenmoQRCodePaymentContext.venmoQRCodePaymentContext});else{if((this._collectCustomerBillingAddress||this._collectCustomerShippingAddress)&&!b.enrichedCustomerDataEnabled)return Promise.reject(new f(c.VENMO_ECD_DISABLED));this._lineItems&&this._lineItems.forEach(function(C){C.unitTaxAmount=C.unitTaxAmount||"0"}),P={subTotalAmount:this._subTotalAmount,discountAmount:this._discountAmount,taxAmount:this._taxAmount,shippingAmount:this._shippingAmount,totalAmount:this._totalAmount,lineItems:this._lineItems},w=Object.keys(P).some(function(C){return P[C]!==void 0}),M=k.request({api:"graphQLApi",data:{query:L.CREATE_PAYMENT_CONTEXT_QUERY,variables:{input:{paymentMethodUsage:this._paymentMethodUsage,intent:"CONTINUE",customerClient:S,isFinalAmount:this._isFinalAmount,displayName:this._displayName,paysheetDetails:{collectCustomerBillingAddress:this._collectCustomerBillingAddress,collectCustomerShippingAddress:this._collectCustomerShippingAddress,transactionDetails:w?P:void 0}}}}}).then(function(C){return C.data.createVenmoPaymentContext.venmoPaymentContext})}return M.then(function(C){var V=new Date(C.expiresAt)-new Date(C.createdAt),$=V*.6666;clearTimeout(O._refreshPaymentContextTimeout),O._refreshPaymentContextTimeout=setTimeout(function(){O._tokenizationInProgress||O._createVenmoPaymentContext(k,!0)},$),!(v&&O._tokenizationInProgress)&&(O._venmoPaymentContextStatus=C.status,O._venmoPaymentContextId=C.id)})},j.prototype._popupBridgeIsInstalled=function(){return window.popupBridge&&typeof window.popupBridge.open=="function"},j.prototype._venmoNativeAppIsInstalled=function(){return!!(window.popupBridge&&(window.parent&&window.parent.popupBridge.isVenmoInstalled||window.popupBridge.isVenmoInstalled))},j.prototype._handleDeepLinkAppSwitch=function(k){q()?this._handleIosWebviewDeepLink(k):this._popupBridgeIsInstalled()?this._handlePopupBridgeAppSwitch(k):(n.sendEvent(this._createPromise,"venmo.appswitch.start.webview"),this._venmoWindow=window.open(k))},j.prototype._handleIosWebviewDeepLink=function(k){n.sendEvent(this._createPromise,"venmo.appswitch.start.ios-webview"),g()?this._handleIosWebviewInIframe(k):!this._venmoNativeAppIsInstalled()&&this._popupBridgeIsInstalled()?this._handlePopupBridgeAppSwitch(k):window.location.href=k},j.prototype._handleIosWebviewInIframe=function(k){this._venmoNativeAppIsInstalled()?this._handleIFrameBreakout(k):this._popupBridgeIsInstalled()?this._handlePopupBridgeAppSwitch(k):this._handleIFrameBreakout(k)},j.prototype._handlePopupBridgeAppSwitch=function(k){n.sendEvent(this._createPromise,"venmo.appswitch.start.popup-bridge"),window.popupBridge.open(k)},j.prototype._handleBrowserAppSwitch=function(k){n.sendEvent(this._createPromise,"venmo.appswitch.start.browser"),l.doesNotSupportWindowOpenInIos()||this._shouldUseRedirectStrategy()||this._mobileWebFallBack&&l.isAndroid()&&l.isChrome()?window.location.href=k:this._venmoWindow=window.open(k)},j.prototype._handleIFrameBreakout=function(k){window.top.location.href=k},j.prototype.appSwitch=function(k){this._deepLinkReturnUrl?this._handleDeepLinkAppSwitch(k):this._handleBrowserAppSwitch(k)},j.prototype.getUrl=function(){return this._createPromise.then(function(k){var v=k.getConfiguration(),O={},M=this._deepLinkReturnUrl||window.location.href.replace(window.location.hash,""),P=v.gatewayConfiguration.payWithVenmo,T=v.analyticsMetadata,b=P.accessToken,w={_meta:{version:T.sdkVersion,integration:T.integration,platform:T.platform,sessionId:T.sessionId}};return this._isDebug=v.isDebug,this._assetsUrl=v.gatewayConfiguration.assetsUrl,M=M.replace(/#*$/,""),this._venmoPaymentContextId&&(this._shouldUseLegacyFlow?b+="|pcid:"+this._venmoPaymentContextId:O.resource_id=this._venmoPaymentContextId),this._shouldIncludeReturnUrls()||this._useAllowDesktopWebLogin?(this._useAllowDesktopWebLogin&&(M=this._assetsUrl+"/web/"+U+"/html/redirect-frame.html"),O["x-success"]=M+"#venmoSuccess=1",O["x-cancel"]=M+"#venmoCancel=1",O["x-error"]=M+"#venmoError=1"):(O["x-success"]="NOOP",O["x-cancel"]="NOOP",O["x-error"]="NOOP"),this._allowAndroidRecreation?O.allowAndroidRecreation=1:O.allowAndroidRecreation=0,O.ua=window.navigator.userAgent,O.braintree_merchant_id=this._profileId||P.merchantId,O.braintree_access_token=b,O.braintree_environment=P.environment,O.braintree_sdk_data=btoa(JSON.stringify(w)),N({useAllowDesktopWebLogin:this._useAllowDesktopWebLogin,mobileWebFallBack:this._mobileWebFallBack})+"?"+u.stringify(O)}.bind(this))},j.prototype.isBrowserSupported=function(){return o.isBrowserSupported({allowNewBrowserTab:this._allowNewBrowserTab,allowWebviews:this._allowWebviews,allowDesktop:this._allowDesktop,allowDesktopWebLogin:this._allowDesktopWebLogin})},j.prototype.hasTokenizationResult=function(){return this._hasTokenizationResult()},j.prototype._hasTokenizationResult=function(k){var v=B(k),O=R.getUrlParams();return O.resource_id?this._venmoPaymentContextId=O.resource_id:v.id&&(this._venmoPaymentContextId=v.id),typeof(v.venmoSuccess||v.venmoError||v.venmoCancel)!="undefined"},j.prototype._shouldIncludeReturnUrls=function(){return this._deepLinkReturnUrl?!0:!this._cannotHaveReturnUrls},j.prototype._isDesktop=function(){return!(l.isIos()||l.isAndroid())},j.prototype.tokenize=function(k){var v=this,O;return k=k||{},this._tokenizationInProgress===!0?Promise.reject(new f(c.VENMO_TOKENIZATION_REQUEST_ACTIVE)):(this._tokenizationInProgress=!0,this._useDesktopQRFlow?O=this._tokenizeForDesktopQRFlow(k):this._useAllowDesktopWebLogin?O=this._tokenizeWebLoginWithRedirect(k):this._cannotHaveReturnUrls?O=this._tokenizeForMobileWithManualReturn():O=this._tokenizeForMobileWithHashChangeListeners(k),O.then(function(M){return v._createPromise.then(function(P){return v._createVenmoPaymentContext(P)}).then(function(){return v._tokenizationInProgress=!1,v._venmoWindow=null,z(M)})}).catch(function(M){return v._createPromise.then(function(P){return v._createVenmoPaymentContext(P)}).then(function(){return v._tokenizationInProgress=!1,v._venmoWindow=null,Promise.reject(M)})}))},j.prototype.cancelTokenization=function(){return this._tokenizationInProgress?(this._removeVisibilityEventListener(),this._tokenizePromise&&this._tokenizePromise.reject(new f(c.VENMO_TOKENIZATION_CANCELED_BY_MERCHANT)),Promise.all([this._cancelMobilePaymentContext(),this._cancelVenmoDesktopContext()])):Promise.reject(new f(c.VENMO_TOKENIZATION_REQUEST_NOT_ACTIVE))},j.prototype._tokenizeWebLoginWithRedirect=function(){var k=this,v;return n.sendEventPlus(k._createPromise,"venmo.tokenize.web-login.start",{context_id:k._venmoPaymentContextId}),this._tokenizePromise=new E,this.getUrl().then(function(O){return v={checkForStatusChange:k._checkPaymentContextStatusAndProcessResult.bind(k),cancelTokenization:k.cancelTokenization.bind(k),frameServiceInstance:k._frameServiceInstance,venmoUrl:O,debug:k._isDebug,checkPaymentContextStatus:k._checkPaymentContextStatus.bind(k)},k._cspNonce&&(v=s({},v,{styleCspNonce:k._cspNonce})),_.runWebLogin(v).then(function(M){n.sendEventPlus(k._createPromise,"venmo.tokenize.web-login.success",{context_id:k._venmoPaymentContextId}),k._tokenizePromise.resolve({paymentMethodNonce:M.paymentMethodId,username:M.userName,payerInfo:M.payerInfo,id:k._venmoPaymentContextId})}).catch(function(M){n.sendEventPlus(k._createPromise,"venmo.tokenize.web-login.failure",{context_id:k._venmoPaymentContextId}),k._tokenizePromise.reject(M)}),k._tokenizePromise})},j.prototype._queryPaymentContextStatus=function(k){var v=this;return this._createPromise.then(function(O){var M=v._shouldUseLegacyFlow?L.LEGACY_VENMO_PAYMENT_CONTEXT_STATUS_QUERY:L.VENMO_PAYMENT_CONTEXT_STATUS_QUERY;return O.request({api:"graphQLApi",data:{query:M,variables:{id:k}}})}).then(function(O){return O.data.node})},j.prototype._checkPaymentContextStatusAndProcessResult=function(k){var v=this;return v._checkPaymentContextStatus().then(function(O){var M=O.status;if(M!==v._venmoPaymentContextStatus)switch(v._venmoPaymentContextStatus=M,n.sendEventPlus(v._createPromise,"venmo.tokenize.web-login.status-change",{context_id:v._venmoPaymentContextId}),M){case"APPROVED":return Promise.resolve(O);case"CANCELED":return Promise.reject(new f(c.VENMO_CUSTOMER_CANCELED));case"FAILED":return Promise.reject(new f(c.VENMO_TOKENIZATION_FAILED))}return new Promise(function(P,T){k<v._maxRetryCount?(k++,v._checkPaymentContextStatusAndProcessResult(k).then(P).catch(T)):T(new f(c.VENMO_TOKENIZATION_FAILED))})})},j.prototype._checkPaymentContextStatus=function(){var k=this;return k._queryPaymentContextStatus(k._venmoPaymentContextId).catch(function(v){return Promise.reject(new f({type:c.VENMO_NETWORK_ERROR.type,code:c.VENMO_NETWORK_ERROR.code,message:c.VENMO_NETWORK_ERROR.message,details:v}))}).then(function(v){return Promise.resolve(v)})},j.prototype._pollForStatusChange=function(){var k=this;return k._venmoPaymentContextId?Date.now()>k._mobilePollingContextExpiresIn?Promise.reject(new f(c.VENMO_MOBILE_POLLING_TOKENIZATION_TIMEOUT)):k._venmoWindow&&k._venmoWindow.closed&&k._venmoPaymentContextStatus==="CREATED"?(n.sendEvent(k._createPromise,"venmo.appswitch.browser-window.closed"),k._cancelMobilePaymentContext().then(function(){n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.canceled",{context_id:k._venmoPaymentContextId})}).catch(function(v){n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.canceled.error",{context_id:k._venmoPaymentContextId})}),Promise.reject(new f(c.VENMO_MOBILE_POLLING_TOKENIZATION_CANCELED))):this._queryPaymentContextStatus(this._venmoPaymentContextId).catch(function(v){return Promise.reject(new f({type:c.VENMO_MOBILE_POLLING_TOKENIZATION_NETWORK_ERROR.type,code:c.VENMO_MOBILE_POLLING_TOKENIZATION_NETWORK_ERROR.code,message:c.VENMO_MOBILE_POLLING_TOKENIZATION_NETWORK_ERROR.message,details:{originalError:v}}))}).then(function(v){var O=v.status;if(O!==k._venmoPaymentContextStatus)switch(k._venmoPaymentContextStatus=O,n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.status-change."+O.toLowerCase(),{context_id:k._venmoPaymentContextId}),O){case"EXPIRED":case"FAILED":case"CANCELED":return Promise.reject(new f(c["VENMO_MOBILE_POLLING_TOKENIZATION_"+O]));case"APPROVED":return Promise.resolve(v)}return new Promise(function(M,P){setTimeout(function(){k._pollForStatusChange().then(M).catch(P)},k._mobilePollingInterval)})}):Promise.reject(new f(c.VENMO_MOBILE_POLLING_TOKENIZATION_NO_CONTEXT_ID))},j.prototype._tokenizeForMobileWithManualReturn=function(){var k=this;return n.sendEventPlus(this._createPromise,"venmo.tokenize.manual-return.start",{context_id:k._venmoPaymentContextId}),this._mobilePollingContextExpiresIn=Date.now()+this._mobilePollingExpiresThreshold,this._tokenizePromise=new E,this._pollForStatusChange().then(function(v){n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.success",{context_id:k._venmoPaymentContextId}),k._tokenizePromise.resolve({paymentMethodNonce:v.paymentMethodId,username:v.userName,payerInfo:v.payerInfo,id:k._venmoPaymentContextId})}).catch(function(v){n.sendEventPlus(k._createPromise,"venmo.tokenize.manual-return.failure",{context_id:k._venmoPaymentContextId}),k._tokenizePromise.reject(v)}),this.getUrl().then(function(v){return k.appSwitch(v),k._tokenizePromise})},j.prototype._shouldUseRedirectStrategy=function(){return l.isIos()?this._mobileWebFallBack===!0?!0:this._useRedirectForIOS:!1},j.prototype._tokenizeForMobileWithHashChangeListeners=function(k){var v=this,O,M;if(this.hasTokenizationResult())return this.processHashChangeFlowResults();n.sendEvent(this._createPromise,"venmo.tokenize.mobile.start"),this._tokenizePromise=new E,this._previousHash=window.location.hash;function P(T){var b;v.processHashChangeFlowResults(T).catch(function(w){b=w}).then(function(w){!v._ignoreHistoryChanges&&window.location.hash!==v._previousHash&&(window.location.hash=v._previousHash),v._removeVisibilityEventListener(),b?v._tokenizePromise.reject(b):v._tokenizePromise.resolve(w),delete v._tokenizePromise})}return this._onHashChangeListener=function(T){var b=T.newURL.split("#")[1];v._hasTokenizationResult(b)&&(O=!0,clearTimeout(M),P(b))},window.addEventListener("hashchange",this._onHashChangeListener,!1),this._visibilityChangeListener=function(){var T=k.processResultsDelay||d.DEFAULT_PROCESS_RESULTS_DELAY;window.document.hidden||(v._venmoWindow&&!v._venmoWindow.closed&&v._venmoWindow.close(),O||(M=setTimeout(P,T)))},this.getUrl().then(function(T){return v.appSwitch(T),setTimeout(function(){window.document.addEventListener(W(),v._visibilityChangeListener)},d.DOCUMENT_VISIBILITY_CHANGE_EVENT_DELAY),v._tokenizePromise})},j.prototype._tokenizeForDesktopQRFlow=function(){var k=this;return n.sendEvent(this._createPromise,"venmo.tokenize.desktop.start"),this._tokenizePromise=new E,this._createPromise.then(function(){return k._venmoDesktopInstance.launchDesktopFlow()}).then(function(v){k._venmoDesktopInstance.hideDesktopFlow(),n.sendEvent(k._createPromise,"venmo.tokenize.desktop.success"),k._tokenizePromise.resolve(v)}).catch(function(v){if(n.sendEvent(k._createPromise,"venmo.tokenize.desktop.failure"),k._venmoDesktopInstance&&k._venmoDesktopInstance.hideDesktopFlow(),v&&v.reason==="CUSTOMER_CANCELED"){k._tokenizePromise.reject(new f(c.VENMO_DESKTOP_CANCELED));return}k._tokenizePromise.reject(new f({type:c.VENMO_DESKTOP_UNKNOWN_ERROR.type,code:c.VENMO_DESKTOP_UNKNOWN_ERROR.code,message:c.VENMO_DESKTOP_UNKNOWN_ERROR.message,details:{originalError:v}}))}),this._tokenizePromise},j.prototype._cancelMobilePaymentContext=function(){var k=this;return this._createPromise.then(function(v){var O;return k._venmoPaymentContextId?(O=k._shouldUseLegacyFlow?L.LEGACY_UPDATE_PAYMENT_CONTEXT_QUERY:L.UPDATE_PAYMENT_CONTEXT_QUERY,v.request({api:"graphQLApi",data:{query:O,variables:{input:{id:k._venmoPaymentContextId,status:"CANCELED"}}}})):Promise.resolve()})},j.prototype._cancelVenmoDesktopContext=function(){var k=this;return this._createPromise.then(function(){return k._venmoDesktopInstance&&k._venmoDesktopInstance.updateVenmoDesktopPaymentContext("CANCELED"),Promise.resolve()})},j.prototype.teardown=function(){var k=this;return this._removeVisibilityEventListener(),this._createPromise.then(function(){k._venmoDesktopInstance&&k._venmoDesktopInstance.teardown(),clearTimeout(k._refreshPaymentContextTimeout),k._cancelMobilePaymentContext(),m(this,p(j.prototype))}.bind(this))},j.prototype._removeVisibilityEventListener=function(){window.removeEventListener("hashchange",this._onHashChangeListener),window.document.removeEventListener(W(),this._visibilityChangeListener),delete this._visibilityChangeListener,delete this._onHashChangeListener},j.prototype.processHashChangeFlowResults=function(k){var v=this,O=B(k);return new Promise(function(M,P){v._shouldUseLegacyFlow?O.venmoSuccess?(n.sendEvent(v._createPromise,"venmo.appswitch.handle.success"),window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:succeeded"),M(O)):O.venmoError?(n.sendEvent(v._createPromise,"venmo.appswitch.handle.error"),window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:failed"),P(new f({type:c.VENMO_APP_FAILED.type,code:c.VENMO_APP_FAILED.code,message:c.VENMO_APP_FAILED.message,details:{originalError:{message:decodeURIComponent(O.errorMessage),code:O.errorCode}}}))):O.venmoCancel?(n.sendEvent(v._createPromise,"venmo.appswitch.handle.cancel"),window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:canceled"),P(new f(c.VENMO_APP_CANCELED))):(n.sendEvent(v._createPromise,"venmo.appswitch.cancel-or-unavailable"),P(new f(c.VENMO_CANCELED))):v._pollForStatusChange().then(function(T){return n.sendEventPlus(v._createPromise,"venmo.appswitch.handle.payment-context-status-query.success",{context_id:v._venmoPaymentContextId}),window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:succeeded"),M({paymentMethodNonce:T.paymentMethodId,username:T.userName,payerInfo:T.payerInfo,id:v._venmoPaymentContextId})}).catch(function(T){T.code===c.VENMO_MOBILE_POLLING_TOKENIZATION_CANCELED.code?(window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:canceled"),P(T)):window.popupBridge&&n.sendEvent(v._createPromise,"popup-bridge:venmo:failed"),n.sendEventPlus(v._createPromise,"venmo.process-results.payment-context-status-query-failed",{context_id:v._venmoPaymentContextId}),M(O)}),v._clearFragmentParameters()})},j.prototype._clearFragmentParameters=function(){this._ignoreHistoryChanges||typeof window.history.replaceState=="function"&&window.location.hash&&history.pushState({},"",window.location.href.slice(0,window.location.href.indexOf("#")))};function B(k){var v=(k||window.location.hash.substring(1)).split("&"),O=v.reduce(function(M,P){var T=P.split("="),b=decodeURIComponent(T[0]).replace(/\W/g,""),w=I(b),S=decodeURIComponent(T[1]);return M[w]=S,M},{});return O.resourceId&&(O.id=O.resourceId),O}function J(k){return k=k||"","@"+k.replace("@","")}function z(k){var v={nonce:k.paymentMethodNonce,type:"VenmoAccount",details:{username:J(k.username),paymentContextId:k.id}};return k.payerInfo&&(v.details.payerInfo=k.payerInfo,v.details.payerInfo.userName=J(k.payerInfo.userName)),v}function W(){var k;return typeof window.document.hidden!="undefined"?k="visibilitychange":typeof window.document.msHidden!="undefined"?k="msvisibilitychange":typeof window.document.webkitHidden!="undefined"&&(k="webkitvisibilitychange"),k}function q(){return window.navigator.platform&&/iPhone|iPad|iPod/.test(window.navigator.platform)}r.exports=y.wrapPrototype(j)},{"../lib/analytics":55,"../lib/assign":57,"../lib/braintree-error":59,"../lib/convert-methods-to-error":61,"../lib/in-iframe":78,"../lib/is-verified-domain":79,"../lib/methods":81,"../lib/querystring":82,"../lib/snake-case-to-camel-case":83,"../lib/url-params":84,"./external/":87,"./external/queries":88,"./shared/browser-detection":91,"./shared/constants":92,"./shared/errors":93,"./shared/get-venmo-url":95,"./shared/supports-venmo":96,"./shared/web-login-backdrop":97,"@braintree/extended-promise":26,"@braintree/wrap-promise":35}]},{},[90])(90)})}(xt)),xt.exports}var Qd=$d();const Zd=kt(Qd);class Xd{constructor(){A(this,"client",null);A(this,"venmoInstance",null);A(this,"deviceData",null)}init(e){return H(this,null,function*(){try{this.client=yield Hd.create({authorization:e.authorization});try{const a=yield Wd.create({client:this.client,paypal:!0});this.deviceData=a.deviceData||null}catch(a){console.warn("Braintree device data collection failed:",a),this.deviceData=null}}catch(a){throw console.error("Failed to initialize Braintree client:",a),a}})}createVenmo(e){return H(this,null,function*(){if(!this.client)throw new Error("Braintree client must be initialized before creating Venmo instance");try{return this.venmoInstance=yield Zd.create(K({client:this.client,allowDesktop:!0,mobileWebFallBack:!0,allowDesktopWebLogin:!0,paymentMethodUsage:"multi_use"},e)),this.venmoInstance}catch(a){throw console.error("Failed to create Venmo instance:",a),a}})}isBrowserSupported(){var e,a;return(a=(e=this.venmoInstance)==null?void 0:e.isBrowserSupported())!=null?a:!1}hasTokenizationResult(){var e,a;return(a=(e=this.venmoInstance)==null?void 0:e.hasTokenizationResult())!=null?a:!1}tokenize(){return H(this,null,function*(){if(!this.venmoInstance)throw new Error("Venmo instance not initialized");return new Promise((e,a)=>{this.venmoInstance.tokenize(void 0,(r,i)=>{if(r)a(r);else{const n=ee(K({},i),{device_data:this.deviceData||void 0}),s=i,o=(s==null?void 0:s.billingAddress)||(s==null?void 0:s.billing_address);if(o){const l={city:o.adminArea2,country:o.countryCode,line1:o.line1,line2:o.line2,postal_code:o.postalCode,state:o.adminArea1};n.billing_address=l}e(n)}})})})}}class Fn{constructor(){A(this,"ev",new ii);A(this,"paypal",new Ud);A(this,"braintree",new Xd);A(this,"state",{translate:new xd,checkout:new kd,transaction:new Ed,styles:new Cd});A(this,"checkout",new Pd({state:this.state,service:{ev:this.ev,paypal:this.paypal,braintree:this.braintree}}))}clearState(){Object.values(this.state).forEach(e=>e.clearState())}}class Jd{constructor(e){A(this,"parent");A(this,"core");typeof window!="undefined"&&(this.parent=e,this.core=new Fn)}mount(e){return H(this,null,function*(){if(!this.parent||!this.core)return;const a=yield this.core.checkout.mount();this.parent.innerHTML="",this.parent.appendChild(a),this.core.state.checkout.setState(e)})}unmount(){return H(this,null,function*(){!this.parent||!this.core||(this.parent.innerHTML="",this.core.clearState())})}}re.Core=Fn,re.PayNextCheckout=Jd,re.PaymentMethod=te,Object.defineProperty(re,Symbol.toStringTag,{value:"Module"})});
486
486
  //# sourceMappingURL=index.umd.js.map