UNPKG

@adyen/adyen-web

Version:

[![npm](https://img.shields.io/npm/v/@adyen/adyen-web.svg)](https://www.npmjs.com/package/@adyen/adyen-web)

3 lines (2 loc) 7.42 kB
import{createElement as e}from"../../external/preact/dist/preact.js";import{TxVariants as t}from"../tx-variants.js";import{UIElement as n}from"../internal/UIElement/UIElement.js";import r from"../internal/RedirectButton/RedirectButton.js";import o,{ERROR as i}from"../../core/Errors/AdyenCheckoutError.js";import{PasskeyService as s}from"./services/PasskeyService.js";import{authorizeEnrollment as a}from"./services/authorizeEnrollment.js";import{authorizePayment as p}from"./services/authorizePayment.js";import l from"./components/StoredPayment/StoredPayment.js";import d from"./components/Enrollment/Enrollment.js";function c(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),r.forEach(function(t){c(e,t,n[t])})}return e}function y(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t.push.apply(t,n)}return t}(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))}),e}function m(e,t){if(null==e)return{};var n,r,o,i={};if("undefined"!=typeof Reflect&&Reflect.ownKeys){for(n=Reflect.ownKeys(Object(e)),o=0;o<n.length;o++)r=n[o],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}if(i=function(e,t){if(null==e)return{};var n,r,o={},i=Object.getOwnPropertyNames(e);for(r=0;r<i.length;r++)n=i[r],t.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n]);return o}(e,t),Object.getOwnPropertySymbols)for(n=Object.getOwnPropertySymbols(e),o=0;o<n.length;o++)r=n[o],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(i[r]=e[r]);return i}class u extends n{get isValid(){var e;return!(this.props._isAdyenHosted&&!this.props.storedPaymentMethodId)||!!(null===(e=this.state)||void 0===e?void 0:e.isValid)}get additionalInfo(){var e,t;return this.props.storedPaymentMethodId?this.props.i18n.get("paybybankpix.storedPayment.additionalLabel",{values:{receiver:null===(t=this.props)||void 0===t||null===(e=t.payByBankPixDetails)||void 0===e?void 0:e.receiver}}):""}get icon(){var e,t;return this.props.storedPaymentMethodId?this.resources.getImage({parentFolder:`${u.type}/`})(null===(t=this.props)||void 0===t||null===(e=t.payByBankPixDetails)||void 0===e?void 0:e.ispb):super.icon}async isAvailable(){const e=await this.passkeyService.getWebAuthnUnsupportedReason();if(e)return Promise.reject(new o(i,e));if(!this.props._isAdyenHosted)return Promise.resolve();try{if(await this.passkeyService.initialize(),this.props.storedPaymentMethodId){return await this.passkeyService.canUseStoredCredential()?Promise.resolve():Promise.reject(new o("ERROR","The stored payment method is not available on this device"))}return Promise.resolve()}catch(e){return Promise.reject(e instanceof Error?null==e?void 0:e.message:"Unknown error")}}handleAction(e,t={}){const n=this.core.createFromAction(e,y(h({},this.elementRef.props,t),{onAdditionalDetails:this.handleAdditionalDetails}));return n?(this.unmount(),n.isAvailable().then(()=>{n.mount(this._node)}),n):null}formatData(){if(!this.props._isAdyenHosted)return{paymentMethod:{type:t.paybybank_pix}};const e=null==this.props.storedPaymentMethodId;return h({paymentMethod:h({type:t.paybybank_pix},this.state.data)},e?{storePaymentMethod:!0}:{})}componentToRender(){var t,n,o;return this.props._isAdyenHosted?null!=this.props.storedPaymentMethodId?e(l,{txVariant:u.type,type:this.props.type,clientKey:this.props.clientKey,enrollmentId:null===(t=this.props.paymentMethodData)||void 0===t?void 0:t.enrollmentId,initiationId:null===(n=this.props.paymentMethodData)||void 0===n?void 0:n.initiationId,setComponentRef:this.setComponentRef,onPay:this.payWithStoredPayment,onAuthorize:this.authorizePayment}):e(d,{onError:this.handleError,txVariant:u.type,type:this.props.type,clientKey:this.props.clientKey,enrollmentId:null===(o=this.props.paymentMethodData)||void 0===o?void 0:o.enrollmentId,countdownTime:this.props.countdownTime,onEnroll:this.authorizeEnrollment,issuers:this.props.issuers,payButton:this.payButton,onChange:this.onIssuerSelected,onSubmitAnalytics:this.submitAnalytics,setComponentRef:this.setComponentRef}):e(r,{showPayButton:this.props.showPayButton,name:this.displayName,label:this.props.i18n.get("paybybankpix.redirectBtn.label"),payButton:this.payButton,onSubmit:this.submit,ref:e=>{this.componentRef=e}})}constructor(e,t){var n,r;super(e,t),c(this,"passkeyService",void 0),c(this,"onIssuerSelected",async e=>{try{const{data:t={}}=e;if(!t.issuer)return;const n=await this.passkeyService.captureRiskSignalsEnrollment(),{deviceId:r}=n,o=m(n,["deviceId"]);this.setState(y(h({},e),{data:y(h({},t),{riskSignals:o,deviceId:r})}))}catch(e){const t=e instanceof Error?e.message:"Unknown error in the onIssuerSelected";this.handleError(e instanceof o?e:new o(i,t))}}),c(this,"authorizeEnrollment",async e=>{try{var t;const n=await this.passkeyService.createCredentialForEnrollment(e),r={enrollmentId:null===(t=this.props.paymentMethodData)||void 0===t?void 0:t.enrollmentId,fidoAssertion:n},{redirectResult:o}=await a({enrollment:r,clientKey:this.props.clientKey,loadingContext:this.props.loadingContext});this.handleAdditionalDetails({data:{details:{redirectResult:o}}})}catch(e){const t=e instanceof Error?e.message:"Unknown error in the authorizeEnrollment";this.handleError(e instanceof o?e:new o(i,t))}}),c(this,"payWithStoredPayment",async()=>{try{const e=await this.passkeyService.captureRiskSignalsAuthentication(),{deviceId:t}=e,n=m(e,["deviceId"]);this.state=h({},this.state,{data:{storedPaymentMethodId:this.props.storedPaymentMethodId,riskSignals:n,deviceId:t}}),super.submit()}catch(e){const t=e instanceof Error?e.message:"Unknown error in the payWithStoredPayment";this.handleError(e instanceof o?e:new o(i,t))}}),c(this,"authorizePayment",async e=>{try{var t,n;const r=await this.passkeyService.authenticateWithCredential(e),o={enrollmentId:null===(t=this.props.paymentMethodData)||void 0===t?void 0:t.enrollmentId,initiationId:null===(n=this.props.paymentMethodData)||void 0===n?void 0:n.initiationId,fidoAssertion:r},{redirectResult:i}=await p({payment:o,clientKey:this.props.clientKey,loadingContext:this.props.loadingContext});this.handleAdditionalDetails({data:{details:{redirectResult:i}}})}catch(e){const t=e instanceof Error?e.message:"Unknown error in the authorizePayment";this.handleError(e instanceof o?e:new o(i,t))}});const l=this.props.storedPaymentMethodId?null===(r=this.props)||void 0===r||null===(n=r.payByBankPixDetails)||void 0===n?void 0:n.deviceId:this.props.deviceId;this.passkeyService=new s({environment:this.props.environment,deviceId:l},this.analytics),this.props._isAdyenHosted&&this.passkeyService.initialize()}}c(u,"type",t.paybybank_pix),c(u,"TIMEOUT_MINUTES",1),c(u,"defaultProps",{showPayButton:!0,_isAdyenHosted:(()=>{try{return new URL(window.location.href).hostname.endsWith(".adyen.com")}catch(e){return!1}})(),countdownTime:u.TIMEOUT_MINUTES});export{u as default}; //# sourceMappingURL=PayByBankPix.js.map