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.54 kB
import{createElement as t}from"../../external/preact/dist/preact.js";import{UIElement as e}from"../internal/UIElement/UIElement.js";import{CoreProvider as r}from"../../core/Context/CoreProvider.js";import{CashAppComponent as o}from"./components/CashAppComponent.js";import s from"./services/CashAppService.js";import{CashAppSdkLoader as n}from"./services/CashAppSdkLoader.js";import i from"./defaultProps.js";import a from"../internal/RedirectButton/RedirectButton.js";import"../internal/Button/Button.js";import{payAmountLabel as p}from"../internal/PayButton/utils.js";import{TxVariants as h}from"../tx-variants.js";import{PREFIX as c}from"../internal/Icon/constants.js";function d(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function l(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){d(t,e,r[e])}))}return t}function u(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 m extends e{formatProps(t){var e,r;return u(l({},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:m.type,storedPaymentMethodId:i}};return l({paymentMethod:l({type:m.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}render(){var e;return t(r,{i18n:this.props.i18n,resources:this.resources,loadingContext:this.props.loadingContext},this.props.storedPaymentMethodId?t(a,{showPayButton:this.props.showPayButton,label:p(this.props.i18n,this.props.amount),icon:null===(e=this.resources)||void 0===e?void 0:e.getImage({imageFolder:"components/"})(`${c}lock`),name:this.displayName,amount:this.props.amount,payButton:this.payButton,onSubmit:this.submit,ref:t=>{this.componentRef=t}}):t(o,{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,o;super(t,e),d(this,"cashAppService",void 0),d(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())).then((()=>{this.cashAppService.begin()})).catch((t=>{r||this.handleError(t)}))})),d(this,"handleOnChangeStoreDetails",(t=>{const e=u(l({},this.state.data),{shopperWantsToStore:t});this.setState({data:e})})),d(this,"handleAuthorize",(t=>{const e=l({},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||(this.cashAppService=new s(new n,{storePaymentMethod:this.props.storePaymentMethod,useCashAppButtonUi:this.props.showPayButton,environment:this.props.environment,amount:this.props.amount,redirectURL:this.props.redirectURL,clientId:null===(r=this.props.configuration)||void 0===r?void 0:r.clientId,scopeId:null===(o=this.props.configuration)||void 0===o?void 0:o.scopeId,button:this.props.button,referenceId:this.props.referenceId}))}}d(m,"type",h.cashapp),d(m,"defaultProps",i);export{m as CashAppPay,m as default}; //# sourceMappingURL=CashAppPay.js.map