UNPKG

@atlas-kitchen/adyen-web

Version:
3 lines (2 loc) 2.19 kB
import t from"../../../core/Errors/AdyenCheckoutError.js";function e(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(t){for(var n=1;n<arguments.length;n++){var i=null!=arguments[n]?arguments[n]:{},r=Object.keys(i);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(i).filter((function(t){return Object.getOwnPropertyDescriptor(i,t).enumerable})))),r.forEach((function(n){e(t,n,i[n])}))}return t}class i{get hasOneTimePayment(){const{amount:t}=this.configuration;return(null==t?void 0:t.value)>0}get hasOnFilePayment(){return this.configuration.storePaymentMethod}setStorePaymentMethod(t){this.configuration.storePaymentMethod=t}async initialize(){try{const{environment:t,clientId:e}=this.configuration,n=await this.sdkLoader.load(t);this.pay=await n.pay({clientId:e})}catch(e){throw new t("ERROR","Error during initialization",{cause:e})}}async renderButton(e){try{const{button:t,useCashAppButtonUi:i}=this.configuration,{begin:r}=await this.pay.render(e,{manage:!1,button:!!i&&n({width:"full",shape:"semiround"},t)});this.startAuthorization=r}catch(e){throw new t("ERROR","Error rendering CashAppPay button",{cause:e})}}begin(){this.startAuthorization?this.startAuthorization():console.warn("CashAppService - begin() not available")}subscribeToEvent(t,e){return this.pay.addEventListener(t,e),()=>{this.pay.removeEventListener(t,e)}}async createCustomerRequest(){try{const{referenceId:t,amount:e,scopeId:i,redirectURL:r=window.location.href}=this.configuration,o={referenceId:t,redirectURL:r,actions:n({},this.hasOneTimePayment&&{payment:{amount:e,scopeId:i}},this.hasOnFilePayment&&{onFile:{scopeId:i}})};await this.pay.customerRequest(o)}catch(e){throw new t("ERROR","Something went wrong during customerRequest creation",{cause:e})}}async restart(){await this.pay.restart()}constructor(t,n){e(this,"sdkLoader",void 0),e(this,"configuration",void 0),e(this,"pay",void 0),e(this,"startAuthorization",void 0),this.configuration=n,this.sdkLoader=t,n.clientId||console.warn("CashAppService: clientId is missing")}}export{i as default}; //# sourceMappingURL=CashAppService.js.map