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) 4.38 kB
import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import{CashAppComponent as r}from"./components/CashAppComponent.js";import o from"./services/CashAppService.js";import{CashAppSdkLoader as s}from"./services/CashAppSdkLoader.js";import n from"./defaultProps.js";import i from"../internal/RedirectButton/RedirectButton.js";import{payAmountLabel as a}from"../internal/PayButton/utils.js";import{TxVariants as p}from"../tx-variants.js";import{PREFIX as h}from"../internal/Icon/constants.js";function c(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function d(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter(function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable}))),o.forEach(function(e){c(t,e,r[e])})}return t}function l(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):function(t){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e.push.apply(e,r)}return e}(Object(e)).forEach(function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))}),t}class u extends e{formatProps(t){var e,r;return l(d({},t),{enableStoreDetails:(null===(r=t.session)||void 0===r||null===(e=r.configuration)||void 0===e?void 0:e.enableStoreDetails)||t.enableStoreDetails})}formatData(){const{shopperWantsToStore:t,grantId:e,onFileGrantId:r,cashTag:o,customerId:s}=this.state.data||{},{storePaymentMethod:n,storedPaymentMethodId:i}=this.props,a=this.props.enableStoreDetails||!this.props.session&&n;if(i)return{paymentMethod:{type:u.type,storedPaymentMethodId:i}};return d({paymentMethod:d({type:u.type},e&&{grantId:e},s&&{customerId:s},r&&o&&{onFileGrantId:r,cashtag:o})},a&&{storePaymentMethod:n||t})}get displayName(){return this.props.storedPaymentMethodId&&this.props.cashtag?this.props.cashtag:this.props.name}get additionalInfo(){return this.props.storedPaymentMethodId?"Cash App Pay":""}get isValid(){return!0}componentToRender(){var e;return this.props.storedPaymentMethodId?t(i,{showPayButton:this.props.showPayButton,label:a(this.props.i18n,this.props.amount),icon:null===(e=this.resources)||void 0===e?void 0:e.getImage({imageFolder:"components/"})(`${h}lock`),name:this.displayName,payButton:this.payButton,onSubmit:this.submit,ref:t=>{this.componentRef=t}}):t(r,{ref:t=>{this.componentRef=t},enableStoreDetails:this.props.enableStoreDetails,cashAppService:this.cashAppService,onChangeStoreDetails:this.handleOnChangeStoreDetails,onError:this.handleError,onClick:this.submit,onAuthorize:this.handleAuthorize})}constructor(t,e){var r,n;if(super(t,e),c(this,"cashAppService",void 0),c(this,"submit",()=>{const{onClick:t,storedPaymentMethodId:e}=this.props;if(e)return void super.submit();let r=!1;new Promise((e,r)=>t({resolve:e,reject:r})).catch(()=>{throw r=!0,Error("onClick rejected")}).then(()=>this.cashAppService.createCustomerRequest(this.props.amount)).then(()=>{this.cashAppService.begin()}).catch(t=>{r||this.handleError(t)})}),c(this,"handleOnChangeStoreDetails",t=>{const e=l(d({},this.state.data),{shopperWantsToStore:t});this.setState({data:e})}),c(this,"handleAuthorize",t=>{const e=d({},this.state.data,t);this.setState({data:e,valid:{},errors:{},isValid:!0}),super.submit()}),this.props.enableStoreDetails&&this.props.storePaymentMethod&&console.warn("CashAppPay: enableStoreDetails AND storePaymentMethod configuration properties should not be used together. That can lead to undesired behavior."),this.props.storedPaymentMethodId)return;const i=new s({environment:this.props.environment,analytics:this.analytics});this.cashAppService=new o(i,{storePaymentMethod:this.props.storePaymentMethod,useCashAppButtonUi:this.props.showPayButton,environment:this.props.environment,redirectURL:this.props.redirectURL,clientId:null===(r=this.props.configuration)||void 0===r?void 0:r.clientId,scopeId:null===(n=this.props.configuration)||void 0===n?void 0:n.scopeId,button:this.props.button,referenceId:this.props.referenceId})}}c(u,"type",p.cashapp),c(u,"defaultProps",n);export{u as CashAppPay,u as default}; //# sourceMappingURL=CashAppPay.js.map