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) 1.8 kB
import t from"../../../core/Errors/AdyenCheckoutError.js";function e(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}class i{isOneTimePayment(t){return t?.value>0}isOnFilePayment(){return this.configuration.storePaymentMethod}setStorePaymentMethod(t){this.configuration.storePaymentMethod=t}async initialize(){try{const{environment:t,clientId:e}=this.configuration,i=await this.sdkLoader.load(t);this.pay=await i.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:n}=await this.pay.render(e,{manage:!1,button:!!i&&{width:"full",shape:"semiround",...t}});this.startAuthorization=n}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(e){try{const{referenceId:t,scopeId:i,redirectURL:n=window.location.href}=this.configuration,r={referenceId:t,redirectURL:n,actions:{...this.isOneTimePayment(e)&&{payment:{amount:e,scopeId:i}},...this.isOnFilePayment()&&{onFile:{scopeId:i}}}};await this.pay.customerRequest(r)}catch(e){throw new t("ERROR","Something went wrong during customerRequest creation",{cause:e})}}async restart(){await this.pay.restart()}constructor(t,i){e(this,"sdkLoader",void 0),e(this,"configuration",void 0),e(this,"pay",void 0),e(this,"startAuthorization",void 0),this.configuration=i,this.sdkLoader=t,i.clientId||console.warn("CashAppService: clientId is missing")}}export{i as default}; //# sourceMappingURL=CashAppService.js.map