@adyen/adyen-web 6.38.0 → 6.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/adyen.css +91 -91
- package/dist/cjs/adyen.css.map +1 -1
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +91 -75
- package/dist/es/adyen.css +91 -91
- package/dist/es/adyen.css.map +1 -1
- package/dist/es/components/ANCV/components/ANCVInput.js +1 -1
- package/dist/es/components/ANCV/components/ANCVInput.js.map +1 -1
- package/dist/es/components/Ach/components/AchComponent.js +1 -1
- package/dist/es/components/Ach/components/AchComponent.js.map +1 -1
- package/dist/es/components/Affirm/Affirm.js +1 -1
- package/dist/es/components/Affirm/Affirm.js.map +1 -1
- package/dist/es/components/Affirm/config.js +1 -1
- package/dist/es/components/Affirm/config.js.map +1 -1
- package/dist/es/components/BacsDD/components/BacsInput.js +1 -1
- package/dist/es/components/BacsDD/components/BacsInput.js.map +1 -1
- package/dist/es/components/BankTransfer/components/BankTransferInput/BankTransferInput.js +1 -1
- package/dist/es/components/BankTransfer/components/BankTransferInput/BankTransferInput.js.map +1 -1
- package/dist/es/components/Card/components/CardInput/components/StoredCardFields.js +1 -1
- package/dist/es/components/Card/components/CardInput/components/StoredCardFields.js.map +1 -1
- package/dist/es/components/Dragonpay/components/DragonpayInput/DragonpayInput.js +1 -1
- package/dist/es/components/Dragonpay/components/DragonpayInput/DragonpayInput.js.map +1 -1
- package/dist/es/components/Dropin/components/PaymentMethod/OrderPaymentMethods.js +1 -1
- package/dist/es/components/Dropin/components/PaymentMethod/OrderPaymentMethods.js.map +1 -1
- package/dist/es/components/PayPal/Paypal.js +1 -1
- package/dist/es/components/PayPal/Paypal.js.map +1 -1
- package/dist/es/components/PayPal/constants.js +1 -1
- package/dist/es/components/PayPal/constants.js.map +1 -1
- package/dist/es/components/PayTo/components/BSBInput.js +1 -1
- package/dist/es/components/PayTo/components/BSBInput.js.map +1 -1
- package/dist/es/components/PayTo/components/PayIDInput.js +1 -1
- package/dist/es/components/PayTo/components/PayIDInput.js.map +1 -1
- package/dist/es/components/PayTo/components/PayToNameFields.js +1 -1
- package/dist/es/components/PayTo/components/PayToNameFields.js.map +1 -1
- package/dist/es/components/Pix/components/PixQRDetails.js +1 -1
- package/dist/es/components/Pix/components/PixQRDetails.js.map +1 -1
- package/dist/es/components/PreAuthorizedDebitCanada/components/PreAuthorizedDebitCanadaComponent.js +1 -1
- package/dist/es/components/PreAuthorizedDebitCanada/components/PreAuthorizedDebitCanadaComponent.js.map +1 -1
- package/dist/es/components/internal/Address/Address.js +1 -1
- package/dist/es/components/internal/Address/Address.js.map +1 -1
- package/dist/es/components/internal/Address/components/FieldContainer.js +1 -1
- package/dist/es/components/internal/Address/components/FieldContainer.js.map +1 -1
- package/dist/es/components/internal/Address/constants.js +1 -1
- package/dist/es/components/internal/Address/constants.js.map +1 -1
- package/dist/es/components/internal/Address/utils.js +1 -1
- package/dist/es/components/internal/Address/utils.js.map +1 -1
- package/dist/es/components/internal/Button/Button.js +1 -1
- package/dist/es/components/internal/Button/Button.js.map +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPLogin/CtPLogin.js +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPLogin/CtPLogin.js.map +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPLogin/CtPLoginInput.js +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPLogin/CtPLoginInput.js.map +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPLogin/validate.js +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPLogin/validate.js.map +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPOneTimePassword/CtPOneTimePasswordInput/CtPOneTimePasswordInput.js +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPOneTimePassword/CtPOneTimePasswordInput/CtPOneTimePasswordInput.js.map +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPOneTimePassword/CtPOneTimePasswordInput/CtPResendOtpLink.js +1 -1
- package/dist/es/components/internal/ClickToPay/components/CtPOneTimePassword/CtPOneTimePasswordInput/CtPResendOtpLink.js.map +1 -1
- package/dist/es/components/internal/CompanyDetails/CompanyDetails.js +1 -1
- package/dist/es/components/internal/CompanyDetails/CompanyDetails.js.map +1 -1
- package/dist/es/components/internal/FormFields/InputBase.js +1 -1
- package/dist/es/components/internal/FormFields/InputBase.js.map +1 -1
- package/dist/es/components/internal/FormFields/RadioGroup/RadioGroup.js +1 -1
- package/dist/es/components/internal/FormFields/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/es/components/internal/FormFields/Select/Select.js +1 -1
- package/dist/es/components/internal/FormFields/Select/Select.js.map +1 -1
- package/dist/es/components/internal/FormFields/Select/components/SelectList.js +1 -1
- package/dist/es/components/internal/FormFields/Select/components/SelectList.js.map +1 -1
- package/dist/es/components/internal/IbanInput/IbanInput.js +1 -1
- package/dist/es/components/internal/IbanInput/IbanInput.js.map +1 -1
- package/dist/es/components/internal/PersonalDetails/PersonalDetails.js +1 -1
- package/dist/es/components/internal/PersonalDetails/PersonalDetails.js.map +1 -1
- package/dist/es/components/internal/PhoneInput/PhoneInputFields.js +1 -1
- package/dist/es/components/internal/PhoneInput/PhoneInputFields.js.map +1 -1
- package/dist/es/components/internal/SendCopyToEmail/SendCopyToEmail.js +1 -1
- package/dist/es/components/internal/SendCopyToEmail/SendCopyToEmail.js.map +1 -1
- package/dist/es/components/internal/SocialSecurityNumberBrazil/BrazilPersonalDetail.js +1 -1
- package/dist/es/components/internal/SocialSecurityNumberBrazil/BrazilPersonalDetail.js.map +1 -1
- package/dist/es/components/internal/SocialSecurityNumberBrazil/SocialSecurityNumberBrazil.js +1 -1
- package/dist/es/components/internal/SocialSecurityNumberBrazil/SocialSecurityNumberBrazil.js.map +1 -1
- package/dist/es/core/config.js +1 -1
- package/dist/es/external/preact/dist/preact.js +1 -1
- package/dist/es/external/preact/dist/preact.js.map +1 -1
- package/dist/es/index.d.ts +91 -75
- package/dist/es/packages/server/translations/en-US.json.js +1 -1
- package/dist/es/utils/Validator/ValidationRuleResult.js +1 -1
- package/dist/es/utils/Validator/ValidationRuleResult.js.map +1 -1
- package/dist/es/utils/Validator/Validator.js +1 -1
- package/dist/es/utils/Validator/Validator.js.map +1 -1
- package/dist/es/utils/useForm/useForm.js +1 -1
- package/dist/es/utils/useForm/useForm.js.map +1 -1
- package/dist/es-legacy/adyen.css +91 -91
- package/dist/es-legacy/adyen.css.map +1 -1
- package/dist/es-legacy/components/ANCV/components/ANCVInput.js +1 -1
- package/dist/es-legacy/components/ANCV/components/ANCVInput.js.map +1 -1
- package/dist/es-legacy/components/Ach/components/AchComponent.js +1 -1
- package/dist/es-legacy/components/Ach/components/AchComponent.js.map +1 -1
- package/dist/es-legacy/components/Affirm/Affirm.js +1 -1
- package/dist/es-legacy/components/Affirm/Affirm.js.map +1 -1
- package/dist/es-legacy/components/Affirm/config.js +1 -1
- package/dist/es-legacy/components/Affirm/config.js.map +1 -1
- package/dist/es-legacy/components/BacsDD/components/BacsInput.js +1 -1
- package/dist/es-legacy/components/BacsDD/components/BacsInput.js.map +1 -1
- package/dist/es-legacy/components/BankTransfer/components/BankTransferInput/BankTransferInput.js +1 -1
- package/dist/es-legacy/components/BankTransfer/components/BankTransferInput/BankTransferInput.js.map +1 -1
- package/dist/es-legacy/components/Card/components/CardInput/components/StoredCardFields.js +1 -1
- package/dist/es-legacy/components/Card/components/CardInput/components/StoredCardFields.js.map +1 -1
- package/dist/es-legacy/components/Dragonpay/components/DragonpayInput/DragonpayInput.js +1 -1
- package/dist/es-legacy/components/Dragonpay/components/DragonpayInput/DragonpayInput.js.map +1 -1
- package/dist/es-legacy/components/Dropin/components/PaymentMethod/OrderPaymentMethods.js +1 -1
- package/dist/es-legacy/components/Dropin/components/PaymentMethod/OrderPaymentMethods.js.map +1 -1
- package/dist/es-legacy/components/PayPal/Paypal.js +1 -1
- package/dist/es-legacy/components/PayPal/Paypal.js.map +1 -1
- package/dist/es-legacy/components/PayPal/constants.js +1 -1
- package/dist/es-legacy/components/PayPal/constants.js.map +1 -1
- package/dist/es-legacy/components/PayTo/components/BSBInput.js +1 -1
- package/dist/es-legacy/components/PayTo/components/BSBInput.js.map +1 -1
- package/dist/es-legacy/components/PayTo/components/PayIDInput.js +1 -1
- package/dist/es-legacy/components/PayTo/components/PayIDInput.js.map +1 -1
- package/dist/es-legacy/components/PayTo/components/PayToNameFields.js +1 -1
- package/dist/es-legacy/components/PayTo/components/PayToNameFields.js.map +1 -1
- package/dist/es-legacy/components/Pix/components/PixQRDetails.js +1 -1
- package/dist/es-legacy/components/Pix/components/PixQRDetails.js.map +1 -1
- package/dist/es-legacy/components/PreAuthorizedDebitCanada/components/PreAuthorizedDebitCanadaComponent.js +1 -1
- package/dist/es-legacy/components/PreAuthorizedDebitCanada/components/PreAuthorizedDebitCanadaComponent.js.map +1 -1
- package/dist/es-legacy/components/internal/Address/Address.js +1 -1
- package/dist/es-legacy/components/internal/Address/Address.js.map +1 -1
- package/dist/es-legacy/components/internal/Address/components/FieldContainer.js +1 -1
- package/dist/es-legacy/components/internal/Address/components/FieldContainer.js.map +1 -1
- package/dist/es-legacy/components/internal/Address/constants.js +1 -1
- package/dist/es-legacy/components/internal/Address/constants.js.map +1 -1
- package/dist/es-legacy/components/internal/Address/utils.js +1 -1
- package/dist/es-legacy/components/internal/Address/utils.js.map +1 -1
- package/dist/es-legacy/components/internal/Button/Button.js +1 -1
- package/dist/es-legacy/components/internal/Button/Button.js.map +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPLogin/CtPLogin.js +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPLogin/CtPLogin.js.map +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPLogin/CtPLoginInput.js +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPLogin/CtPLoginInput.js.map +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPLogin/validate.js +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPLogin/validate.js.map +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPOneTimePassword/CtPOneTimePasswordInput/CtPOneTimePasswordInput.js +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPOneTimePassword/CtPOneTimePasswordInput/CtPOneTimePasswordInput.js.map +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPOneTimePassword/CtPOneTimePasswordInput/CtPResendOtpLink.js +1 -1
- package/dist/es-legacy/components/internal/ClickToPay/components/CtPOneTimePassword/CtPOneTimePasswordInput/CtPResendOtpLink.js.map +1 -1
- package/dist/es-legacy/components/internal/CompanyDetails/CompanyDetails.js +1 -1
- package/dist/es-legacy/components/internal/CompanyDetails/CompanyDetails.js.map +1 -1
- package/dist/es-legacy/components/internal/FormFields/InputBase.js +1 -1
- package/dist/es-legacy/components/internal/FormFields/InputBase.js.map +1 -1
- package/dist/es-legacy/components/internal/FormFields/RadioGroup/RadioGroup.js +1 -1
- package/dist/es-legacy/components/internal/FormFields/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/es-legacy/components/internal/FormFields/Select/Select.js +1 -1
- package/dist/es-legacy/components/internal/FormFields/Select/Select.js.map +1 -1
- package/dist/es-legacy/components/internal/FormFields/Select/components/SelectList.js +1 -1
- package/dist/es-legacy/components/internal/FormFields/Select/components/SelectList.js.map +1 -1
- package/dist/es-legacy/components/internal/IbanInput/IbanInput.js +1 -1
- package/dist/es-legacy/components/internal/IbanInput/IbanInput.js.map +1 -1
- package/dist/es-legacy/components/internal/PersonalDetails/PersonalDetails.js +1 -1
- package/dist/es-legacy/components/internal/PersonalDetails/PersonalDetails.js.map +1 -1
- package/dist/es-legacy/components/internal/PhoneInput/PhoneInputFields.js +1 -1
- package/dist/es-legacy/components/internal/PhoneInput/PhoneInputFields.js.map +1 -1
- package/dist/es-legacy/components/internal/SendCopyToEmail/SendCopyToEmail.js +1 -1
- package/dist/es-legacy/components/internal/SendCopyToEmail/SendCopyToEmail.js.map +1 -1
- package/dist/es-legacy/components/internal/SocialSecurityNumberBrazil/BrazilPersonalDetail.js +1 -1
- package/dist/es-legacy/components/internal/SocialSecurityNumberBrazil/BrazilPersonalDetail.js.map +1 -1
- package/dist/es-legacy/components/internal/SocialSecurityNumberBrazil/SocialSecurityNumberBrazil.js +1 -1
- package/dist/es-legacy/components/internal/SocialSecurityNumberBrazil/SocialSecurityNumberBrazil.js.map +1 -1
- package/dist/es-legacy/core/config.js +1 -1
- package/dist/es-legacy/external/preact/dist/preact.js +1 -1
- package/dist/es-legacy/external/preact/dist/preact.js.map +1 -1
- package/dist/es-legacy/packages/server/translations/en-US.json.js +1 -1
- package/dist/es-legacy/utils/Validator/ValidationRuleResult.js +1 -1
- package/dist/es-legacy/utils/Validator/ValidationRuleResult.js.map +1 -1
- package/dist/es-legacy/utils/Validator/Validator.js +1 -1
- package/dist/es-legacy/utils/Validator/Validator.js.map +1 -1
- package/dist/es-legacy/utils/useForm/useForm.js +1 -1
- package/dist/es-legacy/utils/useForm/useForm.js.map +1 -1
- package/package.json +17 -17
- package/styles/adyen.css +91 -91
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Paypal.js","sources":["../../../../src/components/PayPal/Paypal.tsx"],"sourcesContent":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport PaypalComponent from './components/PaypalComponent';\nimport defaultProps from './defaultProps';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { ERRORS } from './constants';\nimport { TxVariants } from '../tx-variants';\nimport { formatPaypalOrderContactToAdyenFormat } from './utils/format-paypal-order-contact-to-adyen-format';\n\nimport type { ICore } from '../../core/types';\nimport type { PaymentAction } from '../../types/global-types';\nimport type { Intent, PayPalConfiguration } from './types';\nimport type {\n PayPalOnApproveActions,\n PayPalOnApproveData,\n PayPalOnShippingAddressChangeActions,\n PayPalOnShippingAddressChangeData,\n PayPalOnShippingOptionsChangeActions,\n PayPalOnShippingOptionsChangeData,\n PayPalOrderResponseBody\n} from './paypal-js-types';\n\nimport { AnalyticsInfoEvent, InfoEventType } from '../../core/Analytics/events/AnalyticsInfoEvent';\nimport './Paypal.scss';\n\nclass PaypalElement extends UIElement<PayPalConfiguration> {\n public static readonly type = TxVariants.paypal;\n public static readonly subtype = 'sdk';\n\n public paymentData: string | null = null;\n\n private resolve: ((value: string) => void) | null = null;\n private reject: ((error?: Error) => void) | null = null;\n\n protected static readonly defaultProps = defaultProps;\n\n constructor(checkout: ICore, props?: PayPalConfiguration) {\n super(checkout, props);\n this.handleSubmit = this.handleSubmit.bind(this);\n this.handleOnShippingAddressChange = this.handleOnShippingAddressChange.bind(this);\n this.handleOnShippingOptionsChange = this.handleOnShippingOptionsChange.bind(this);\n }\n\n formatProps(props: PayPalConfiguration): PayPalConfiguration {\n const merchantId = props.configuration?.merchantId;\n const intentFromConfig = props.configuration?.intent;\n const isZeroAuth = props.amount?.value === 0;\n const intent: Intent | undefined = isZeroAuth ? 'tokenize' : props.intent || intentFromConfig;\n const vault = intent === 'tokenize' || props.vault;\n\n const displayContinueToReviewPageButton = props.userAction === 'continue';\n\n return {\n ...props,\n commit: displayContinueToReviewPageButton ? false : props.commit,\n vault,\n configuration: {\n intent,\n merchantId\n }\n };\n }\n\n protected override beforeRender(configSetByMerchant?: PayPalConfiguration) {\n const event = new AnalyticsInfoEvent({\n type: InfoEventType.rendered,\n component: this.type,\n configData: { ...configSetByMerchant, showPayButton: this.props.showPayButton },\n ...(configSetByMerchant?.isExpress && { isExpress: configSetByMerchant.isExpress }),\n ...(configSetByMerchant?.expressPage && { expressPage: configSetByMerchant.expressPage })\n });\n\n this.analytics.sendAnalytics(event);\n }\n\n public submit = () => {\n this.handleError(new AdyenCheckoutError('IMPLEMENTATION_ERROR', ERRORS.SUBMIT_NOT_SUPPORTED));\n };\n\n /**\n * Updates the paymentData value. It must be used in the PayPal Express flow, when patching the amount\n * @param paymentData - Payment data value\n */\n public updatePaymentData(paymentData: string): void {\n if (!paymentData) console.warn('PayPal - Updating payment data with an invalid value');\n this.paymentData = paymentData;\n }\n\n /**\n * Formats the component data output\n */\n protected formatData() {\n const { isExpress, userAction } = this.props;\n\n return {\n paymentMethod: {\n type: PaypalElement.type,\n userAction,\n subtype: isExpress ? 'express' : PaypalElement.subtype\n }\n };\n }\n\n public handleAction = (action: PaymentAction) => {\n return this.updateWithAction(action);\n };\n\n public updateWithAction = (action: PaymentAction) => {\n if (action.paymentMethodType !== this.type) throw new Error('Invalid Action');\n\n if (action.paymentData) {\n this.paymentData = action.paymentData;\n }\n\n if (action.sdkData && action.sdkData.token) {\n this.onActionHandled({ componentType: this.type, actionDescription: 'sdk-loaded', originalAction: action });\n this.handleResolve(action.sdkData.token);\n } else {\n this.handleReject(ERRORS.NO_TOKEN_PROVIDED);\n }\n\n return null;\n };\n\n /**\n * Dropin Validation\n *\n * @remarks\n * Paypal does not require any specific Dropin validation\n */\n get isValid() {\n return true;\n }\n\n private readonly handleOnApprove = (data: PayPalOnApproveData, actions: PayPalOnApproveActions): Promise<void> => {\n const { onAuthorized } = this.props;\n const state = { data: { details: data, paymentData: this.paymentData ?? undefined } };\n\n if (!onAuthorized) {\n this.handleAdditionalDetails(state);\n return Promise.resolve();\n }\n\n if (!actions.order) {\n this.handleError(new AdyenCheckoutError('ERROR', 'PayPal order actions are not available'));\n return Promise.resolve();\n }\n\n return actions.order\n .get()\n .then((paypalOrder: PayPalOrderResponseBody) => {\n const billingAddress = formatPaypalOrderContactToAdyenFormat(paypalOrder?.payer);\n const deliveryAddress = formatPaypalOrderContactToAdyenFormat(paypalOrder?.purchase_units?.[0].shipping, true);\n\n this.setState({\n authorizedEvent: paypalOrder,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n });\n\n return new Promise<void>((resolve, reject) =>\n onAuthorized(\n {\n authorizedEvent: paypalOrder,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n },\n { resolve, reject }\n )\n );\n })\n .then(() => this.handleAdditionalDetails(state))\n .catch(error => this.handleError(new AdyenCheckoutError('ERROR', 'Something went wrong while parsing PayPal Order', { cause: error })));\n };\n\n handleResolve(token: string) {\n if (!this.resolve) return this.handleError(new AdyenCheckoutError('ERROR', ERRORS.WRONG_INSTANCE));\n this.resolve(token);\n }\n\n handleReject(errorMessage: string) {\n if (!this.reject) return this.handleError(new AdyenCheckoutError('ERROR', ERRORS.WRONG_INSTANCE));\n this.reject(new Error(errorMessage));\n }\n\n private handleSubmit(): Promise<string> {\n super.submit();\n\n return new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n\n /**\n * If the merchant provides the 'onShippingAddressChange' callback, then this method is used as a wrapper to it, in order\n * to expose to the merchant the 'component' instance. The merchant needs the 'component' in order to manipulate the\n * paymentData\n *\n * @param data - PayPal data\n * @param actions - PayPal actions.\n */\n private handleOnShippingAddressChange(data: PayPalOnShippingAddressChangeData, actions: PayPalOnShippingAddressChangeActions): Promise<void> {\n const { onShippingAddressChange } = this.props;\n\n if (!onShippingAddressChange) return Promise.resolve();\n\n return onShippingAddressChange(data, actions, this);\n }\n\n /**\n * If the merchant provides the 'onShippingOptionsChange' callback, then this method is used as a wrapper to it, in order\n * to expose to the merchant the 'component' instance. The merchant needs the 'component' in order to manipulate the\n * paymentData\n *\n * @param data - PayPal data\n * @param actions - PayPal actions.\n */\n private handleOnShippingOptionsChange(data: PayPalOnShippingOptionsChangeData, actions: PayPalOnShippingOptionsChangeActions): Promise<void> {\n const { onShippingOptionsChange } = this.props;\n\n if (!onShippingOptionsChange) return Promise.resolve();\n\n return onShippingOptionsChange(data, actions, this);\n }\n\n protected override componentToRender(): h.JSX.Element | null {\n if (!this.props.showPayButton) return null;\n\n const { onShippingAddressChange, onShippingOptionsChange, ...rest } = this.props;\n\n return (\n <PaypalComponent\n {...rest}\n setComponentRef={this.setComponentRef}\n {...(onShippingAddressChange && { onShippingAddressChange: this.handleOnShippingAddressChange })}\n {...(onShippingOptionsChange && { onShippingOptionsChange: this.handleOnShippingOptionsChange })}\n onCancel={() => this.handleError(new AdyenCheckoutError('CANCEL'))}\n onChange={this.setState}\n onApprove={this.handleOnApprove}\n onError={error => {\n this.handleError(new AdyenCheckoutError('ERROR', String(error), { cause: error }));\n }}\n onScriptLoadFailure={error => this.handleError(error)}\n onSubmit={this.handleSubmit}\n />\n );\n }\n}\n\nexport default PaypalElement;\n"],"names":["PaypalElement","UIElement","formatProps","props","merchantId","configuration","intentFromConfig","intent","amount","value","vault","displayContinueToReviewPageButton","userAction","commit","beforeRender","configSetByMerchant","event","AnalyticsInfoEvent","type","InfoEventType","rendered","component","this","configData","showPayButton","isExpress","expressPage","analytics","sendAnalytics","updatePaymentData","paymentData","console","warn","formatData","paymentMethod","subtype","isValid","handleResolve","token","resolve","handleError","AdyenCheckoutError","ERRORS","WRONG_INSTANCE","handleReject","errorMessage","reject","Error","handleSubmit","super","submit","Promise","handleOnShippingAddressChange","data","actions","onShippingAddressChange","handleOnShippingOptionsChange","onShippingOptionsChange","componentToRender","rest","h","PaypalComponent","setComponentRef","onCancel","onChange","setState","onApprove","handleOnApprove","onError","error","String","cause","onScriptLoadFailure","onSubmit","constructor","checkout","_define_property","SUBMIT_NOT_SUPPORTED","handleAction","action","updateWithAction","paymentMethodType","sdkData","onActionHandled","componentType","actionDescription","originalAction","NO_TOKEN_PROVIDED","onAuthorized","state","details","undefined","order","get","then","paypalOrder","billingAddress","formatPaypalOrderContactToAdyenFormat","payer","deliveryAddress","purchase_units","shipping","authorizedEvent","handleAdditionalDetails","catch","bind","TxVariants","paypal","defaultProps"],"mappings":"mrBAyBA,MAAMA,UAAsBC,EAkBxBC,WAAAA,CAAYC,GACR,MAAMC,EAAaD,EAAME,eAAeD,WAClCE,EAAmBH,EAAME,eAAeE,OAExCA,EADqC,IAAxBJ,EAAMK,QAAQC,MACe,WAAaN,EAAMI,QAAUD,EACvEI,EAAmB,aAAXH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":["import { h } from 'preact';\nimport UIElement from '../internal/UIElement/UIElement';\nimport PaypalComponent from './components/PaypalComponent';\nimport defaultProps from './defaultProps';\nimport AdyenCheckoutError from '../../core/Errors/AdyenCheckoutError';\nimport { ERRORS } from './constants';\nimport { TxVariants } from '../tx-variants';\nimport { formatPaypalOrderContactToAdyenFormat } from './utils/format-paypal-order-contact-to-adyen-format';\n\nimport type { ICore } from '../../core/types';\nimport type { PaymentAction, PaymentResponseData } from '../../types/global-types';\nimport type { Intent, PayPalConfiguration } from './types';\nimport type {\n PayPalOnApproveActions,\n PayPalOnApproveData,\n PayPalOnShippingAddressChangeActions,\n PayPalOnShippingAddressChangeData,\n PayPalOnShippingOptionsChangeActions,\n PayPalOnShippingOptionsChangeData,\n PayPalOrderResponseBody\n} from './paypal-js-types';\n\nimport { AnalyticsInfoEvent, InfoEventType } from '../../core/Analytics/events/AnalyticsInfoEvent';\nimport { sanitizeResponse, verifyPaymentDidNotFail } from '../internal/UIElement/utils';\nimport CancelError from '../../core/Errors/CancelError';\nimport './Paypal.scss';\n\nclass PaypalElement extends UIElement<PayPalConfiguration> {\n public static readonly type = TxVariants.paypal;\n public static readonly subtype = 'sdk';\n\n public paymentData: string | null = null;\n\n private resolve: ((value: string) => void) | null = null;\n private reject: ((error?: Error) => void) | null = null;\n\n protected static readonly defaultProps = defaultProps;\n\n constructor(checkout: ICore, props?: PayPalConfiguration) {\n super(checkout, props);\n this.handleSubmit = this.handleSubmit.bind(this);\n this.handleOnShippingAddressChange = this.handleOnShippingAddressChange.bind(this);\n this.handleOnShippingOptionsChange = this.handleOnShippingOptionsChange.bind(this);\n }\n\n formatProps(props: PayPalConfiguration): PayPalConfiguration {\n const merchantId = props.configuration?.merchantId;\n const intentFromConfig = props.configuration?.intent;\n const isZeroAuth = props.amount?.value === 0;\n const intent: Intent | undefined = isZeroAuth ? 'tokenize' : props.intent || intentFromConfig;\n const vault = intent === 'tokenize' || props.vault;\n\n const displayContinueToReviewPageButton = props.userAction === 'continue';\n\n return {\n ...props,\n commit: displayContinueToReviewPageButton ? false : props.commit,\n vault,\n configuration: {\n intent,\n merchantId\n }\n };\n }\n\n protected override beforeRender(configSetByMerchant?: PayPalConfiguration) {\n const event = new AnalyticsInfoEvent({\n type: InfoEventType.rendered,\n component: this.type,\n configData: { ...configSetByMerchant, showPayButton: this.props.showPayButton },\n ...(configSetByMerchant?.isExpress && { isExpress: configSetByMerchant.isExpress }),\n ...(configSetByMerchant?.expressPage && { expressPage: configSetByMerchant.expressPage })\n });\n\n this.analytics.sendAnalytics(event);\n }\n\n public submit = () => {\n this.handleError(new AdyenCheckoutError('IMPLEMENTATION_ERROR', ERRORS.SUBMIT_NOT_SUPPORTED));\n };\n\n /**\n * Updates the paymentData value. It must be used in the PayPal Express flow, when patching the amount\n * @param paymentData - Payment data value\n */\n public updatePaymentData(paymentData: string): void {\n if (!paymentData) console.warn('PayPal - Updating payment data with an invalid value');\n this.paymentData = paymentData;\n }\n\n /**\n * Formats the component data output\n */\n protected formatData() {\n const { isExpress, userAction } = this.props;\n\n return {\n paymentMethod: {\n type: PaypalElement.type,\n userAction,\n subtype: isExpress ? 'express' : PaypalElement.subtype\n }\n };\n }\n\n public handleAction = (action: PaymentAction) => {\n return this.updateWithAction(action);\n };\n\n public updateWithAction = (action: PaymentAction) => {\n if (action.paymentMethodType !== this.type) throw new Error('Invalid Action');\n\n if (action.paymentData) {\n this.paymentData = action.paymentData;\n }\n\n if (action.sdkData && action.sdkData.token) {\n this.onActionHandled({ componentType: this.type, actionDescription: 'sdk-loaded', originalAction: action });\n this.handleResolve(action.sdkData.token);\n } else {\n this.handleReject(ERRORS.NO_TOKEN_PROVIDED);\n }\n\n return null;\n };\n\n /**\n * Dropin Validation\n *\n * @remarks\n * Paypal does not require any specific Dropin validation\n */\n get isValid() {\n return true;\n }\n\n private readonly handleOnApprove = (data: PayPalOnApproveData, actions: PayPalOnApproveActions): Promise<void> => {\n const { onAuthorized } = this.props;\n const state = { data: { details: data, paymentData: this.paymentData ?? undefined } };\n\n if (!onAuthorized) {\n this.handleAdditionalDetails(state);\n return Promise.resolve();\n }\n\n if (!actions.order) {\n this.handleError(new AdyenCheckoutError('ERROR', 'PayPal order actions are not available'));\n return Promise.resolve();\n }\n\n return actions.order\n .get()\n .then((paypalOrder: PayPalOrderResponseBody) => {\n const billingAddress = formatPaypalOrderContactToAdyenFormat(paypalOrder?.payer);\n const deliveryAddress = formatPaypalOrderContactToAdyenFormat(paypalOrder?.purchase_units?.[0].shipping, true);\n\n this.setState({\n authorizedEvent: paypalOrder,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n });\n\n return new Promise<void>((resolve, reject) =>\n onAuthorized(\n {\n authorizedEvent: paypalOrder,\n ...(billingAddress && { billingAddress }),\n ...(deliveryAddress && { deliveryAddress })\n },\n { resolve, reject }\n )\n );\n })\n .then(() => this.handleAdditionalDetails(state))\n .catch(error => this.handleError(new AdyenCheckoutError('ERROR', 'Something went wrong while parsing PayPal Order', { cause: error })));\n };\n\n handleResolve(token: string) {\n if (!this.resolve) return this.handleError(new AdyenCheckoutError('ERROR', ERRORS.WRONG_INSTANCE));\n this.resolve(token);\n }\n\n handleReject(errorMessage: string) {\n if (!this.reject) return this.handleError(new AdyenCheckoutError('ERROR', ERRORS.WRONG_INSTANCE));\n this.reject(new Error(errorMessage));\n }\n\n private handleSubmit(): Promise<string> {\n return new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n\n this.makePaymentsCall()\n .then(sanitizeResponse)\n .then(verifyPaymentDidNotFail)\n .then(this.handleResponse)\n .catch((e: PaymentResponseData | Error) => {\n if (e instanceof CancelError) {\n this.setElementStatus('ready');\n return;\n }\n this.handleFailedResult(e as PaymentResponseData);\n const errorDetail = e instanceof Error ? e.message : JSON.stringify(e);\n const errorMessage = e ? `: ${errorDetail}` : '';\n this.handleReject(`${ERRORS.PAYMENT_FAILED}${errorMessage}`);\n });\n });\n }\n\n /**\n * If the merchant provides the 'onShippingAddressChange' callback, then this method is used as a wrapper to it, in order\n * to expose to the merchant the 'component' instance. The merchant needs the 'component' in order to manipulate the\n * paymentData\n *\n * @param data - PayPal data\n * @param actions - PayPal actions.\n */\n private handleOnShippingAddressChange(data: PayPalOnShippingAddressChangeData, actions: PayPalOnShippingAddressChangeActions): Promise<void> {\n const { onShippingAddressChange } = this.props;\n\n if (!onShippingAddressChange) return Promise.resolve();\n\n return onShippingAddressChange(data, actions, this);\n }\n\n /**\n * If the merchant provides the 'onShippingOptionsChange' callback, then this method is used as a wrapper to it, in order\n * to expose to the merchant the 'component' instance. The merchant needs the 'component' in order to manipulate the\n * paymentData\n *\n * @param data - PayPal data\n * @param actions - PayPal actions.\n */\n private handleOnShippingOptionsChange(data: PayPalOnShippingOptionsChangeData, actions: PayPalOnShippingOptionsChangeActions): Promise<void> {\n const { onShippingOptionsChange } = this.props;\n\n if (!onShippingOptionsChange) return Promise.resolve();\n\n return onShippingOptionsChange(data, actions, this);\n }\n\n protected override componentToRender(): h.JSX.Element | null {\n if (!this.props.showPayButton) return null;\n\n const { onShippingAddressChange, onShippingOptionsChange, ...rest } = this.props;\n\n return (\n <PaypalComponent\n {...rest}\n setComponentRef={this.setComponentRef}\n {...(onShippingAddressChange && { onShippingAddressChange: this.handleOnShippingAddressChange })}\n {...(onShippingOptionsChange && { onShippingOptionsChange: this.handleOnShippingOptionsChange })}\n onCancel={() => this.handleError(new AdyenCheckoutError('CANCEL'))}\n onChange={this.setState}\n onApprove={this.handleOnApprove}\n onError={error => {\n this.handleError(new AdyenCheckoutError('ERROR', String(error), { cause: error }));\n }}\n onScriptLoadFailure={error => this.handleError(error)}\n onSubmit={this.handleSubmit}\n />\n );\n }\n}\n\nexport default PaypalElement;\n"],"names":["PaypalElement","UIElement","formatProps","props","merchantId","configuration","intentFromConfig","intent","amount","value","vault","displayContinueToReviewPageButton","userAction","commit","beforeRender","configSetByMerchant","event","AnalyticsInfoEvent","type","InfoEventType","rendered","component","this","configData","showPayButton","isExpress","expressPage","analytics","sendAnalytics","updatePaymentData","paymentData","console","warn","formatData","paymentMethod","subtype","isValid","handleResolve","token","resolve","handleError","AdyenCheckoutError","ERRORS","WRONG_INSTANCE","handleReject","errorMessage","reject","Error","handleSubmit","Promise","makePaymentsCall","then","sanitizeResponse","verifyPaymentDidNotFail","handleResponse","catch","e","CancelError","setElementStatus","handleFailedResult","errorDetail","message","JSON","stringify","PAYMENT_FAILED","handleOnShippingAddressChange","data","actions","onShippingAddressChange","handleOnShippingOptionsChange","onShippingOptionsChange","componentToRender","rest","h","PaypalComponent","setComponentRef","onCancel","onChange","setState","onApprove","handleOnApprove","onError","error","String","cause","onScriptLoadFailure","onSubmit","constructor","checkout","super","_define_property","submit","SUBMIT_NOT_SUPPORTED","handleAction","action","updateWithAction","paymentMethodType","sdkData","onActionHandled","componentType","actionDescription","originalAction","NO_TOKEN_PROVIDED","onAuthorized","state","details","undefined","order","get","paypalOrder","billingAddress","formatPaypalOrderContactToAdyenFormat","payer","deliveryAddress","purchase_units","shipping","authorizedEvent","handleAdditionalDetails","bind","TxVariants","paypal","defaultProps"],"mappings":"k0BA2BA,MAAMA,UAAsBC,EAkBxBC,WAAAA,CAAYC,GACR,MAAMC,EAAaD,EAAME,eAAeD,WAClCE,EAAmBH,EAAME,eAAeE,OAExCA,EADqC,IAAxBJ,EAAMK,QAAQC,MACe,WAAaN,EAAMI,QAAUD,EACvEI,EAAmB,aAAXH,GAAyBJ,EAAMO,MAEvCC,EAAyD,aAArBR,EAAMS,WAEhD,MAAO,IACAT,EACHU,QAAQF,GAA4CR,EAAMU,OAC1DH,QACAL,cAAe,CACXE,SACAH,cAGZ,CAEmBU,YAAAA,CAAaC,GAC5B,MAAMC,EAAQ,IAAIC,EAAmB,CACjCC,KAAMC,EAAcC,SACpBC,UAAWC,KAAKJ,KAChBK,WAAY,IAAKR,EAAqBS,cAAeF,KAAKnB,MAAMqB,kBAC5DT,GAAqBU,WAAa,CAAEA,UAAWV,EAAoBU,cACnEV,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OG,QAAQ3D,QAElChB,KAAKsB,aAAaF,EAAO4D,mBAGtB,OAaXZ,EAAApE,KAAiB0D,kBAAkB,CAACd,EAA2BC,KAC3D,MAAMoC,aAAEA,GAAiBjF,KAAKnB,MACxBqG,EAAQ,CAAEtC,KAAM,CAAEuC,QAASvC,EAAMpC,YAAaR,KAAKQ,kBAAe4E,IAExE,OAAKH,EAKApC,EAAQwC,MAKNxC,EAAQwC,MACVC,MACAzD,KAAM0D,IACH,MAAMC,EAAiBC,EAAsCF,GAAaG,OACpEC,EAAkBF,EAAsCF,GAAaK,iBAAiB,GAAGC,UAAU,GAQzG,OANA7F,KAAKwD,SAAS,CACVsC,gBAAiBP,KACbC,GAAkB,CAAEA,qBACpBG,GAAmB,CAAEA,qBAGtB,IAAIhE,QAAc,CAACV,EAASO,IAC/ByD,EACI,CACIa,gBAAiBP,KACbC,GAAkB,CAAEA,qBACpBG,GAAmB,CAAEA,oBAE7B,CAAE1E,UAASO,cAItBK,KAAK,IAAM7B,KAAK+F,wBAAwBb,IACxCjD,MAAM2B,GAAS5D,KAAKkB,YAAY,IAAIC,EAAmB,QAAS,kDAAmD,CAAE2C,MAAOF,OA5B7H5D,KAAKkB,YAAY,IAAIC,EAAmB,QAAS,2CAC1CQ,QAAQV,YANfjB,KAAK+F,wBAAwBb,GACtBvD,QAAQV,aAtGnBjB,KAAK0B,aAAe1B,KAAK0B,aAAasE,KAAKhG,MAC3CA,KAAK2C,8BAAgC3C,KAAK2C,8BAA8BqD,KAAKhG,MAC7EA,KAAK+C,8BAAgC/C,KAAK+C,8BAA8BiD,KAAKhG,KACjF,EAfAoE,EADE1F,EACqBkB,OAAOqG,EAAWC,QACzC9B,EAFE1F,EAEqBmC,UAAU,OAOjCuD,EATE1F,EASwByH,eAAeA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const t={NO_TOKEN_PROVIDED:"No token was provided",SUBMIT_NOT_SUPPORTED:"Calling submit() is not supported for this payment method",WRONG_INSTANCE:"The instance of the PayPal component being used is not the same which started the payment"};export{t as ERRORS};
|
|
1
|
+
const t={NO_TOKEN_PROVIDED:"No token was provided",SUBMIT_NOT_SUPPORTED:"Calling submit() is not supported for this payment method",WRONG_INSTANCE:"The instance of the PayPal component being used is not the same which started the payment",PAYMENT_FAILED:"Something went wrong during PayPal payment"};export{t as ERRORS};
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../src/components/PayPal/constants.ts"],"sourcesContent":["export const ERRORS = {\n INVALID_ACTION: 'Invalid Action',\n NO_TOKEN_PROVIDED: 'No token was provided',\n PAYPAL_OVERLAY_CLOSED: 'PayPal overlay closed',\n SUBMIT_NOT_SUPPORTED: 'Calling submit() is not supported for this payment method',\n WRONG_INSTANCE: 'The instance of the PayPal component being used is not the same which started the payment'\n};\n"],"names":["ERRORS","NO_TOKEN_PROVIDED","SUBMIT_NOT_SUPPORTED","WRONG_INSTANCE"],"mappings":"MAAaA,EAAS,CAElBC,kBAAmB,wBAEnBC,qBAAsB,4DACtBC,eAAgB"}
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../src/components/PayPal/constants.ts"],"sourcesContent":["export const ERRORS = {\n INVALID_ACTION: 'Invalid Action',\n NO_TOKEN_PROVIDED: 'No token was provided',\n PAYPAL_OVERLAY_CLOSED: 'PayPal overlay closed',\n SUBMIT_NOT_SUPPORTED: 'Calling submit() is not supported for this payment method',\n WRONG_INSTANCE: 'The instance of the PayPal component being used is not the same which started the payment',\n PAYMENT_FAILED: 'Something went wrong during PayPal payment'\n};\n"],"names":["ERRORS","NO_TOKEN_PROVIDED","SUBMIT_NOT_SUPPORTED","WRONG_INSTANCE","PAYMENT_FAILED"],"mappings":"MAAaA,EAAS,CAElBC,kBAAmB,wBAEnBC,qBAAsB,4DACtBC,eAAgB,4FAChBC,eAAgB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createElement as e}from"../../../external/preact/dist/preact.js";import r from"../../internal/FormFields/Fieldset/Fieldset.js";import{useEffect as t,useRef as a}from"../../../external/preact/hooks/dist/hooks.js";import o from"../../../utils/useForm/useFormWithA11y.js";import"../../internal/SecuredFields/lib/CSF/utils/userAgent.js";import{getErrorMessage as
|
|
1
|
+
import{createElement as e}from"../../../external/preact/dist/preact.js";import r from"../../internal/FormFields/Fieldset/Fieldset.js";import{useEffect as t,useRef as a}from"../../../external/preact/hooks/dist/hooks.js";import{useCoreContext as o}from"../../../core/Context/CoreProvider.js";import s from"../../../utils/useForm/useFormWithA11y.js";import"../../internal/SecuredFields/lib/CSF/utils/userAgent.js";import{getErrorMessage as n}from"../../../utils/getErrorMessage.js";import i from"../../internal/FormFields/Field/Field.js";import l from"../../internal/FormFields/InputText.js";import{bsbValidationRules as u}from"./validate.js";import{phoneFormatters as b}from"../../internal/PhoneInput/validate.js";import m from"./PayToNameFields.js";const c=["bankAccountNumber","bsb","firstName","lastName"];function d({setComponentRef:d,defaultData:p,placeholders:f,onChange:h,setStatus:F,id:N}){const{i18n:k}=o(),g=s({schema:c,defaultData:p,rules:u,formatters:b,formHolder:`#${N}`}),{handleChangeFor:A,triggerValidation:j,data:v,errors:B,valid:C,isValid:S}=g;t(()=>{h({data:v,valid:C,errors:B,isValid:S})},[v,C,B,S]);const y=a({setStatus:F,showValidation:j});return t(()=>{d(y.current)},[d]),e(r,{id:N,classNameModifiers:["payto__bsb_input"],label:"BSB",description:"payto.bsb.description"},e(i,{label:k.get("payto.bsb.label.bankAccountNumber"),classNameModifiers:["col-60","bankAccountNumber"],errorMessage:n(k,B.bankAccountNumber,k.get("payto.bsb.label.bankAccountNumber")),name:"bankAccountNumber",i18n:k,errorLive:!0},e(l,{name:"bankAccountNumber",value:v.bankAccountNumber,onInput:A("bankAccountNumber","input"),onBlur:A("bankAccountNumber","blur"),placeholder:f?.bankAccountNumber,required:!0,autocomplete:void 0})),e(i,{label:k.get("Bank State Branch"),classNameModifiers:["col-40","bsb"],errorMessage:n(k,B.bsb,k.get("Bank State Branch")),name:"bsb",i18n:k,errorLive:!0},e(l,{name:"bsb",value:v.bsb,onInput:A("bsb","input"),onBlur:A("bsb","blur"),placeholder:f?.bsb,required:!0,autocomplete:void 0})),e(m,{i18n:k,data:v,handleChangeFor:A,errors:B,placeholders:f}))}export{d as default};
|
|
2
2
|
//# sourceMappingURL=BSBInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BSBInput.js","sources":["../../../../../src/components/PayTo/components/BSBInput.tsx"],"sourcesContent":["import { h } from 'preact';\nimport Fieldset from '../../internal/FormFields/Fieldset';\nimport { useEffect, useRef } from 'preact/hooks';\nimport { useFormWithA11y } from '../../../utils/useForm';\nimport { getErrorMessage } from '../../../utils/getErrorMessage';\nimport Field from '../../internal/FormFields/Field';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport InputText from '../../internal/FormFields/InputText';\nimport { bsbValidationRules } from './validate';\nimport './PayIDInput.scss';\nimport { phoneFormatters } from '../../internal/PhoneInput/validate';\nimport { ComponentMethodsRef, UIElementStatus } from '../../internal/UIElement/types';\nimport PayToNameFields from './PayToNameFields';\nimport { PayToPlaceholdersType } from '../types';\n\nexport interface BSBFormData {\n bsb: string;\n bankAccountNumber: string;\n firstName: string;\n lastName: string;\n}\n\nexport interface BSBInputProps {\n status: UIElementStatus;\n setStatus: (status: UIElementStatus) => void;\n defaultData: BSBFormData;\n placeholders: PayToPlaceholdersType;\n onChange: (e) => void;\n setComponentRef: (ref: ComponentMethodsRef) => void;\n id?: string;\n}\n\nconst BASE_SCHEMA = ['bankAccountNumber', 'bsb', 'firstName', 'lastName'];\n\nexport default function BSBInput({ setComponentRef, defaultData, placeholders, onChange, setStatus, id }: Readonly<BSBInputProps>) {\n const { i18n } = useCoreContext();\n\n const form = useFormWithA11y<BSBFormData>({\n schema: BASE_SCHEMA,\n defaultData: defaultData,\n rules: bsbValidationRules,\n formatters: phoneFormatters,\n formHolder: `#${id}`\n });\n const { handleChangeFor, triggerValidation, data, errors, valid, isValid } = form;\n\n // standard onChange propagate to parent state\n useEffect(() => {\n onChange({ data, valid, errors, isValid });\n }, [data, valid, errors, isValid]);\n\n const payToRef = useRef<ComponentMethodsRef>({\n setStatus: setStatus,\n showValidation: triggerValidation\n });\n\n useEffect(() => {\n setComponentRef(payToRef.current);\n }, [setComponentRef]);\n\n return (\n <Fieldset id={id} classNameModifiers={['payto__bsb_input']} label={'BSB'} description={'payto.bsb.description'}>\n <Field\n label={i18n.get('payto.bsb.label.bankAccountNumber')}\n classNameModifiers={['col-60', 'bankAccountNumber']}\n errorMessage={getErrorMessage(i18n, errors.bankAccountNumber, i18n.get('payto.bsb.label.bankAccountNumber'))}\n name={'bankAccountNumber'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'bankAccountNumber'}\n value={data.bankAccountNumber}\n onInput={handleChangeFor('bankAccountNumber', 'input')}\n onBlur={handleChangeFor('bankAccountNumber', 'blur')}\n placeholder={placeholders?.bankAccountNumber}\n required={true}\n />\n </Field>\n\n <Field\n label={i18n.get('Bank State Branch')}\n classNameModifiers={['col-40', 'bsb']}\n errorMessage={getErrorMessage(i18n, errors.bsb, i18n.get('Bank State Branch'))}\n name={'bsb'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'bsb'}\n value={data.bsb}\n onInput={handleChangeFor('bsb', 'input')}\n onBlur={handleChangeFor('bsb', 'blur')}\n placeholder={placeholders?.bsb}\n required={true}\n />\n </Field>\n\n <PayToNameFields i18n={i18n} data={data} handleChangeFor={handleChangeFor} errors={errors} placeholders={placeholders} />\n </Fieldset>\n );\n}\n"],"names":["BASE_SCHEMA","BSBInput","setComponentRef","defaultData","placeholders","onChange","setStatus","id","i18n","useCoreContext","form","useFormWithA11y","schema","rules","bsbValidationRules","formatters","phoneFormatters","formHolder","handleChangeFor","triggerValidation","data","errors","valid","isValid","useEffect","payToRef","useRef","showValidation","current","h","Fieldset","classNameModifiers","label","description","Field","get","errorMessage","getErrorMessage","bankAccountNumber","name","errorLive","InputText","value","onInput","onBlur","placeholder","required","bsb","PayToNameFields"],"mappings":"4uBAgCA,MAAMA,EAAc,CAAC,oBAAqB,MAAO,YAAa,YAE/C,SAASC,GAASC,gBAAEA,EAAeC,YAAEA,EAAWC,aAAEA,EAAYC,SAAEA,EAAQC,UAAEA,EAASC,GAAEA,IAChG,MAAMC,KAAEA,GAASC,IAEXC,EAAOC,EAA6B,CACtCC,OAAQZ,EACRG,YAAaA,EACbU,MAAOC,EACPC,WAAYC,EACZC,WAAY,IAAIV,OAEdW,gBAAEA,EAAeC,kBAAEA,EAAiBC,KAAEA,EAAIC,OAAEA,EAAMC,MAAEA,EAAKC,QAAEA,GAAYb,EAG7Ec,EAAU,KACNnB,EAAS,CAAEe,OAAME,QAAOD,SAAQE,aACjC,CAACH,EAAME,EAAOD,EAAQE,IAEzB,MAAME,EAAWC,EAA4B,CACzCpB,UAAWA,EACXqB,eAAgBR,IAOpB,OAJAK,EAAU,KACNtB,EAAgBuB,EAASG,UAC1B,CAAC1B,IAGA2B,EAACC,EAAAA,CAASvB,GAAIA,EAAIwB,mBAAoB,CAAC,oBAAqBC,MAAO,MAAOC,YAAa,yBACnFJ,EAACK,EAAAA,CACGF,MAAOxB,EAAK2B,IAAI,qCAChBJ,mBAAoB,CAAC,SAAU,qBAC/BK,aAAcC,EAAgB7B,EAAMa,EAAOiB,kBAAmB9B,EAAK2B,IAAI,sCACvEI,KAAM,oBACN/B,KAAMA,EACNgC,WAAW,GAEXX,EAACY,EAAAA,CACGF,KAAM,oBACNG,MAAOtB,EAAKkB,kBACZK,QAASzB,EAAgB,oBAAqB,SAC9C0B,OAAQ1B,EAAgB,oBAAqB,QAC7C2B,YAAazC,GAAckC,kBAC3BQ,UAAU,
|
|
1
|
+
{"version":3,"file":"BSBInput.js","sources":["../../../../../src/components/PayTo/components/BSBInput.tsx"],"sourcesContent":["import { h } from 'preact';\nimport Fieldset from '../../internal/FormFields/Fieldset';\nimport { useEffect, useRef } from 'preact/hooks';\nimport { useFormWithA11y } from '../../../utils/useForm';\nimport { getErrorMessage } from '../../../utils/getErrorMessage';\nimport Field from '../../internal/FormFields/Field';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport InputText from '../../internal/FormFields/InputText';\nimport { bsbValidationRules } from './validate';\nimport './PayIDInput.scss';\nimport { phoneFormatters } from '../../internal/PhoneInput/validate';\nimport { ComponentMethodsRef, UIElementStatus } from '../../internal/UIElement/types';\nimport PayToNameFields from './PayToNameFields';\nimport { PayToPlaceholdersType } from '../types';\n\nexport interface BSBFormData {\n bsb: string;\n bankAccountNumber: string;\n firstName: string;\n lastName: string;\n}\n\nexport interface BSBInputProps {\n status: UIElementStatus;\n setStatus: (status: UIElementStatus) => void;\n defaultData: BSBFormData;\n placeholders: PayToPlaceholdersType;\n onChange: (e) => void;\n setComponentRef: (ref: ComponentMethodsRef) => void;\n id?: string;\n}\n\nconst BASE_SCHEMA = ['bankAccountNumber', 'bsb', 'firstName', 'lastName'];\n\nexport default function BSBInput({ setComponentRef, defaultData, placeholders, onChange, setStatus, id }: Readonly<BSBInputProps>) {\n const { i18n } = useCoreContext();\n\n const form = useFormWithA11y<BSBFormData>({\n schema: BASE_SCHEMA,\n defaultData: defaultData,\n rules: bsbValidationRules,\n formatters: phoneFormatters,\n formHolder: `#${id}`\n });\n const { handleChangeFor, triggerValidation, data, errors, valid, isValid } = form;\n\n // standard onChange propagate to parent state\n useEffect(() => {\n onChange({ data, valid, errors, isValid });\n }, [data, valid, errors, isValid]);\n\n const payToRef = useRef<ComponentMethodsRef>({\n setStatus: setStatus,\n showValidation: triggerValidation\n });\n\n useEffect(() => {\n setComponentRef(payToRef.current);\n }, [setComponentRef]);\n\n return (\n <Fieldset id={id} classNameModifiers={['payto__bsb_input']} label={'BSB'} description={'payto.bsb.description'}>\n <Field\n label={i18n.get('payto.bsb.label.bankAccountNumber')}\n classNameModifiers={['col-60', 'bankAccountNumber']}\n errorMessage={getErrorMessage(i18n, errors.bankAccountNumber, i18n.get('payto.bsb.label.bankAccountNumber'))}\n name={'bankAccountNumber'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'bankAccountNumber'}\n value={data.bankAccountNumber}\n onInput={handleChangeFor('bankAccountNumber', 'input')}\n onBlur={handleChangeFor('bankAccountNumber', 'blur')}\n placeholder={placeholders?.bankAccountNumber}\n required={true}\n autocomplete={undefined}\n />\n </Field>\n\n <Field\n label={i18n.get('Bank State Branch')}\n classNameModifiers={['col-40', 'bsb']}\n errorMessage={getErrorMessage(i18n, errors.bsb, i18n.get('Bank State Branch'))}\n name={'bsb'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'bsb'}\n value={data.bsb}\n onInput={handleChangeFor('bsb', 'input')}\n onBlur={handleChangeFor('bsb', 'blur')}\n placeholder={placeholders?.bsb}\n required={true}\n autocomplete={undefined}\n />\n </Field>\n\n <PayToNameFields i18n={i18n} data={data} handleChangeFor={handleChangeFor} errors={errors} placeholders={placeholders} />\n </Fieldset>\n );\n}\n"],"names":["BASE_SCHEMA","BSBInput","setComponentRef","defaultData","placeholders","onChange","setStatus","id","i18n","useCoreContext","form","useFormWithA11y","schema","rules","bsbValidationRules","formatters","phoneFormatters","formHolder","handleChangeFor","triggerValidation","data","errors","valid","isValid","useEffect","payToRef","useRef","showValidation","current","h","Fieldset","classNameModifiers","label","description","Field","get","errorMessage","getErrorMessage","bankAccountNumber","name","errorLive","InputText","value","onInput","onBlur","placeholder","required","autocomplete","undefined","bsb","PayToNameFields"],"mappings":"4uBAgCA,MAAMA,EAAc,CAAC,oBAAqB,MAAO,YAAa,YAE/C,SAASC,GAASC,gBAAEA,EAAeC,YAAEA,EAAWC,aAAEA,EAAYC,SAAEA,EAAQC,UAAEA,EAASC,GAAEA,IAChG,MAAMC,KAAEA,GAASC,IAEXC,EAAOC,EAA6B,CACtCC,OAAQZ,EACRG,YAAaA,EACbU,MAAOC,EACPC,WAAYC,EACZC,WAAY,IAAIV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
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createElement as e}from"../../../external/preact/dist/preact.js";import r from"../../internal/FormFields/Fieldset/Fieldset.js";import i,{PayToIdentifierEnum as
|
|
1
|
+
import{createElement as e}from"../../../external/preact/dist/preact.js";import r from"../../internal/FormFields/Fieldset/Fieldset.js";import i,{PayToIdentifierEnum as o}from"./IdentifierSelector.js";import{useEffect as t,useRef as a}from"../../../external/preact/hooks/dist/hooks.js";import{useCoreContext as l}from"../../../core/Context/CoreProvider.js";import s from"../../../utils/useForm/useFormWithA11y.js";import"../../internal/SecuredFields/lib/CSF/utils/userAgent.js";import n from"./PayToPhone.js";import d from"../../internal/FormFields/InputEmail.js";import{getErrorMessage as m}from"../../../utils/getErrorMessage.js";import p from"../../internal/FormFields/Field/Field.js";import c from"../../internal/FormFields/InputText.js";import{payIdValidationRules as f}from"./validate.js";import{phoneFormatters as u}from"../../internal/PhoneInput/validate.js";import g from"./PayToNameFields.js";const h=["selectedIdentifier","firstName","lastName"],b={[o.email]:["email"],[o.phone]:["phoneNumber","phonePrefix"],[o.abn]:["abn"],[o.orgid]:["orgid"]};function I({setComponentRef:I,defaultData:F,placeholders:j,onChange:v,setStatus:y,id:N}){const{i18n:M}=l(),C=s({schema:h,defaultData:{selectedIdentifier:o.phone,...F},rules:f,formatters:u,formHolder:`#${N}`}),{handleChangeFor:P,triggerValidation:S,data:x,errors:B,valid:E,isValid:A,setSchema:V}=C;t(()=>{V([...b[x.selectedIdentifier],...h])},[x.selectedIdentifier]),t(()=>{v({data:x,valid:E,errors:B,isValid:A})},[x,E,B,A]);const q=a({setStatus:y,showValidation:S});return t(()=>{I(q.current)},[I]),e(r,{id:N,classNameModifiers:["payto__payid_input"],label:"PayID",description:"payto.payid.description"},e(i,{classNameModifiers:["col-40"],onSelectedIdentifier:P("selectedIdentifier"),selectedIdentifier:x.selectedIdentifier}),x.selectedIdentifier===o.phone&&e(n,{form:C}),x.selectedIdentifier===o.email&&e(p,{label:M.get("shopperEmail"),classNameModifiers:["col-60","email"],errorMessage:m(M,B.email,M.get("shopperEmail")),dir:"ltr",name:"email",i18n:M,errorLive:!0},e(d,{name:"email",value:x.email,onInput:P("email","input"),onBlur:P("email","blur"),placeholder:j?.email,required:!0,autocomplete:"email"})),x.selectedIdentifier===o.abn&&e(p,{label:M.get("ABN"),classNameModifiers:["col-60","abn"],errorMessage:m(M,B.abn,M.get("ABN")),name:"ABN",i18n:M,errorLive:!0},e(c,{name:"abn",value:x.abn,onInput:P("abn","input"),onBlur:P("abn","blur"),placeholder:j?.abn,required:!0,autocomplete:void 0})),x.selectedIdentifier===o.orgid&&e(p,{label:M.get("payto.payid.label.orgid"),classNameModifiers:["col-60","orgid"],errorMessage:m(M,B.orgid,M.get("payto.payid.label.orgid")),name:"orgid",i18n:M,errorLive:!0},e(c,{name:"orgid",value:x.orgid,onInput:P("orgid","input"),onBlur:P("orgid","blur"),placeholder:j?.orgid,required:!0,autocomplete:void 0})),e(g,{i18n:M,data:x,handleChangeFor:P,errors:B,placeholders:j}))}export{I as default};
|
|
2
2
|
//# sourceMappingURL=PayIDInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PayIDInput.js","sources":["../../../../../src/components/PayTo/components/PayIDInput.tsx"],"sourcesContent":["import { h } from 'preact';\nimport Fieldset from '../../internal/FormFields/Fieldset';\nimport IdentifierSelector, { PayToIdentifierEnum } from './IdentifierSelector';\nimport { useEffect, useRef } from 'preact/hooks';\nimport { useFormWithA11y } from '../../../utils/useForm';\nimport PayToPhone from './PayToPhone';\nimport InputEmail from '../../internal/FormFields/InputEmail';\nimport { getErrorMessage } from '../../../utils/getErrorMessage';\nimport Field from '../../internal/FormFields/Field';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport InputText from '../../internal/FormFields/InputText';\nimport { payIdValidationRules } from './validate';\nimport './PayIDInput.scss';\nimport { phoneFormatters } from '../../internal/PhoneInput/validate';\nimport { ComponentMethodsRef, UIElementStatus } from '../../internal/UIElement/types';\nimport PayToNameFields from './PayToNameFields';\nimport { PayToPlaceholdersType } from '../types';\n\nexport interface PayIdFormData {\n email: string;\n phone: string;\n abn: string;\n orgid: string;\n firstName: string;\n lastName: string;\n phoneNumber?: string;\n phonePrefix?: string;\n selectedIdentifier: PayToIdentifierEnum;\n}\n\nexport interface PayIDInputProps {\n status: UIElementStatus;\n setStatus: (status: UIElementStatus) => void;\n defaultData: PayIdFormData;\n placeholders: PayToPlaceholdersType;\n onChange: (e) => void;\n setComponentRef: (ref: ComponentMethodsRef) => void;\n id?: string;\n}\n\nconst BASE_SCHEMA = ['selectedIdentifier', 'firstName', 'lastName'];\n\nconst IDENTIFIER_SCHEMA = {\n [PayToIdentifierEnum.email]: ['email'],\n [PayToIdentifierEnum.phone]: ['phoneNumber', 'phonePrefix'],\n [PayToIdentifierEnum.abn]: ['abn'],\n [PayToIdentifierEnum.orgid]: ['orgid']\n};\n\nexport default function PayIDInput({ setComponentRef, defaultData, placeholders, onChange, setStatus, id }: Readonly<PayIDInputProps>) {\n const { i18n } = useCoreContext();\n\n const form = useFormWithA11y<PayIdFormData>({\n schema: BASE_SCHEMA,\n defaultData: { selectedIdentifier: PayToIdentifierEnum.phone, ...defaultData },\n rules: payIdValidationRules,\n formatters: phoneFormatters,\n formHolder: `#${id}`\n });\n const { handleChangeFor, triggerValidation, data, errors, valid, isValid, setSchema } = form;\n\n // handle the changes of identifier, each identifier gets its own schema\n useEffect(() => {\n // get the correct schema for each identifier and merge it with the base\n setSchema([...IDENTIFIER_SCHEMA[data.selectedIdentifier], ...BASE_SCHEMA]);\n }, [data.selectedIdentifier]);\n\n // standard onChange propagate to parent state\n useEffect(() => {\n onChange({ data, valid, errors, isValid });\n }, [data, valid, errors, isValid]);\n\n const payToRef = useRef<ComponentMethodsRef>({\n setStatus: setStatus,\n showValidation: triggerValidation\n });\n\n useEffect(() => {\n setComponentRef(payToRef.current);\n }, [setComponentRef]);\n\n return (\n <Fieldset id={id} classNameModifiers={['payto__payid_input']} label={'PayID'} description={'payto.payid.description'}>\n <IdentifierSelector\n classNameModifiers={['col-40']}\n onSelectedIdentifier={handleChangeFor('selectedIdentifier')}\n selectedIdentifier={data.selectedIdentifier}\n />\n {data.selectedIdentifier === PayToIdentifierEnum.phone && <PayToPhone form={form} />}\n\n {/* TODO probably worth refactoring this into either re-usable components or builder */}\n {data.selectedIdentifier === PayToIdentifierEnum.email && (\n <Field\n label={i18n.get('shopperEmail')}\n classNameModifiers={['col-60', 'email']}\n errorMessage={getErrorMessage(i18n, errors.email, i18n.get('shopperEmail'))}\n dir={'ltr'}\n name={'email'}\n i18n={i18n}\n errorLive={true}\n >\n <InputEmail\n name={'email'}\n value={data.email}\n onInput={handleChangeFor('email', 'input')}\n onBlur={handleChangeFor('email', 'blur')}\n placeholder={placeholders?.email}\n required={true}\n />\n </Field>\n )}\n\n {data.selectedIdentifier === PayToIdentifierEnum.abn && (\n <Field\n label={i18n.get('ABN')}\n classNameModifiers={['col-60', 'abn']}\n errorMessage={getErrorMessage(i18n, errors.abn, i18n.get('ABN'))}\n name={'ABN'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'abn'}\n value={data.abn}\n onInput={handleChangeFor('abn', 'input')}\n onBlur={handleChangeFor('abn', 'blur')}\n placeholder={placeholders?.abn}\n required={true}\n />\n </Field>\n )}\n\n {data.selectedIdentifier === PayToIdentifierEnum.orgid && (\n <Field\n label={i18n.get('payto.payid.label.orgid')}\n classNameModifiers={['col-60', 'orgid']}\n errorMessage={getErrorMessage(i18n, errors.orgid, i18n.get('payto.payid.label.orgid'))}\n name={'orgid'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'orgid'}\n value={data.orgid}\n onInput={handleChangeFor('orgid', 'input')}\n onBlur={handleChangeFor('orgid', 'blur')}\n placeholder={placeholders?.orgid}\n required={true}\n />\n </Field>\n )}\n\n <PayToNameFields i18n={i18n} data={data} handleChangeFor={handleChangeFor} errors={errors} placeholders={placeholders} />\n </Fieldset>\n );\n}\n"],"names":["BASE_SCHEMA","IDENTIFIER_SCHEMA","PayToIdentifierEnum","email","phone","abn","orgid","PayIDInput","setComponentRef","defaultData","placeholders","onChange","setStatus","id","i18n","useCoreContext","form","useFormWithA11y","schema","selectedIdentifier","rules","payIdValidationRules","formatters","phoneFormatters","formHolder","handleChangeFor","triggerValidation","data","errors","valid","isValid","setSchema","useEffect","payToRef","useRef","showValidation","current","h","Fieldset","classNameModifiers","label","description","IdentifierSelector","onSelectedIdentifier","PayToPhone","Field","get","errorMessage","getErrorMessage","dir","name","errorLive","InputEmail","value","onInput","onBlur","placeholder","required","InputText","PayToNameFields"],"mappings":"q4BAwCA,MAAMA,EAAc,CAAC,qBAAsB,YAAa,YAElDC,EAAoB,CACtB,CAACC,EAAoBC,OAAQ,CAAC,SAC9B,CAACD,EAAoBE,OAAQ,CAAC,cAAe,eAC7C,CAACF,EAAoBG,KAAM,CAAC,OAC5B,CAACH,EAAoBI,OAAQ,CAAC,UAGnB,SAASC,GAAWC,gBAAEA,EAAeC,YAAEA,EAAWC,aAAEA,EAAYC,SAAEA,EAAQC,UAAEA,EAASC,GAAEA,IAClG,MAAMC,KAAEA,GAASC,IAEXC,EAAOC,EAA+B,CACxCC,OAAQlB,EACRS,YAAa,CAAEU,mBAAoBjB,EAAoBE,SAAUK,GACjEW,MAAOC,EACPC,WAAYC,EACZC,WAAY,IAAIX,OAEdY,gBAAEA,EAAeC,kBAAEA,EAAiBC,KAAEA,EAAIC,OAAEA,EAAMC,MAAEA,EAAKC,QAAEA,EAAOC,UAAEA,GAAcf,EAGxFgB,EAAU,KAEND,EAAU,IAAI9B,EAAkB0B,EAAKR,uBAAwBnB,KAC9D,CAAC2B,EAAKR,qBAGTa,EAAU,KACNrB,EAAS,CAAEgB,OAAME,QAAOD,SAAQE,aACjC,CAACH,EAAME,EAAOD,EAAQE,IAEzB,MAAMG,EAAWC,EAA4B,CACzCtB,UAAWA,EACXuB,eAAgBT,IAOpB,OAJAM,EAAU,KACNxB,EAAgByB,EAASG,UAC1B,CAAC5B,IAGA6B,EAACC,EAAAA,CAASzB,GAAIA,EAAI0B,mBAAoB,CAAC,sBAAuBC,MAAO,QAASC,YAAa,2BACvFJ,EAACK,EAAAA,CACGH,mBAAoB,CAAC,UACrBI,qBAAsBlB,EAAgB,sBACtCN,mBAAoBQ,EAAKR,qBAE5BQ,EAAKR,qBAAuBjB,EAAoBE,OAASiC,EAACO,EAAAA,CAAW5B,KAAMA,IAG3EW,EAAKR,qBAAuBjB,EAAoBC,OAC7CkC,EAACQ,EAAAA,CACGL,MAAO1B,EAAKgC,IAAI,gBAChBP,mBAAoB,CAAC,SAAU,SAC/BQ,aAAcC,EAAgBlC,EAAMc,EAAOzB,MAAOW,EAAKgC,IAAI,iBAC3DG,IAAK,MACLC,KAAM,QACNpC,KAAMA,EACNqC,WAAW,GAEXd,EAACe,EAAAA,CACGF,KAAM,QACNG,MAAO1B,EAAKxB,MACZmD,QAAS7B,EAAgB,QAAS,SAClC8B,OAAQ9B,EAAgB,QAAS,QACjC+B,YAAa9C,GAAcP,MAC3BsD,UAAU,
|
|
1
|
+
{"version":3,"file":"PayIDInput.js","sources":["../../../../../src/components/PayTo/components/PayIDInput.tsx"],"sourcesContent":["import { h } from 'preact';\nimport Fieldset from '../../internal/FormFields/Fieldset';\nimport IdentifierSelector, { PayToIdentifierEnum } from './IdentifierSelector';\nimport { useEffect, useRef } from 'preact/hooks';\nimport { useFormWithA11y } from '../../../utils/useForm';\nimport PayToPhone from './PayToPhone';\nimport InputEmail from '../../internal/FormFields/InputEmail';\nimport { getErrorMessage } from '../../../utils/getErrorMessage';\nimport Field from '../../internal/FormFields/Field';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport InputText from '../../internal/FormFields/InputText';\nimport { payIdValidationRules } from './validate';\nimport './PayIDInput.scss';\nimport { phoneFormatters } from '../../internal/PhoneInput/validate';\nimport { ComponentMethodsRef, UIElementStatus } from '../../internal/UIElement/types';\nimport PayToNameFields from './PayToNameFields';\nimport { PayToPlaceholdersType } from '../types';\n\nexport interface PayIdFormData {\n email: string;\n phone: string;\n abn: string;\n orgid: string;\n firstName: string;\n lastName: string;\n phoneNumber?: string;\n phonePrefix?: string;\n selectedIdentifier: PayToIdentifierEnum;\n}\n\nexport interface PayIDInputProps {\n status: UIElementStatus;\n setStatus: (status: UIElementStatus) => void;\n defaultData: PayIdFormData;\n placeholders: PayToPlaceholdersType;\n onChange: (e) => void;\n setComponentRef: (ref: ComponentMethodsRef) => void;\n id?: string;\n}\n\nconst BASE_SCHEMA = ['selectedIdentifier', 'firstName', 'lastName'];\n\nconst IDENTIFIER_SCHEMA = {\n [PayToIdentifierEnum.email]: ['email'],\n [PayToIdentifierEnum.phone]: ['phoneNumber', 'phonePrefix'],\n [PayToIdentifierEnum.abn]: ['abn'],\n [PayToIdentifierEnum.orgid]: ['orgid']\n};\n\nexport default function PayIDInput({ setComponentRef, defaultData, placeholders, onChange, setStatus, id }: Readonly<PayIDInputProps>) {\n const { i18n } = useCoreContext();\n\n const form = useFormWithA11y<PayIdFormData>({\n schema: BASE_SCHEMA,\n defaultData: { selectedIdentifier: PayToIdentifierEnum.phone, ...defaultData },\n rules: payIdValidationRules,\n formatters: phoneFormatters,\n formHolder: `#${id}`\n });\n const { handleChangeFor, triggerValidation, data, errors, valid, isValid, setSchema } = form;\n\n // handle the changes of identifier, each identifier gets its own schema\n useEffect(() => {\n // get the correct schema for each identifier and merge it with the base\n setSchema([...IDENTIFIER_SCHEMA[data.selectedIdentifier], ...BASE_SCHEMA]);\n }, [data.selectedIdentifier]);\n\n // standard onChange propagate to parent state\n useEffect(() => {\n onChange({ data, valid, errors, isValid });\n }, [data, valid, errors, isValid]);\n\n const payToRef = useRef<ComponentMethodsRef>({\n setStatus: setStatus,\n showValidation: triggerValidation\n });\n\n useEffect(() => {\n setComponentRef(payToRef.current);\n }, [setComponentRef]);\n\n return (\n <Fieldset id={id} classNameModifiers={['payto__payid_input']} label={'PayID'} description={'payto.payid.description'}>\n <IdentifierSelector\n classNameModifiers={['col-40']}\n onSelectedIdentifier={handleChangeFor('selectedIdentifier')}\n selectedIdentifier={data.selectedIdentifier}\n />\n {data.selectedIdentifier === PayToIdentifierEnum.phone && <PayToPhone form={form} />}\n\n {/* TODO probably worth refactoring this into either re-usable components or builder */}\n {data.selectedIdentifier === PayToIdentifierEnum.email && (\n <Field\n label={i18n.get('shopperEmail')}\n classNameModifiers={['col-60', 'email']}\n errorMessage={getErrorMessage(i18n, errors.email, i18n.get('shopperEmail'))}\n dir={'ltr'}\n name={'email'}\n i18n={i18n}\n errorLive={true}\n >\n <InputEmail\n name={'email'}\n value={data.email}\n onInput={handleChangeFor('email', 'input')}\n onBlur={handleChangeFor('email', 'blur')}\n placeholder={placeholders?.email}\n required={true}\n autocomplete={'email'}\n />\n </Field>\n )}\n\n {data.selectedIdentifier === PayToIdentifierEnum.abn && (\n <Field\n label={i18n.get('ABN')}\n classNameModifiers={['col-60', 'abn']}\n errorMessage={getErrorMessage(i18n, errors.abn, i18n.get('ABN'))}\n name={'ABN'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'abn'}\n value={data.abn}\n onInput={handleChangeFor('abn', 'input')}\n onBlur={handleChangeFor('abn', 'blur')}\n placeholder={placeholders?.abn}\n required={true}\n autocomplete={undefined}\n />\n </Field>\n )}\n\n {data.selectedIdentifier === PayToIdentifierEnum.orgid && (\n <Field\n label={i18n.get('payto.payid.label.orgid')}\n classNameModifiers={['col-60', 'orgid']}\n errorMessage={getErrorMessage(i18n, errors.orgid, i18n.get('payto.payid.label.orgid'))}\n name={'orgid'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'orgid'}\n value={data.orgid}\n onInput={handleChangeFor('orgid', 'input')}\n onBlur={handleChangeFor('orgid', 'blur')}\n placeholder={placeholders?.orgid}\n required={true}\n autocomplete={undefined}\n />\n </Field>\n )}\n\n <PayToNameFields i18n={i18n} data={data} handleChangeFor={handleChangeFor} errors={errors} placeholders={placeholders} />\n </Fieldset>\n );\n}\n"],"names":["BASE_SCHEMA","IDENTIFIER_SCHEMA","PayToIdentifierEnum","email","phone","abn","orgid","PayIDInput","setComponentRef","defaultData","placeholders","onChange","setStatus","id","i18n","useCoreContext","form","useFormWithA11y","schema","selectedIdentifier","rules","payIdValidationRules","formatters","phoneFormatters","formHolder","handleChangeFor","triggerValidation","data","errors","valid","isValid","setSchema","useEffect","payToRef","useRef","showValidation","current","h","Fieldset","classNameModifiers","label","description","IdentifierSelector","onSelectedIdentifier","PayToPhone","Field","get","errorMessage","getErrorMessage","dir","name","errorLive","InputEmail","value","onInput","onBlur","placeholder","required","autocomplete","InputText","undefined","PayToNameFields"],"mappings":"q4BAwCA,MAAMA,EAAc,CAAC,qBAAsB,YAAa,YAElDC,EAAoB,CACtB,CAACC,EAAoBC,OAAQ,CAAC,SAC9B,CAACD,EAAoBE,OAAQ,CAAC,cAAe,eAC7C,CAACF,EAAoBG,KAAM,CAAC,OAC5B,CAACH,EAAoBI,OAAQ,CAAC,UAGnB,SAASC,GAAWC,gBAAEA,EAAeC,YAAEA,EAAWC,aAAEA,EAAYC,SAAEA,EAAQC,UAAEA,EAASC,GAAEA,IAClG,MAAMC,KAAEA,GAASC,IAEXC,EAAOC,EAA+B,CACxCC,OAAQlB,EACRS,YAAa,CAAEU,mBAAoBjB,EAAoBE,SAAUK,GACjEW,MAAOC,EACPC,WAAYC,EACZC,WAAY,IAAIX,OAEdY,gBAAEA,EAAeC,kBAAEA,EAAiBC,KAAEA,EAAIC,OAAEA,EAAMC,MAAEA,EAAKC,QAAEA,EAAOC,UAAEA,GAAcf,EAGxFgB,EAAU,KAEND,EAAU,IAAI9B,EAAkB0B,EAAKR,uBAAwBnB,KAC9D,CAAC2B,EAAKR,qBAGTa,EAAU,KACNrB,EAAS,CAAEgB,OAAME,QAAOD,SAAQE,aACjC,CAACH,EAAME,EAAOD,EAAQE,IAEzB,MAAMG,EAAWC,EAA4B,CACzCtB,UAAWA,EACXuB,e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U,SAC/BQ,aAAcC,EAAgBlC,EAAMc,EAAOtB,MAAOQ,EAAKgC,IAAI,4BAC3DI,KAAM,QACNpC,KAAMA,EACNqC,WAAW,GAEXd,EAACsB,EAAAA,CACGT,KAAM,QACNG,MAAO1B,EAAKrB,MACZgD,QAAS7B,EAAgB,QAAS,SAClC8B,OAAQ9B,EAAgB,QAAS,QACjC+B,YAAa9C,GAAcJ,MAC3BmD,UAAU,EACVC,kBAAcE,KAK1BvB,EAACwB,EAAAA,CAAgB/C,KAAMA,EAAMa,KAAMA,EAAMF,gBAAiBA,EAAiBG,OAAQA,EAAQlB,aAAcA,IAGrH"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createElement as e,Fragment as a}from"../../../external/preact/dist/preact.js";import r from"../../internal/FormFields/Field/Field.js";import{getErrorMessage as
|
|
1
|
+
import{createElement as e,Fragment as a}from"../../../external/preact/dist/preact.js";import r from"../../internal/FormFields/Field/Field.js";import{getErrorMessage as t}from"../../../utils/getErrorMessage.js";import l from"../../internal/FormFields/InputText.js";function s({i18n:s,errors:m,data:i,handleChangeFor:o,placeholders:n}){return e(a,null,e(r,{label:s.get("payto.label.firstName"),classNameModifiers:["col-50","firstName"],errorMessage:t(s,m.firstName,s.get("firstName")),name:"firstName",i18n:s,errorLive:!0},e(l,{name:"firstName",value:i.firstName,classNameModifiers:["firstName"],onInput:o("firstName","input"),onBlur:o("firstName","input"),placeholder:n?.firstName,spellcheck:!1,required:!0,autocomplete:"given-name"})),e(r,{label:s.get("payto.label.lastName"),classNameModifiers:["col-50","lastName"],errorMessage:t(s,m.lastName,s.get("lastName")),name:"lastName",i18n:s,errorLive:!0},e(l,{name:"lastName",value:i.lastName,classNameModifiers:["lastName"],onInput:o("lastName","input"),onBlur:o("lastName","blur"),placeholder:n?.lastName,spellcheck:!1,required:!0,autocomplete:"family-name"})))}export{s as default};
|
|
2
2
|
//# sourceMappingURL=PayToNameFields.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PayToNameFields.js","sources":["../../../../../src/components/PayTo/components/PayToNameFields.tsx"],"sourcesContent":["import { h, Fragment } from 'preact';\nimport Field from '../../internal/FormFields/Field';\nimport { getErrorMessage } from '../../../utils/getErrorMessage';\nimport InputText from '../../internal/FormFields/InputText';\nimport Language from '../../../language';\nimport { HandleChangeForModeType } from '../../../utils/useForm/types';\nimport { ValidationRuleResult } from '../../../utils/Validator/ValidationRuleResult';\n\nexport interface PayToNameFieldsProps {\n i18n: Language;\n errors: {\n [key: string]: ValidationRuleResult;\n };\n data: {\n firstName: string;\n lastName: string;\n };\n handleChangeFor: (key: string, mode?: HandleChangeForModeType) => (e: h.JSX.TargetedEvent<HTMLInputElement, Event>) => void;\n placeholders: {\n firstName: string;\n lastName: string;\n };\n}\n\nexport default function PayToNameFields({ i18n, errors, data, handleChangeFor, placeholders }: Readonly<PayToNameFieldsProps>) {\n return (\n <Fragment>\n <Field\n label={i18n.get('payto.label.firstName')}\n classNameModifiers={['col-50', 'firstName']}\n errorMessage={getErrorMessage(i18n, errors.firstName, i18n.get('firstName'))}\n name={'firstName'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'firstName'}\n value={data.firstName}\n classNameModifiers={['firstName']}\n onInput={handleChangeFor('firstName', 'input')}\n onBlur={handleChangeFor('firstName', 'input')}\n placeholder={placeholders?.firstName}\n spellcheck={false}\n required={true}\n />\n </Field>\n <Field\n label={i18n.get('payto.label.lastName')}\n classNameModifiers={['col-50', 'lastName']}\n errorMessage={getErrorMessage(i18n, errors.lastName, i18n.get('lastName'))}\n name={'lastName'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'lastName'}\n value={data.lastName}\n classNameModifiers={['lastName']}\n onInput={handleChangeFor('lastName', 'input')}\n onBlur={handleChangeFor('lastName', 'blur')}\n placeholder={placeholders?.lastName}\n spellcheck={false}\n required={true}\n />\n </Field>\n </Fragment>\n );\n}\n"],"names":["PayToNameFields","i18n","errors","data","handleChangeFor","placeholders","h","Fragment","Field","label","get","classNameModifiers","errorMessage","getErrorMessage","firstName","name","errorLive","InputText","value","onInput","onBlur","placeholder","spellcheck","required","lastName"],"mappings":"wQAwBe,SAASA,GAAgBC,KAAEA,EAAIC,OAAEA,EAAMC,KAAEA,EAAIC,gBAAEA,EAAeC,aAAEA,IAC3E,OACIC,EAACC,OACGD,EAACE,EAAAA,CACGC,MAAOR,EAAKS,IAAI,yBAChBC,mBAAoB,CAAC,SAAU,aAC/BC,aAAcC,EAAgBZ,EAAMC,EAAOY,UAAWb,EAAKS,IAAI,cAC/DK,KAAM,YACNd,KAAMA,EACNe,WAAW,GAEXV,EAACW,EAAAA,CACGF,KAAM,YACNG,MAAOf,EAAKW,UACZH,mBAAoB,CAAC,aACrBQ,QAASf,EAAgB,YAAa,SACtCgB,OAAQhB,EAAgB,YAAa,SACrCiB,YAAahB,GAAcS,UAC3BQ,YAAY,EACZC,UAAU,
|
|
1
|
+
{"version":3,"file":"PayToNameFields.js","sources":["../../../../../src/components/PayTo/components/PayToNameFields.tsx"],"sourcesContent":["import { h, Fragment } from 'preact';\nimport Field from '../../internal/FormFields/Field';\nimport { getErrorMessage } from '../../../utils/getErrorMessage';\nimport InputText from '../../internal/FormFields/InputText';\nimport Language from '../../../language';\nimport { HandleChangeForModeType } from '../../../utils/useForm/types';\nimport { ValidationRuleResult } from '../../../utils/Validator/ValidationRuleResult';\n\nexport interface PayToNameFieldsProps {\n i18n: Language;\n errors: {\n [key: string]: ValidationRuleResult;\n };\n data: {\n firstName: string;\n lastName: string;\n };\n handleChangeFor: (key: string, mode?: HandleChangeForModeType) => (e: h.JSX.TargetedEvent<HTMLInputElement, Event>) => void;\n placeholders: {\n firstName: string;\n lastName: string;\n };\n}\n\nexport default function PayToNameFields({ i18n, errors, data, handleChangeFor, placeholders }: Readonly<PayToNameFieldsProps>) {\n return (\n <Fragment>\n <Field\n label={i18n.get('payto.label.firstName')}\n classNameModifiers={['col-50', 'firstName']}\n errorMessage={getErrorMessage(i18n, errors.firstName, i18n.get('firstName'))}\n name={'firstName'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'firstName'}\n value={data.firstName}\n classNameModifiers={['firstName']}\n onInput={handleChangeFor('firstName', 'input')}\n onBlur={handleChangeFor('firstName', 'input')}\n placeholder={placeholders?.firstName}\n spellcheck={false}\n required={true}\n autocomplete={'given-name'}\n />\n </Field>\n <Field\n label={i18n.get('payto.label.lastName')}\n classNameModifiers={['col-50', 'lastName']}\n errorMessage={getErrorMessage(i18n, errors.lastName, i18n.get('lastName'))}\n name={'lastName'}\n i18n={i18n}\n errorLive={true}\n >\n <InputText\n name={'lastName'}\n value={data.lastName}\n classNameModifiers={['lastName']}\n onInput={handleChangeFor('lastName', 'input')}\n onBlur={handleChangeFor('lastName', 'blur')}\n placeholder={placeholders?.lastName}\n spellcheck={false}\n required={true}\n autocomplete={'family-name'}\n />\n </Field>\n </Fragment>\n );\n}\n"],"names":["PayToNameFields","i18n","errors","data","handleChangeFor","placeholders","h","Fragment","Field","label","get","classNameModifiers","errorMessage","getErrorMessage","firstName","name","errorLive","InputText","value","onInput","onBlur","placeholder","spellcheck","required","autocomplete","lastName"],"mappings":"wQAwBe,SAASA,GAAgBC,KAAEA,EAAIC,OAAEA,EAAMC,KAAEA,EAAIC,gBAAEA,EAAeC,aAAEA,IAC3E,OACIC,EAACC,OACGD,EAACE,EAAAA,CACGC,MAAOR,EAAKS,IAAI,yBAChBC,mBAAoB,CAAC,SAAU,aAC/BC,aAAcC,EAAgBZ,EAAMC,EAAOY,UAAWb,EAAKS,IAAI,cAC/DK,KAAM,YACNd,KAAMA,EACNe,WAAW,GAEXV,EAACW,EAAAA,CACGF,KAAM,YACNG,MAAOf,EAAKW,UACZH,mBAAoB,CAAC,aACrBQ,QAASf,EAAgB,YAAa,SACtCgB,OAAQhB,EAAgB,YAAa,SACrCiB,YAAahB,GAAcS,UAC3BQ,YAAY,EACZC,UAAU,EACVC,aAAc,gBAGtBlB,EAACE,EAAAA,CACGC,MAAOR,EAAKS,IAAI,wBAChBC,mBAAoB,CAAC,SAAU,YAC/BC,aAAcC,EAAgBZ,EAAMC,EAAOuB,SAAUxB,EAAKS,IAAI,aAC9DK,KAAM,WACNd,KAAMA,EACNe,WAAW,GAEXV,EAACW,EAAAA,CACGF,KAAM,WACNG,MAAOf,EAAKsB,SACZd,mBAAoB,CAAC,YACrBQ,QAASf,EAAgB,WAAY,SACrCgB,OAAQhB,EAAgB,WAAY,QACpCiB,YAAahB,GAAcoB,SAC3BH,YAAY,EACZC,UAAU,EACVC,aAAc,iBAKlC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createElement as e}from"../../../external/preact/dist/preact.js";import"../../internal/QRLoader/QRLoader.js";import{QRImage as o}from"../../internal/QRLoader/components/QRImage.js";import{QRProgressbar as r}from"../../internal/QRLoader/components/QRProgressbar.js";import{QRCountdown as
|
|
1
|
+
import{createElement as e}from"../../../external/preact/dist/preact.js";import"../../internal/QRLoader/QRLoader.js";import{QRImage as o}from"../../internal/QRLoader/components/QRImage.js";import{QRProgressbar as r}from"../../internal/QRLoader/components/QRProgressbar.js";import{QRCountdown as t}from"../../internal/QRLoader/components/QRCountdown.js";import{useCoreContext as a}from"../../../core/Context/CoreProvider.js";import{QRCodeCopyButton as n}from"../../internal/QRLoader/components/QRCodeCopyButton.js";import{useQRLoaderDetails as i}from"../../internal/QRLoader/QRLoaderDetailsProvider.js";import d from"../../internal/FormFields/Field/Field.js";import l from"../../internal/FormFields/InputText.js";import{TxVariants as m}from"../../tx-variants.js";const p=()=>{const{i18n:p}=a(),{qrCodeData:s,qrCodeImage:c,percentage:_,timeToPay:x,onTick:u,countdownTime:L,onQRCodeLoad:Q,onTimeUp:R,handleCopy:y}=i();return e("div",{className:"adyen-checkout__qr-loader--pix__qr_details"},e(o,{type:m.pix,src:c,onLoad:Q}),e("div",{className:"adyen-checkout__qr-loader--pix__qr_details__timer"},e(r,{percentage:_}),e(t,{countdownTime:L,timeToPay:x,onTick:u,onCompleted:R})),e(d,{name:"pix-code",useLabelElement:!1},e(l,{className:"adyen-checkout__qr-loader--pix__qr_details__code",value:s,readonly:!0,"aria-label":p.get("pix.code.label"),autocomplete:void 0})),e(n,{text:s,copyLabel:p.get("pix.code.copy.label"),copiedLabel:p.get("pix.code.copied.label"),handleCopy:y}))};export{p as default};
|
|
2
2
|
//# sourceMappingURL=PixQRDetails.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PixQRDetails.js","sources":["../../../../../src/components/Pix/components/PixQRDetails.tsx"],"sourcesContent":["import { h } from 'preact';\nimport { QRImage, QRProgressbar, QRCountdown, QRCodeCopyButton, useQRLoaderDetails } from '../../internal/QRLoader';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport Field from '../../internal/FormFields/Field';\nimport InputText from '../../internal/FormFields/InputText';\nimport { TxVariants } from '../../tx-variants';\n\nconst PixQRDetails = () => {\n const { i18n } = useCoreContext();\n const { qrCodeData, qrCodeImage, percentage, timeToPay, onTick, countdownTime, onQRCodeLoad, onTimeUp, handleCopy } = useQRLoaderDetails();\n\n return (\n <div className=\"adyen-checkout__qr-loader--pix__qr_details\">\n <QRImage type={TxVariants.pix} src={qrCodeImage} onLoad={onQRCodeLoad} />\n <div className=\"adyen-checkout__qr-loader--pix__qr_details__timer\">\n <QRProgressbar percentage={percentage} />\n <QRCountdown countdownTime={countdownTime} timeToPay={timeToPay} onTick={onTick} onCompleted={onTimeUp} />\n </div>\n <Field name=\"pix-code\" useLabelElement={false}>\n <InputText\n className=\"adyen-checkout__qr-loader--pix__qr_details__code\"\n value={qrCodeData}\n readonly\n aria-label={i18n.get('pix.code.label')}\n />\n </Field>\n <QRCodeCopyButton\n text={qrCodeData}\n copyLabel={i18n.get('pix.code.copy.label')}\n copiedLabel={i18n.get('pix.code.copied.label')}\n handleCopy={handleCopy}\n />\n </div>\n );\n};\n\nexport default PixQRDetails;\n"],"names":["PixQRDetails","i18n","useCoreContext","qrCodeData","qrCodeImage","percentage","timeToPay","onTick","countdownTime","onQRCodeLoad","onTimeUp","handleCopy","useQRLoaderDetails","h","div","className","QRImage","type","TxVariants","pix","src","onLoad","QRProgressbar","QRCountdown","onCompleted","Field","name","useLabelElement","InputText","value","readonly","aria-label","get","QRCodeCopyButton","text","copyLabel","copiedLabel"],"mappings":"yvBAOA,MAAMA,EAAe,KACjB,MAAMC,KAAEA,GAASC,KACXC,WAAEA,EAAUC,YAAEA,EAAWC,WAAEA,EAAUC,UAAEA,EAASC,OAAEA,EAAMC,cAAEA,EAAaC,aAAEA,EAAYC,SAAEA,EAAQC,WAAEA,GAAeC,IAEtH,OACIC,EAACC,MAAAA,CAAIC,UAAU,8CACXF,EAACG,EAAAA,CAAQC,KAAMC,EAAWC,IAAKC,IAAKhB,EAAaiB,OAAQZ,IACzDI,EAACC,MAAAA,CAAIC,UAAU,qDACXF,EAACS,EAAAA,CAAcjB,WAAYA,IAC3BQ,EAACU,EAAAA,CAAYf,cAAeA,EAAeF,UAAWA,EAAWC,OAAQA,EAAQiB,YAAad,KAElGG,EAACY,EAAAA,CAAMC,KAAK,WAAWC,iBAAiB,GACpCd,EAACe,EAAAA,CACGb,UAAU,mDACVc,MAAO1B,EACP2B,UAAAA,EACAC,aAAY9B,EAAK+B,IAAI,
|
|
1
|
+
{"version":3,"file":"PixQRDetails.js","sources":["../../../../../src/components/Pix/components/PixQRDetails.tsx"],"sourcesContent":["import { h } from 'preact';\nimport { QRImage, QRProgressbar, QRCountdown, QRCodeCopyButton, useQRLoaderDetails } from '../../internal/QRLoader';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport Field from '../../internal/FormFields/Field';\nimport InputText from '../../internal/FormFields/InputText';\nimport { TxVariants } from '../../tx-variants';\n\nconst PixQRDetails = () => {\n const { i18n } = useCoreContext();\n const { qrCodeData, qrCodeImage, percentage, timeToPay, onTick, countdownTime, onQRCodeLoad, onTimeUp, handleCopy } = useQRLoaderDetails();\n\n return (\n <div className=\"adyen-checkout__qr-loader--pix__qr_details\">\n <QRImage type={TxVariants.pix} src={qrCodeImage} onLoad={onQRCodeLoad} />\n <div className=\"adyen-checkout__qr-loader--pix__qr_details__timer\">\n <QRProgressbar percentage={percentage} />\n <QRCountdown countdownTime={countdownTime} timeToPay={timeToPay} onTick={onTick} onCompleted={onTimeUp} />\n </div>\n <Field name=\"pix-code\" useLabelElement={false}>\n <InputText\n className=\"adyen-checkout__qr-loader--pix__qr_details__code\"\n value={qrCodeData}\n readonly\n aria-label={i18n.get('pix.code.label')}\n autocomplete={undefined}\n />\n </Field>\n <QRCodeCopyButton\n text={qrCodeData}\n copyLabel={i18n.get('pix.code.copy.label')}\n copiedLabel={i18n.get('pix.code.copied.label')}\n handleCopy={handleCopy}\n />\n </div>\n );\n};\n\nexport default PixQRDetails;\n"],"names":["PixQRDetails","i18n","useCoreContext","qrCodeData","qrCodeImage","percentage","timeToPay","onTick","countdownTime","onQRCodeLoad","onTimeUp","handleCopy","useQRLoaderDetails","h","div","className","QRImage","type","TxVariants","pix","src","onLoad","QRProgressbar","QRCountdown","onCompleted","Field","name","useLabelElement","InputText","value","readonly","aria-label","get","autocomplete","undefined","QRCodeCopyButton","text","copyLabel","copiedLabel"],"mappings":"yvBAOA,MAAMA,EAAe,KACjB,MAAMC,KAAEA,GAASC,KACXC,WAAEA,EAAUC,YAAEA,EAAWC,WAAEA,EAAUC,UAAEA,EAASC,OAAEA,EAAMC,cAAEA,EAAaC,aAAEA,EAAYC,SAAEA,EAAQC,WAAEA,GAAeC,IAEtH,OACIC,EAACC,MAAAA,CAAIC,UAAU,8CACXF,EAACG,EAAAA,CAAQC,KAAMC,EAAWC,IAAKC,IAAKhB,EAAaiB,OAAQZ,IACzDI,EAACC,MAAAA,CAAIC,UAAU,qDACXF,EAACS,EAAAA,CAAcjB,WAAYA,IAC3BQ,EAACU,EAAAA,CAAYf,cAAeA,EAAeF,UAAWA,EAAWC,OAAQA,EAAQiB,YAAad,KAElGG,EAACY,EAAAA,CAAMC,KAAK,WAAWC,iBAAiB,GACpCd,EAACe,EAAAA,CACGb,UAAU,mDACVc,MAAO1B,EACP2B,UAAAA,EACAC,aAAY9B,EAAK+B,IAAI,kBACrBC,kBAAcC,KAGtBrB,EAACsB,EAAAA,CACGC,KAAMjC,EACNkC,UAAWpC,EAAK+B,IAAI,uBACpBM,YAAarC,EAAK+B,IAAI,yBACtBrB,WAAYA"}
|
package/dist/es/components/PreAuthorizedDebitCanada/components/PreAuthorizedDebitCanadaComponent.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createElement as e}from"../../../external/preact/dist/preact.js";import{useState as a,useRef as t,useEffect as n}from"../../../external/preact/hooks/dist/hooks.js";import{useCoreContext as o}from"../../../core/Context/CoreProvider.js";import r from"../../internal/FormFields/Fieldset/Fieldset.js";import l from"../../internal/FormInstruction/FormInstruction.js";import i from"../../../utils/useForm/useForm.js";import"../../internal/SecuredFields/lib/CSF/utils/userAgent.js";import s from"../../internal/FormFields/Field/Field.js";import u from"../../internal/FormFields/InputText.js";import{preAuthorizedDebitCanadaValidationRules as d,preAuthorizedDebitCanadaFormatters as m}from"./validate.js";import c from"../../internal/StoreDetails/StoreDetails.js";import b from"../../../core/Context/useImage.js";import{SettlementInfo as p}from"./SettlementInfo.js";function k({onChange:k,payButton:f,showPayButton:g,placeholders:N,setComponentRef:x,enableStoreDetails:h,showContextualElement:C=!0}){const I=b(),{i18n:F}=o(),[w,j]=a("ready"),{handleChangeFor:
|
|
1
|
+
import{createElement as e}from"../../../external/preact/dist/preact.js";import{useState as a,useRef as t,useEffect as n}from"../../../external/preact/hooks/dist/hooks.js";import{useCoreContext as o}from"../../../core/Context/CoreProvider.js";import r from"../../internal/FormFields/Fieldset/Fieldset.js";import l from"../../internal/FormInstruction/FormInstruction.js";import i from"../../../utils/useForm/useForm.js";import"../../internal/SecuredFields/lib/CSF/utils/userAgent.js";import s from"../../internal/FormFields/Field/Field.js";import u from"../../internal/FormFields/InputText.js";import{preAuthorizedDebitCanadaValidationRules as d,preAuthorizedDebitCanadaFormatters as m}from"./validate.js";import c from"../../internal/StoreDetails/StoreDetails.js";import b from"../../../core/Context/useImage.js";import{SettlementInfo as p}from"./SettlementInfo.js";function k({onChange:k,payButton:f,showPayButton:g,placeholders:N,setComponentRef:x,enableStoreDetails:h,showContextualElement:C=!0}){const I=b(),{i18n:F}=o(),[w,j]=a("ready"),{handleChangeFor:v,triggerValidation:A,data:M,errors:L,valid:S,isValid:V}=i({schema:["ownerName","bankAccountNumber","bankCode","bankLocationId"],rules:d,formatters:m}),[T,y]=a(!1),B="loading"===w,E=t({setStatus:j,showValidation:()=>{A()}});return n(()=>{x(E.current)},[x,E.current]),n(()=>{k({data:M,valid:S,errors:L,isValid:V,storePaymentMethod:T})},[k,M,S,L,V,T]),e("div",{className:"adyen-checkout__eftpad-canada"},e(l,null),e(r,null,e(s,{label:F.get("eftpad-canada.input.accountHolderName.label"),errorMessage:!!L.ownerName&&F.get(L.ownerName.errorMessage),isValid:!!S.ownerName,name:"ownerName"},e(u,{disabled:B,name:"ownerName",placeholder:N?.ownerName,value:M.ownerName,onInput:v("ownerName","input"),onBlur:v("ownerName","blur"),required:!0,"data-testid":"owner-name",autocomplete:"name"})),e(s,{label:F.get("eftpad-canada.input.accountNumber.label"),errorMessage:!!L.bankAccountNumber&&F.get(L.bankAccountNumber.errorMessage),name:"bankAccountNumber",isValid:!!S.bankAccountNumber,showContextualElement:C,contextualText:F.get("eftpad-canada.input.accountNumber.contextualText")},e(u,{disabled:B,name:"bankAccountNumber",placeholder:N?.bankAccountNumber,value:M.bankAccountNumber,onInput:v("bankAccountNumber","input"),onBlur:v("bankAccountNumber","blur"),required:!0,maxlength:12,autocomplete:void 0})),e(s,{label:F.get("eftpad-canada.input.institutionNumber.label"),classNameModifiers:["col-50"],errorMessage:!!L.bankCode&&F.get(L.bankCode.errorMessage),isValid:!!S.bankCode,name:"bankCode",showContextualElement:C,contextualText:F.get("eftpad-canada.input.institutionNumber.contextualText")},e(u,{disabled:B,name:"bankCode",placeholder:N?.bankCode,value:M.bankCode,onInput:v("bankCode","input"),onBlur:v("bankCode","blur"),required:!0,maxlength:3,autocomplete:void 0})),e(s,{label:F.get("eftpad-canada.input.transitNumber.label"),classNameModifiers:["col-50"],errorMessage:!!L.bankLocationId&&F.get(L.bankLocationId.errorMessage),name:"bankLocationId",isValid:!!S.bankLocationId,showContextualElement:C,contextualText:F.get("eftpad-canada.input.transitNumber.contextualText")},e(u,{disabled:B,name:"bankLocationId",placeholder:N?.bankLocationId,value:M.bankLocationId,onInput:v("bankLocationId","input"),onBlur:v("bankLocationId","blur"),required:!0,maxlength:5,autocomplete:void 0}))),h&&e(c,{className:"adyen-checkout_eftpad-canada-store-details",disabled:B,onChange:y}),e(p,null),g&&f({status:w,icon:I({imageFolder:"components/"})("bento_lock")}))}export{k as default};
|
|
2
2
|
//# sourceMappingURL=PreAuthorizedDebitCanadaComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PreAuthorizedDebitCanadaComponent.js","sources":["../../../../../src/components/PreAuthorizedDebitCanada/components/PreAuthorizedDebitCanadaComponent.tsx"],"sourcesContent":["import { h } from 'preact';\nimport { useEffect, useRef, useState } from 'preact/hooks';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport Fieldset from '../../internal/FormFields/Fieldset';\nimport FormInstruction from '../../internal/FormInstruction';\nimport useForm from '../../../utils/useForm';\nimport Field from '../../internal/FormFields/Field';\nimport InputText from '../../internal/FormFields/InputText';\nimport { preAuthorizedDebitCanadaFormatters, preAuthorizedDebitCanadaValidationRules } from './validate';\nimport StoreDetails from '../../internal/StoreDetails';\nimport useImage from '../../../core/Context/useImage';\nimport { SettlementInfo } from './SettlementInfo';\n\nimport type { PayButtonProps } from '../../internal/PayButton/PayButton';\nimport type { ComponentMethodsRef } from '../../internal/UIElement/types';\nimport type { PreAuthorizedDebitCanadaPlaceholders } from '../types';\n\nimport './PreAuthorizedDebitCanada.scss';\nimport { ValidationRuleResult } from '../../../utils/Validator/ValidationRuleResult';\n\ninterface PreAuthorizedDebitCanadaForm {\n ownerName: string;\n bankAccountNumber: string;\n bankCode: string;\n bankLocationId: string;\n}\n\ninterface PreAuthorizedDebitCanadaComponentProps {\n onChange({\n data,\n valid,\n errors,\n isValid,\n storePaymentMethod\n }: {\n data: PreAuthorizedDebitCanadaForm;\n valid: { [key: string]: boolean };\n errors: { [key: string]: ValidationRuleResult };\n isValid: boolean;\n storePaymentMethod: boolean;\n }): void;\n payButton: (props: PayButtonProps) => h.JSX.Element;\n setComponentRef: (ref: ComponentMethodsRef) => void;\n showPayButton: boolean;\n enableStoreDetails: boolean;\n showContextualElement?: boolean;\n placeholders?: PreAuthorizedDebitCanadaPlaceholders;\n}\n\nfunction PreAuthorizedDebitCanadaComponent({\n onChange,\n payButton,\n showPayButton,\n placeholders,\n setComponentRef,\n enableStoreDetails,\n showContextualElement = true\n}: Readonly<PreAuthorizedDebitCanadaComponentProps>) {\n const getImage = useImage();\n const { i18n } = useCoreContext();\n const [status, setStatus] = useState('ready');\n const { handleChangeFor, triggerValidation, data, errors, valid, isValid } = useForm<PreAuthorizedDebitCanadaForm>({\n schema: ['ownerName', 'bankAccountNumber', 'bankCode', 'bankLocationId'],\n rules: preAuthorizedDebitCanadaValidationRules,\n formatters: preAuthorizedDebitCanadaFormatters\n });\n const [storePaymentMethod, setStorePaymentMethod] = useState(false);\n\n const isFormDisabled = status === 'loading';\n\n const componentRef = useRef<ComponentMethodsRef>({\n setStatus: setStatus,\n showValidation: () => {\n triggerValidation();\n }\n });\n\n useEffect(() => {\n setComponentRef(componentRef.current);\n }, [setComponentRef, componentRef.current]);\n\n useEffect(() => {\n onChange({ data, valid, errors, isValid, storePaymentMethod });\n }, [onChange, data, valid, errors, isValid, storePaymentMethod]);\n\n return (\n <div className=\"adyen-checkout__eftpad-canada\">\n <FormInstruction />\n\n <Fieldset>\n <Field\n label={i18n.get('eftpad-canada.input.accountHolderName.label')}\n errorMessage={!!errors.ownerName && i18n.get(errors.ownerName.errorMessage)}\n isValid={!!valid.ownerName}\n name={'ownerName'}\n >\n <InputText\n disabled={isFormDisabled}\n name={'ownerName'}\n placeholder={placeholders?.ownerName}\n value={data.ownerName}\n onInput={handleChangeFor('ownerName', 'input')}\n onBlur={handleChangeFor('ownerName', 'blur')}\n required={true}\n data-testid={'owner-name'}\n />\n </Field>\n\n <Field\n label={i18n.get('eftpad-canada.input.accountNumber.label')}\n errorMessage={!!errors.bankAccountNumber && i18n.get(errors.bankAccountNumber.errorMessage)}\n name={'bankAccountNumber'}\n isValid={!!valid.bankAccountNumber}\n showContextualElement={showContextualElement}\n contextualText={i18n.get('eftpad-canada.input.accountNumber.contextualText')}\n >\n <InputText\n disabled={isFormDisabled}\n name={'bankAccountNumber'}\n placeholder={placeholders?.bankAccountNumber}\n value={data.bankAccountNumber}\n onInput={handleChangeFor('bankAccountNumber', 'input')}\n onBlur={handleChangeFor('bankAccountNumber', 'blur')}\n required={true}\n maxlength={12}\n />\n </Field>\n\n <Field\n label={i18n.get('eftpad-canada.input.institutionNumber.label')}\n classNameModifiers={['col-50']}\n errorMessage={!!errors.bankCode && i18n.get(errors.bankCode.errorMessage)}\n isValid={!!valid.bankCode}\n name={'bankCode'}\n showContextualElement={showContextualElement}\n contextualText={i18n.get('eftpad-canada.input.institutionNumber.contextualText')}\n >\n <InputText\n disabled={isFormDisabled}\n name={'bankCode'}\n placeholder={placeholders?.bankCode}\n value={data.bankCode}\n onInput={handleChangeFor('bankCode', 'input')}\n onBlur={handleChangeFor('bankCode', 'blur')}\n required={true}\n maxlength={3}\n />\n </Field>\n\n <Field\n label={i18n.get('eftpad-canada.input.transitNumber.label')}\n classNameModifiers={['col-50']}\n errorMessage={!!errors.bankLocationId && i18n.get(errors.bankLocationId.errorMessage)}\n name={'bankLocationId'}\n isValid={!!valid.bankLocationId}\n showContextualElement={showContextualElement}\n contextualText={i18n.get('eftpad-canada.input.transitNumber.contextualText')}\n >\n <InputText\n disabled={isFormDisabled}\n name={'bankLocationId'}\n placeholder={placeholders?.bankLocationId}\n value={data.bankLocationId}\n onInput={handleChangeFor('bankLocationId', 'input')}\n onBlur={handleChangeFor('bankLocationId', 'blur')}\n required={true}\n maxlength={5}\n />\n </Field>\n </Fieldset>\n\n {enableStoreDetails && (\n <StoreDetails className={'adyen-checkout_eftpad-canada-store-details'} disabled={isFormDisabled} onChange={setStorePaymentMethod} />\n )}\n\n <SettlementInfo />\n\n {showPayButton && payButton({ status, icon: getImage({ imageFolder: 'components/' })('bento_lock') })}\n </div>\n );\n}\n\nexport default PreAuthorizedDebitCanadaComponent;\n"],"names":["PreAuthorizedDebitCanadaComponent","onChange","payButton","showPayButton","placeholders","setComponentRef","enableStoreDetails","showContextualElement","getImage","useImage","i18n","useCoreContext","status","setStatus","useState","handleChangeFor","triggerValidation","data","errors","valid","isValid","useForm","schema","rules","preAuthorizedDebitCanadaValidationRules","formatters","preAuthorizedDebitCanadaFormatters","storePaymentMethod","setStorePaymentMethod","isFormDisabled","componentRef","useRef","showValidation","useEffect","current","h","div","className","FormInstruction","Fieldset","Field","label","get","errorMessage","ownerName","name","InputText","disabled","placeholder","value","onInput","onBlur","required","data-testid","bankAccountNumber","contextualText","maxlength","classNameModifiers","bankCode","bankLocationId","StoreDetails","SettlementInfo","icon","imageFolder"],"mappings":"i2BAiDA,SAASA,GAAkCC,SACvCA,EAAQC,UACRA,EAASC,cACTA,EAAaC,aACbA,EAAYC,gBACZA,EAAeC,mBACfA,EAAkBC,sBAClBA,GAAwB,IAExB,MAAMC,EAAWC,KACXC,KAAEA,GAASC,KACVC,EAAQC,GAAaC,EAAS,UAC/BC,gBAAEA,EAAeC,kBAAEA,EAAiBC,KAAEA,EAAIC,OAAEA,EAAMC,MAAEA,EAAKC,QAAEA,GAAYC,EAAsC,CAC/GC,OAAQ,CAAC,YAAa,oBAAqB,WAAY,kBACvDC,MAAOC,EACPC,WAAYC,KAETC,EAAoBC,GAAyBd,GAAS,G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DvB,UAAWD,EAAMuC,SACjBb,KAAM,WACNtC,sBAAuBA,EACvBgD,eAAgB7C,EAAKgC,IAAI,yDAEzBP,EAACW,EAAAA,CACGC,SAAUlB,EACVgB,KAAM,WACNG,YAAa5C,GAAcsD,SAC3BT,MAAOhC,EAAKyC,SACZR,QAASnC,EAAgB,WAAY,SACrCoC,OAAQpC,EAAgB,WAAY,QACpCqC,UAAU,EACVI,UAAW,KAInBrB,EAACK,EAAAA,CACGC,MAAO/B,EAAKgC,IAAI,2CAChBe,mBAAoB,CAAC,UACrBd,eAAgBzB,EAAOyC,gBAAkBjD,EAAKgC,IAAIxB,EAAOyC,eAAehB,cACxEE,KAAM,iBACNzB,UAAWD,EAAMwC,eACjBpD,sBAAuBA,EACvBgD,eAAgB7C,EAAKgC,IAAI,qDAEzBP,EAACW,EAAAA,CACGC,SAAUlB,EACVgB,KAAM,iBACNG,YAAa5C,GAAcuD,eAC3BV,MAAOhC,EAAK0C,eACZT,QAASnC,EAAgB,iBAAkB,SAC3CoC,OAAQpC,EAAgB,iBAAkB,QAC1CqC,UAAU,EACVI,UAAW,MAKtBlD,GACG6B,EAACyB,EAAAA,CAAavB,UAAW,6CAA8CU,SAAUlB,EAAgB5B,SAAU2B,IAG/GO,EAAC0B,EAAAA,MAEA1D,GAAiBD,EAAU,CAAEU,SAAQkD,KAAMtD,EAAS,CAAEuD,YAAa,eAAxBvD,CAAyC,gBAGjG"}
|
|
1
|
+
{"version":3,"file":"PreAuthorizedDebitCanadaComponent.js","sources":["../../../../../src/components/PreAuthorizedDebitCanada/components/PreAuthorizedDebitCanadaComponent.tsx"],"sourcesContent":["import { h } from 'preact';\nimport { useEffect, useRef, useState } from 'preact/hooks';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport Fieldset from '../../internal/FormFields/Fieldset';\nimport FormInstruction from '../../internal/FormInstruction';\nimport useForm from '../../../utils/useForm';\nimport Field from '../../internal/FormFields/Field';\nimport InputText from '../../internal/FormFields/InputText';\nimport { preAuthorizedDebitCanadaFormatters, preAuthorizedDebitCanadaValidationRules } from './validate';\nimport StoreDetails from '../../internal/StoreDetails';\nimport useImage from '../../../core/Context/useImage';\nimport { SettlementInfo } from './SettlementInfo';\n\nimport type { PayButtonProps } from '../../internal/PayButton/PayButton';\nimport type { ComponentMethodsRef } from '../../internal/UIElement/types';\nimport type { PreAuthorizedDebitCanadaPlaceholders } from '../types';\n\nimport './PreAuthorizedDebitCanada.scss';\nimport { ValidationRuleResult } from '../../../utils/Validator/ValidationRuleResult';\n\ninterface PreAuthorizedDebitCanadaForm {\n ownerName: string;\n bankAccountNumber: string;\n bankCode: string;\n bankLocationId: string;\n}\n\ninterface PreAuthorizedDebitCanadaComponentProps {\n onChange({\n data,\n valid,\n errors,\n isValid,\n storePaymentMethod\n }: {\n data: PreAuthorizedDebitCanadaForm;\n valid: { [key: string]: boolean };\n errors: { [key: string]: ValidationRuleResult };\n isValid: boolean;\n storePaymentMethod: boolean;\n }): void;\n payButton: (props: PayButtonProps) => h.JSX.Element;\n setComponentRef: (ref: ComponentMethodsRef) => void;\n showPayButton: boolean;\n enableStoreDetails: boolean;\n showContextualElement?: boolean;\n placeholders?: PreAuthorizedDebitCanadaPlaceholders;\n}\n\nfunction PreAuthorizedDebitCanadaComponent({\n onChange,\n payButton,\n showPayButton,\n placeholders,\n setComponentRef,\n enableStoreDetails,\n showContextualElement = true\n}: Readonly<PreAuthorizedDebitCanadaComponentProps>) {\n const getImage = useImage();\n const { i18n } = useCoreContext();\n const [status, setStatus] = useState('ready');\n const { handleChangeFor, triggerValidation, data, errors, valid, isValid } = useForm<PreAuthorizedDebitCanadaForm>({\n schema: ['ownerName', 'bankAccountNumber', 'bankCode', 'bankLocationId'],\n rules: preAuthorizedDebitCanadaValidationRules,\n formatters: preAuthorizedDebitCanadaFormatters\n });\n const [storePaymentMethod, setStorePaymentMethod] = useState(false);\n\n const isFormDisabled = status === 'loading';\n\n const componentRef = useRef<ComponentMethodsRef>({\n setStatus: setStatus,\n showValidation: () => {\n triggerValidation();\n }\n });\n\n useEffect(() => {\n setComponentRef(componentRef.current);\n }, [setComponentRef, componentRef.current]);\n\n useEffect(() => {\n onChange({ data, valid, errors, isValid, storePaymentMethod });\n }, [onChange, data, valid, errors, isValid, storePaymentMethod]);\n\n return (\n <div className=\"adyen-checkout__eftpad-canada\">\n <FormInstruction />\n\n <Fieldset>\n <Field\n label={i18n.get('eftpad-canada.input.accountHolderName.label')}\n errorMessage={!!errors.ownerName && i18n.get(errors.ownerName.errorMessage)}\n isValid={!!valid.ownerName}\n name={'ownerName'}\n >\n <InputText\n disabled={isFormDisabled}\n name={'ownerName'}\n placeholder={placeholders?.ownerName}\n value={data.ownerName}\n onInput={handleChangeFor('ownerName', 'input')}\n onBlur={handleChangeFor('ownerName', 'blur')}\n required={true}\n data-testid={'owner-name'}\n autocomplete=\"name\"\n />\n </Field>\n\n <Field\n label={i18n.get('eftpad-canada.input.accountNumber.label')}\n errorMessage={!!errors.bankAccountNumber && i18n.get(errors.bankAccountNumber.errorMessage)}\n name={'bankAccountNumber'}\n isValid={!!valid.bankAccountNumber}\n showContextualElement={showContextualElement}\n contextualText={i18n.get('eftpad-canada.input.accountNumber.contextualText')}\n >\n <InputText\n disabled={isFormDisabled}\n name={'bankAccountNumber'}\n placeholder={placeholders?.bankAccountNumber}\n value={data.bankAccountNumber}\n onInput={handleChangeFor('bankAccountNumber', 'input')}\n onBlur={handleChangeFor('bankAccountNumber', 'blur')}\n required={true}\n maxlength={12}\n autocomplete={undefined}\n />\n </Field>\n\n <Field\n label={i18n.get('eftpad-canada.input.institutionNumber.label')}\n classNameModifiers={['col-50']}\n errorMessage={!!errors.bankCode && i18n.get(errors.bankCode.errorMessage)}\n isValid={!!valid.bankCode}\n name={'bankCode'}\n showContextualElement={showContextualElement}\n contextualText={i18n.get('eftpad-canada.input.institutionNumber.contextualText')}\n >\n <InputText\n disabled={isFormDisabled}\n name={'bankCode'}\n placeholder={placeholders?.bankCode}\n value={data.bankCode}\n onInput={handleChangeFor('bankCode', 'input')}\n onBlur={handleChangeFor('bankCode', 'blur')}\n required={true}\n maxlength={3}\n autocomplete={undefined}\n />\n </Field>\n\n <Field\n label={i18n.get('eftpad-canada.input.transitNumber.label')}\n classNameModifiers={['col-50']}\n errorMessage={!!errors.bankLocationId && i18n.get(errors.bankLocationId.errorMessage)}\n name={'bankLocationId'}\n isValid={!!valid.bankLocationId}\n showContextualElement={showContextualElement}\n contextualText={i18n.get('eftpad-canada.input.transitNumber.contextualText')}\n >\n <InputText\n disabled={isFormDisabled}\n name={'bankLocationId'}\n placeholder={placeholders?.bankLocationId}\n value={data.bankLocationId}\n onInput={handleChangeFor('bankLocationId', 'input')}\n onBlur={handleChangeFor('bankLocationId', 'blur')}\n required={true}\n maxlength={5}\n autocomplete={undefined}\n />\n </Field>\n </Fieldset>\n\n {enableStoreDetails && (\n <StoreDetails className={'adyen-checkout_eftpad-canada-store-details'} disabled={isFormDisabled} onChange={setStorePaymentMethod} />\n )}\n\n <SettlementInfo />\n\n {showPayButton && payButton({ status, icon: getImage({ imageFolder: 'components/' })('bento_lock') })}\n </div>\n );\n}\n\nexport default PreAuthorizedDebitCanadaComponent;\n"],"names":["PreAuthorizedDebitCanadaComponent","onChange","payButton","showPayButton","placeholders","setComponentRef","enableStoreDetails","showContextualElement","getImage","useImage","i18n","useCoreContext","status","setStatus","useState","handleChangeFor","triggerValidation","data","errors","valid","isValid","useForm","schema","rules","preAuthorizedDebitCanadaValidationRules","formatters","preAuthorizedDebitCanadaFormatters","storePaymentMethod","setStorePaymentMethod","isFormDisabled","componentRef","useRef","showValidation","useEffect","current","h","div","className","FormInstruction","Fieldset","Field","label","get","errorMessage","ownerName","name","InputText","disabled","placeholder","value","onInput","onBlur","required","data-testid","autocomplete","bankAccountNumber","contextualText","maxlength","undefined","classNameModifiers","bankCode","bankLocationId","StoreDetails","SettlementInfo","icon","imageFolder"],"mappings":"i2BAiDA,SAASA,GAAkCC,SACvCA,EAAQC,UACRA,EA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SAAQoD,KAAMxD,EAAS,CAAEyD,YAAa,eAAxBzD,CAAyC,gBAGjG"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createElement as e,Fragment as t}from"../../../external/preact/dist/preact.js";import{useRef as r,useMemo as
|
|
1
|
+
import{createElement as e,Fragment as t}from"../../../external/preact/dist/preact.js";import{useRef as r,useMemo as s,useState as o,useCallback as n,useEffect as a}from"../../../external/preact/hooks/dist/hooks.js";import i from"../FormFields/Fieldset/Fieldset.js";import l from"./components/ReadOnlyAddress.js";import{getAddressValidationRules as d}from"./validate.js";import{addressFormatters as c,countrySpecificFormatters as u}from"./validate.formats.js";import m from"./components/FieldContainer.js";import p from"../../../utils/useForm/useForm.js";import"../SecuredFields/lib/CSF/utils/userAgent.js";import f from"./Specifications.js";import{ADDRESS_SCHEMA as y,FALLBACK_VALUE as F}from"./constants.js";import{getMaxLengthByFieldAndCountry as h}from"../../../utils/validator-utils.js";import{useCoreContext as C}from"../../../core/Context/CoreProvider.js";import g from"./components/AddressSearch.js";import{getAddressTypeFromLabel as A}from"./utils.js";function v(v){const{i18n:b}=C(),{label:j="",requiredFields:S,visibility:x,iOSFocusedField:k=null,showContextualElement:M}=v,O=A(v.addressType,j),D=r({});Object.keys(D.current).length||v.setComponentRef?.(D.current);const w=s(()=>new f(v.specifications),[v.specifications]),B=w.getAddressSchemaForCountryFlat(v.countryCode).filter(e=>S.includes(e)),[E,L]=o(!1),[N,P]=o(!1),[R,T]=o(""),V=!!v.onAddressLookup,[H,q]=o(!1),_=!v.onAddressLookup||(E||N),{data:I,errors:U,valid:$,isValid:z,handleChangeFor:G,triggerValidation:J,setData:K,mergeData:Q}=p({schema:B,defaultData:v.data,rules:{...d(w),...v.validationRules},formatters:c}),W=r(v.data?.country),X=(I.country||W.current)?.toUpperCase(),Y=s(()=>({...I,country:X}),[I,X]),Z=n(e=>{const t=y.reduce((t,r)=>{const s=e[r];return null!=s&&(t[r]=String(s)),t},{});Q(t),q(!0),J(),L(!0)},[L,J,K]),ee=n(()=>{P(!0)},[]);D.current.showValidation=()=>{J(),T(!V||_||z?"":b.get("address.errors.incomplete"))};const te=B.filter(e=>!k||e===k);if(a(()=>{if(H)return void q(!1);const e=w.countryHasDataset(I.country)?"":F,t={...I,stateOrProvince:e};S.forEach(e=>{G(e,"input")(t[e]??"")}),t.postalCode&&G("postalCode","blur")(I.postalCode)},[I.country]),a(()=>{const e=S.includes("stateOrProvince"),t=I.country&&w.countryHasDataset(I.country),r=e&&t,s=I.stateOrProvince||(r?"":F);G("stateOrProvince","input")(s)},[]),a(()=>{const e=w.getOptionalFieldsForCountry(I.country),t=y.reduce((t,r)=>{const s=e.includes(r),o=S.includes(r),n=I[r],a=v.data[r],i=s&&!n||!o?o||n||!a?F:a:n;return i?.length&&(t[r]=i),t},{});!t.country&&W.current&&(t.country=W.current),v.onChange({data:t,valid:$,errors:U,isValid:z})},[I,$,U,z]),"hidden"===x)return null;if("readOnly"===x)return e(l,{data:I,label:j});const re=(t,{classNameModifiers:r=[]})=>S.includes(t)?e(m,{key:t,allowedCountries:v.allowedCountries,classNameModifiers:[...r,t],data:Y,errors:U,valid:$,fieldName:t,onInput:G(t,"input"),onBlur:G(t,"blur"),onDropdownChange:G(t,"blur"),specifications:w,maxLength:h(u,t,X),trimOnBlur:!0,disabled:!te.includes(t),addressType:O,onFieldFocusAnalytics:v.onFieldFocusAnalytics,onFieldBlurAnalytics:v.onFieldBlurAnalytics}):null,se=w.getAddressSchemaForCountry(I.country);return e(t,null,e(i,{classNameModifiers:[j,"address"],label:j,renderLabelAsSectionHeading:!0},V&&e(g,{onAddressLookup:v.onAddressLookup,onAddressSelected:v.onAddressSelected,onSelect:Z,onManualAddress:ee,externalErrorMessage:R,hideManualButton:_,showContextualElement:M,contextualText:b.get("address.search.contextualText"),addressSearchDebounceMs:v.addressSearchDebounceMs}),_&&e(t,null,se.map(t=>t instanceof Array?e("div",{className:"adyen-checkout__field-group"},t.map(([e,t])=>re(e,{classNameModifiers:[`col-${t}`]}))):re(t,{})))))}v.defaultProps={countryCode:null,validationRules:null,data:{},onChange:()=>{},visibility:"editable",requiredFields:y,specifications:{},onFieldFocusAnalytics:()=>{},onFieldBlurAnalytics:()=>{}};export{v as default};
|
|
2
2
|
//# sourceMappingURL=Address.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Address.js","sources":["../../../../../src/components/internal/Address/Address.tsx"],"sourcesContent":["import { Fragment, h } from 'preact';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'preact/hooks';\nimport Fieldset from '../FormFields/Fieldset';\nimport ReadOnlyAddress from './components/ReadOnlyAddress';\nimport { getAddressValidationRules } from './validate';\nimport { addressFormatters, countrySpecificFormatters } from './validate.formats';\nimport { AddressProps } from './types';\nimport { AddressData } from '../../../types/global-types';\nimport FieldContainer from './components/FieldContainer';\nimport useForm from '../../../utils/useForm';\nimport Specifications from './Specifications';\nimport { ADDRESS_SCHEMA, FALLBACK_VALUE } from './constants';\nimport { getMaxLengthByFieldAndCountry } from '../../../utils/validator-utils';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport AddressSearch from './components/AddressSearch';\nimport { ComponentMethodsRef } from '../UIElement/types';\nimport './Address.scss';\n\nexport default function Address(props: Readonly<AddressProps>) {\n const { i18n } = useCoreContext();\n\n const { label = '', requiredFields, visibility, iOSFocusedField = null, showContextualElement } = props;\n\n /** An object by which to expose 'public' members to the parent UIElement */\n const addressRef = useRef<ComponentMethodsRef>({});\n // Just call once\n if (!Object.keys(addressRef.current).length) {\n props.setComponentRef?.(addressRef.current);\n }\n\n const specifications = useMemo(() => new Specifications(props.specifications), [props.specifications]);\n\n const requiredFieldsSchema = specifications.getAddressSchemaForCountryFlat(props.countryCode).filter(field => requiredFields.includes(field));\n\n const [hasSelectedAddress, setHasSelectedAddress] = useState(false);\n\n const [useManualAddress, setUseManualAddress] = useState(false);\n\n const [searchErrorMessage, setSearchErrorMessage] = useState('');\n\n const showAddressSearch = !!props.onAddressLookup;\n\n const [ignoreCountryChange, setIgnoreCountryChange] = useState(false);\n\n const showAddressFields = props.onAddressLookup ? hasSelectedAddress || useManualAddress : true;\n\n const { data, errors, valid, isValid, handleChangeFor, triggerValidation, setData, mergeData } = useForm<AddressData>({\n schema: requiredFieldsSchema,\n defaultData: props.data,\n // Ensure any passed validation rules are merged with the default ones\n rules: { ...getAddressValidationRules(specifications), ...props.validationRules },\n formatters: addressFormatters\n });\n\n // In partial address mode, country is not in the form schema but we need it for regionalized labels.\n // Store the merchant's country config once at mount, then use it if form data doesn't have country.\n const initialCountryRef = useRef<string | undefined>((props.data as AddressData)?.country);\n const effectiveCountry = (data.country || initialCountryRef.current)?.toUpperCase();\n const dataWithCountry = useMemo(() => ({ ...data, country: effectiveCountry }), [data, effectiveCountry]);\n\n const setSearchData = useCallback(\n (selectedAddress: AddressData) => {\n const propsKeysToProcess = ADDRESS_SCHEMA;\n const newStateData = propsKeysToProcess.reduce((acc: AddressData, propKey) => {\n // Make sure the data provided by the merchant is always strings\n const providedValue = selectedAddress[propKey];\n if (providedValue !== null && providedValue !== undefined) {\n // Cast everything to string\n acc[propKey] = String(providedValue);\n }\n return acc;\n }, {});\n mergeData(newStateData);\n setIgnoreCountryChange(true);\n triggerValidation();\n setHasSelectedAddress(true);\n },\n [setHasSelectedAddress, triggerValidation, setData]\n );\n\n const onManualAddress = useCallback(() => {\n setUseManualAddress(true);\n }, []);\n\n // Expose method expected by (parent) Address.tsx\n addressRef.current.showValidation = () => {\n triggerValidation();\n if (showAddressSearch && !showAddressFields && !isValid) {\n setSearchErrorMessage(i18n.get('address.errors.incomplete'));\n } else {\n setSearchErrorMessage('');\n }\n };\n\n /**\n * For iOS: iOSFocusedField is the name of the element calling for other elements to be disabled\n * - so if it is set (meaning we are in iOS *and* an input has been focussed) only enable the field that corresponds to this element\n */\n const enabledFields: string[] = requiredFieldsSchema.filter(item => {\n return !iOSFocusedField ? true : item === iOSFocusedField;\n });\n\n /**\n * Effect that:\n * - Resets validation for all fields by triggering handleChangeFor(fieldName, 'input')\n * - Applies validation on postalCode field in case it has any value\n */\n useEffect((): void => {\n // if the country was set via setSearchData we don't want to trigger this\n if (ignoreCountryChange) {\n setIgnoreCountryChange(false);\n return;\n }\n\n const stateOrProvince = specifications.countryHasDataset(data.country) ? '' : FALLBACK_VALUE;\n const newData = { ...data, stateOrProvince };\n\n requiredFields.forEach(fieldName => {\n handleChangeFor(fieldName, 'input')(newData[fieldName] ?? '');\n });\n\n if (newData.postalCode) {\n handleChangeFor('postalCode', 'blur')(data.postalCode);\n }\n }, [data.country]);\n\n /**\n * Set the value of 'stateOrProvince' during the initial render if\n * property is provided during the creation of the payment method\n */\n useEffect((): void => {\n const stateFieldIsRequired = requiredFields.includes('stateOrProvince');\n const countryHasStatesDataset = data.country && specifications.countryHasDataset(data.country);\n const addressShouldHaveState = stateFieldIsRequired && countryHasStatesDataset;\n const stateOrProvince = data.stateOrProvince || (addressShouldHaveState ? '' : FALLBACK_VALUE);\n\n handleChangeFor('stateOrProvince', 'input')(stateOrProvince);\n }, []);\n\n useEffect((): void => {\n const optionalFields = specifications.getOptionalFieldsForCountry(data.country);\n const processedData = ADDRESS_SCHEMA.reduce((acc, cur) => {\n const isOptional = optionalFields.includes(cur);\n const isRequired = requiredFields.includes(cur);\n const newValue = data[cur];\n const initialValue = props.data[cur];\n // recover default data values which are not requiredFields, or prefill with 'N/A'\n const fallbackValue = !isRequired && !newValue && !!initialValue ? initialValue : FALLBACK_VALUE;\n const value = (isOptional && !newValue) || !isRequired ? fallbackValue : newValue;\n if (value?.length) acc[cur] = value;\n return acc;\n }, {});\n\n // In partial address mode, ensure country is included in output for regionalized labels/validation.\n if (!(processedData as AddressData).country && initialCountryRef.current) {\n (processedData as AddressData).country = initialCountryRef.current;\n }\n\n props.onChange({ data: processedData, valid, errors, isValid });\n }, [data, valid, errors, isValid]);\n\n if (visibility === 'hidden') return null;\n if (visibility === 'readOnly') return <ReadOnlyAddress data={data} label={label} />;\n\n const getComponent = (fieldName: string, { classNameModifiers = [] }) => {\n if (!requiredFields.includes(fieldName)) return null;\n\n return (\n <FieldContainer\n key={fieldName}\n allowedCountries={props.allowedCountries}\n classNameModifiers={[...classNameModifiers, fieldName]}\n data={dataWithCountry}\n errors={errors}\n valid={valid}\n fieldName={fieldName}\n onInput={handleChangeFor(fieldName, 'input')}\n onBlur={handleChangeFor(fieldName, 'blur')}\n onDropdownChange={handleChangeFor(fieldName, 'blur')}\n specifications={specifications}\n maxLength={getMaxLengthByFieldAndCountry(countrySpecificFormatters, fieldName, effectiveCountry, true)}\n trimOnBlur={true}\n disabled={!enabledFields.includes(fieldName)}\n onFieldFocusAnalytics={props.onFieldFocusAnalytics}\n onFieldBlurAnalytics={props.onFieldBlurAnalytics}\n />\n );\n };\n\n const getWrapper = group => (\n <div className=\"adyen-checkout__field-group\">\n {group.map(([field, size]) => getComponent(field, { classNameModifiers: [`col-${size}`] }))}\n </div>\n );\n\n const addressSchema = specifications.getAddressSchemaForCountry(data.country);\n\n return (\n <Fragment>\n <Fieldset classNameModifiers={[label, 'address']} label={label} renderLabelAsSectionHeading>\n {showAddressSearch && (\n <AddressSearch\n onAddressLookup={props.onAddressLookup}\n onAddressSelected={props.onAddressSelected}\n onSelect={setSearchData}\n onManualAddress={onManualAddress}\n externalErrorMessage={searchErrorMessage}\n hideManualButton={showAddressFields}\n showContextualElement={showContextualElement}\n contextualText={i18n.get('address.search.contextualText')}\n addressSearchDebounceMs={props.addressSearchDebounceMs}\n />\n )}\n {showAddressFields && (\n <Fragment>{addressSchema.map(field => (field instanceof Array ? getWrapper(field) : getComponent(field, {})))}</Fragment>\n )}\n </Fieldset>\n </Fragment>\n );\n}\n\nAddress.defaultProps = {\n countryCode: null,\n validationRules: null,\n data: {},\n onChange: () => {},\n visibility: 'editable',\n requiredFields: ADDRESS_SCHEMA,\n specifications: {},\n onFieldFocusAnalytics: () => {},\n onFieldBlurAnalytics: () => {}\n};\n"],"names":["Address","props","i18n","useCoreContext","label","requiredFields","visibility","iOSFocusedField","showContextualElement","addressRef","useRef","Object","keys","current","length","setComponentRef","specifications","useMemo","Specifications","requiredFieldsSchema","getAddressSchemaForCountryFlat","countryCode","filter","field","includes","hasSelectedAddress","setHasSelectedAddress","useState","useManualAddress","setUseManualAddress","searchErrorMessage","setSearchErrorMessage","showAddressSearch","onAddressLookup","ignoreCountryChange","setIgnoreCountryChange","showAddressFields","data","errors","valid","isValid","handleChangeFor","triggerValidation","setData","mergeData","useForm","schema","defaultData","rules","getAddressValidationRules","validationRules","formatters","addressFormatters","initialCountryRef","country","effectiveCountry","toUpperCase","dataWithCountry","setSearchData","useCallback","selectedAddress","newStateData","ADDRESS_SCHEMA","reduce","acc","propKey","providedValue","String","onManualAddress","showValidation","get","enabledFields","item","useEffect","stateOrProvince","countryHasDataset","FALLBACK_VALUE","newData","forEach","fieldName","postalCode","stateFieldIsRequired","countryHasStatesDataset","addressShouldHaveState","optionalFields","getOptionalFieldsForCountry","processedData","cur","isOptional","isRequired","newValue","initialValue","value","onChange","h","ReadOnlyAddress","getComponent","classNameModifiers","FieldContainer","key","allowedCountries","onInput","onBlur","onDropdownChange","maxLength","getMaxLengthByFieldAndCountry","countrySpecificFormatters","trimOnBlur","disabled","onFieldFocusAnalytics","onFieldBlurAnalytics","addressSchema","getAddressSchemaForCountry","Fragment","Fieldset","renderLabelAsSectionHeading","AddressSearch","onAddressSelected","onSelect","externalErrorMessage","hideManualButton","contextualText","addressSearchDebounceMs","map","Array","div","className","size","defaultProps"],"mappings":"24BAkBe,SAASA,EAAQC,GAC5B,MAAMC,KAAEA,GAASC,KAEXC,MAAEA,EAAQ,GAAEC,eAAEA,EAAcC,WAAEA,EAAUC,gBAAEA,EAAkB,KAAIC,sBAAEA,GAA0BP,EAG5FQ,EAAaC,EAA4B,IAE1CC,OAAOC,KAAKH,EAAWI,SAASC,QACjCb,EAAMc,kBAAkBN,EAAWI,SAGvC,MAAMG,EAAiBC,EAAQ,IAAM,IAAIC,EAAejB,EA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+
{"version":3,"file":"Address.js","sources":["../../../../../src/components/internal/Address/Address.tsx"],"sourcesContent":["import { Fragment, h } from 'preact';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'preact/hooks';\nimport Fieldset from '../FormFields/Fieldset';\nimport ReadOnlyAddress from './components/ReadOnlyAddress';\nimport { getAddressValidationRules } from './validate';\nimport { addressFormatters, countrySpecificFormatters } from './validate.formats';\nimport { AddressProps, AddressType } from './types';\nimport { AddressData } from '../../../types/global-types';\nimport FieldContainer from './components/FieldContainer';\nimport useForm from '../../../utils/useForm';\nimport Specifications from './Specifications';\nimport { ADDRESS_SCHEMA, FALLBACK_VALUE } from './constants';\nimport { getMaxLengthByFieldAndCountry } from '../../../utils/validator-utils';\nimport { useCoreContext } from '../../../core/Context/CoreProvider';\nimport AddressSearch from './components/AddressSearch';\nimport { ComponentMethodsRef } from '../UIElement/types';\nimport './Address.scss';\nimport { getAddressTypeFromLabel } from './utils';\n\nexport default function Address(props: Readonly<AddressProps>) {\n const { i18n } = useCoreContext();\n\n const { label = '', requiredFields, visibility, iOSFocusedField = null, showContextualElement } = props;\n const addressType: AddressType = getAddressTypeFromLabel(props.addressType, label);\n\n /** An object by which to expose 'public' members to the parent UIElement */\n const addressRef = useRef<ComponentMethodsRef>({});\n // Just call once\n if (!Object.keys(addressRef.current).length) {\n props.setComponentRef?.(addressRef.current);\n }\n\n const specifications = useMemo(() => new Specifications(props.specifications), [props.specifications]);\n\n const requiredFieldsSchema = specifications.getAddressSchemaForCountryFlat(props.countryCode).filter(field => requiredFields.includes(field));\n\n const [hasSelectedAddress, setHasSelectedAddress] = useState(false);\n\n const [useManualAddress, setUseManualAddress] = useState(false);\n\n const [searchErrorMessage, setSearchErrorMessage] = useState('');\n\n const showAddressSearch = !!props.onAddressLookup;\n\n const [ignoreCountryChange, setIgnoreCountryChange] = useState(false);\n\n const showAddressFields = props.onAddressLookup ? hasSelectedAddress || useManualAddress : true;\n\n const { data, errors, valid, isValid, handleChangeFor, triggerValidation, setData, mergeData } = useForm<AddressData>({\n schema: requiredFieldsSchema,\n defaultData: props.data,\n // Ensure any passed validation rules are merged with the default ones\n rules: { ...getAddressValidationRules(specifications), ...props.validationRules },\n formatters: addressFormatters\n });\n\n // In partial address mode, country is not in the form schema but we need it for regionalized labels.\n // Store the merchant's country config once at mount, then use it if form data doesn't have country.\n const initialCountryRef = useRef<string | undefined>((props.data as AddressData)?.country);\n const effectiveCountry = (data.country || initialCountryRef.current)?.toUpperCase();\n const dataWithCountry = useMemo(() => ({ ...data, country: effectiveCountry }), [data, effectiveCountry]);\n\n const setSearchData = useCallback(\n (selectedAddress: AddressData) => {\n const propsKeysToProcess = ADDRESS_SCHEMA;\n const newStateData = propsKeysToProcess.reduce((acc: AddressData, propKey) => {\n // Make sure the data provided by the merchant is always strings\n const providedValue = selectedAddress[propKey];\n if (providedValue !== null && providedValue !== undefined) {\n // Cast everything to string\n acc[propKey] = String(providedValue);\n }\n return acc;\n }, {});\n mergeData(newStateData);\n setIgnoreCountryChange(true);\n triggerValidation();\n setHasSelectedAddress(true);\n },\n [setHasSelectedAddress, triggerValidation, setData]\n );\n\n const onManualAddress = useCallback(() => {\n setUseManualAddress(true);\n }, []);\n\n // Expose method expected by (parent) Address.tsx\n addressRef.current.showValidation = () => {\n triggerValidation();\n if (showAddressSearch && !showAddressFields && !isValid) {\n setSearchErrorMessage(i18n.get('address.errors.incomplete'));\n } else {\n setSearchErrorMessage('');\n }\n };\n\n /**\n * For iOS: iOSFocusedField is the name of the element calling for other elements to be disabled\n * - so if it is set (meaning we are in iOS *and* an input has been focussed) only enable the field that corresponds to this element\n */\n const enabledFields: string[] = requiredFieldsSchema.filter(item => {\n return !iOSFocusedField ? true : item === iOSFocusedField;\n });\n\n /**\n * Effect that:\n * - Resets validation for all fields by triggering handleChangeFor(fieldName, 'input')\n * - Applies validation on postalCode field in case it has any value\n */\n useEffect((): void => {\n // if the country was set via setSearchData we don't want to trigger this\n if (ignoreCountryChange) {\n setIgnoreCountryChange(false);\n return;\n }\n\n const stateOrProvince = specifications.countryHasDataset(data.country) ? '' : FALLBACK_VALUE;\n const newData = { ...data, stateOrProvince };\n\n requiredFields.forEach(fieldName => {\n handleChangeFor(fieldName, 'input')(newData[fieldName] ?? '');\n });\n\n if (newData.postalCode) {\n handleChangeFor('postalCode', 'blur')(data.postalCode);\n }\n }, [data.country]);\n\n /**\n * Set the value of 'stateOrProvince' during the initial render if\n * property is provided during the creation of the payment method\n */\n useEffect((): void => {\n const stateFieldIsRequired = requiredFields.includes('stateOrProvince');\n const countryHasStatesDataset = data.country && specifications.countryHasDataset(data.country);\n const addressShouldHaveState = stateFieldIsRequired && countryHasStatesDataset;\n const stateOrProvince = data.stateOrProvince || (addressShouldHaveState ? '' : FALLBACK_VALUE);\n\n handleChangeFor('stateOrProvince', 'input')(stateOrProvince);\n }, []);\n\n useEffect((): void => {\n const optionalFields = specifications.getOptionalFieldsForCountry(data.country);\n const processedData = ADDRESS_SCHEMA.reduce((acc, cur) => {\n const isOptional = optionalFields.includes(cur);\n const isRequired = requiredFields.includes(cur);\n const newValue = data[cur];\n const initialValue = props.data[cur];\n // recover default data values which are not requiredFields, or prefill with 'N/A'\n const fallbackValue = !isRequired && !newValue && !!initialValue ? initialValue : FALLBACK_VALUE;\n const value = (isOptional && !newValue) || !isRequired ? fallbackValue : newValue;\n if (value?.length) acc[cur] = value;\n return acc;\n }, {});\n\n // In partial address mode, ensure country is included in output for regionalized labels/validation.\n if (!(processedData as AddressData).country && initialCountryRef.current) {\n (processedData as AddressData).country = initialCountryRef.current;\n }\n\n props.onChange({ data: processedData, valid, errors, isValid });\n }, [data, valid, errors, isValid]);\n\n if (visibility === 'hidden') return null;\n if (visibility === 'readOnly') return <ReadOnlyAddress data={data} label={label} />;\n\n const getComponent = (fieldName: string, { classNameModifiers = [] }) => {\n if (!requiredFields.includes(fieldName)) return null;\n\n return (\n <FieldContainer\n key={fieldName}\n allowedCountries={props.allowedCountries}\n classNameModifiers={[...classNameModifiers, fieldName]}\n data={dataWithCountry}\n errors={errors}\n valid={valid}\n fieldName={fieldName}\n onInput={handleChangeFor(fieldName, 'input')}\n onBlur={handleChangeFor(fieldName, 'blur')}\n onDropdownChange={handleChangeFor(fieldName, 'blur')}\n specifications={specifications}\n maxLength={getMaxLengthByFieldAndCountry(countrySpecificFormatters, fieldName, effectiveCountry, true)}\n trimOnBlur={true}\n disabled={!enabledFields.includes(fieldName)}\n addressType={addressType}\n onFieldFocusAnalytics={props.onFieldFocusAnalytics}\n onFieldBlurAnalytics={props.onFieldBlurAnalytics}\n />\n );\n };\n\n const getWrapper = group => (\n <div className=\"adyen-checkout__field-group\">\n {group.map(([field, size]) => getComponent(field, { classNameModifiers: [`col-${size}`] }))}\n </div>\n );\n\n const addressSchema = specifications.getAddressSchemaForCountry(data.country);\n\n return (\n <Fragment>\n <Fieldset classNameModifiers={[label, 'address']} label={label} renderLabelAsSectionHeading>\n {showAddressSearch && (\n <AddressSearch\n onAddressLookup={props.onAddressLookup}\n onAddressSelected={props.onAddressSelected}\n onSelect={setSearchData}\n onManualAddress={onManualAddress}\n externalErrorMessage={searchErrorMessage}\n hideManualButton={showAddressFields}\n showContextualElement={showContextualElement}\n contextualText={i18n.get('address.search.contextualText')}\n addressSearchDebounceMs={props.addressSearchDebounceMs}\n />\n )}\n {showAddressFields && (\n <Fragment>{addressSchema.map(field => (field instanceof Array ? getWrapper(field) : getComponent(field, {})))}</Fragment>\n )}\n </Fieldset>\n </Fragment>\n );\n}\n\nAddress.defaultProps = {\n countryCode: null,\n validationRules: null,\n data: {},\n onChange: () => {},\n visibility: 'editable',\n requiredFields: ADDRESS_SCHEMA,\n specifications: {},\n onFieldFocusAnalytics: () => {},\n onFieldBlurAnalytics: () => {}\n};\n"],"names":["Address","props","i18n","useCoreContext","label","requiredFields","visibility","iOSFocusedField","showContextualElement","addressType","getAddressTypeFromLabel","addressRef","useRef","Object","keys","current","length","setComponentRef","specifications","useMemo","Specifications","requiredFieldsSchema","getAddressSchemaForCountryFlat","countryCode","filter","field","includes","hasSelectedAddress","setHasSelectedAddress","useState","useManualAddress","setUseManualAddress","searchErrorMessage","setSearchErrorMessage","showAddressSearch","onAddressLookup","ignoreCountryChange","setIgnoreCountryChange","showAddressFields","data","errors","valid","isValid","handleChangeFor","triggerValidation","setData","mergeData","useForm","schema","defaultData","rules","getAddressValidationRules","validationRules","formatters","addressFormatters","initialCountryRef","country","effectiveCountry","toUpperCase","dataWithCountry","setSearchData","useCallback","selectedAddress","newStateData","ADDRESS_SCHEMA","reduce","acc","propKey","providedValue","String","onManualAddress","showValidation","get","enabledFields","item","useEffect","stateOrProvince","countryHasDataset","FALLBACK_VALUE","newData","forEach","fieldName","postalCode","stateFieldIsRequired","countryHasStatesDataset","addressShouldHaveState","optionalFields","getOptionalFieldsForCountry","processedData","cur","isOptional","isRequired","newValue","initialValue","value","onChange","h","ReadOnlyAddress","getComponent","classNameModifiers","FieldContainer","key","allowedCountries","onInput","onBlur","onDropdownChange","maxLength","getMaxLengthByFieldAndCountry","countrySpecificFormatters","trimOnBlur","disabled","onFieldFocusAnalytics","onFieldBlurAnalytics","addressSchema","getAddressSchemaForCountry","Fragment","Fieldset","renderLabelAsSectionHeading","AddressSearch","onAddressSelected","onSelect","externalErrorMessage","hideManualButton","contextualText","addressSearchDebounceMs","map","Array","div","className","size","defaultProps"],"mappings":"g8BAmBe,SAASA,EAAQC,GAC5B,MAAMC,KAAEA,GAASC,KAEXC,MAAEA,EAAQ,GAAEC,eAAEA,EAAcC,WAAEA,EAAUC,gBAAEA,EAAkB,KAAIC,sBAAEA,GAA0BP,EAC5FQ,EAA2BC,EAAwBT,EAAMQ,YAAaL,GAGtEO,EAAaC,EAA4B,IAE1CC,OAAOC,KAAKH,EAAWI,SAASC,QACjCf,EAAMgB,kBAAkBN,EAAWI,SAGvC,MAAMG,EAAiBC,EAAQ,IAAM,IAAIC,EAAenB,EAAMiB,gBAAiB,CAACjB,EAAMiB,iBAEhFG,EAAuBH,EAAeI,+BAA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e}from"../../../../external/preact/dist/preact.js";import r from"../../FormFields/Field/Field.js";import o from"./StateField.js";import
|
|
1
|
+
import{createElement as e}from"../../../../external/preact/dist/preact.js";import r from"../../FormFields/Field/Field.js";import o from"./StateField.js";import s from"./CountryField.js";import{useCoreContext as t}from"../../../../core/Context/CoreProvider.js";import i from"../../FormFields/InputText.js";import{ADDRESS_FIELD_TOKEN_MAP as n}from"../constants.js";function a(e,r){const o=n[e];if(o)return"billingAddress"===r?`billing ${o}`:"deliveryAddress"===r?`shipping ${o}`:o}function l(n){const{i18n:l}=t(),{classNameModifiers:d=[],data:c,errors:u,valid:m,fieldName:p,onInput:f,onBlur:g,trimOnBlur:F,maxLength:y,disabled:C,addressType:M}=n,b=c[p],j=c.country,h=n.specifications.countryHasOptionalField(j,p),v=n.specifications.getKeyForField(p,j),w=h?` ${l.get("field.title.optional")}`:"",x=`${l.get(v)}${w}`,B=function(e,r,o,s){if("object"==typeof e[r]?.errorMessage){const{translationKey:s,translationObject:t}=e[r].errorMessage;return o.get(s,t)}return o.get(e[r]?.errorMessage,{values:{label:s.toLowerCase()}})||!!e[r]}(u,p,l,x);switch(p){case"country":return e(s,{allowedCountries:n.allowedCountries,classNameModifiers:d,label:x,errorMessage:B,onDropdownChange:n.onDropdownChange,value:b,required:!h});case"stateOrProvince":return e(o,{classNameModifiers:d,label:x,errorMessage:B,onDropdownChange:n.onDropdownChange,selectedCountry:j,specifications:n.specifications,value:b,required:!h});default:return e(r,{label:x,classNameModifiers:d,errorMessage:B,isValid:m[p],name:p,i18n:l,onFocus:e=>n.onFieldFocusAnalytics(p,e),onBlur:e=>n.onFieldBlurAnalytics(p,e)},e(i,{name:p,classNameModifiers:d,value:b,onInput:f,onBlur:g,maxlength:y,trimOnBlur:F,disabled:C,required:!h,autocomplete:a(p,M)}))}}export{l as default};
|
|
2
2
|
//# sourceMappingURL=FieldContainer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldContainer.js","sources":["../../../../../../src/components/internal/Address/components/FieldContainer.tsx"],"sourcesContent":["import { h } from 'preact';\nimport Field from '../../FormFields/Field';\nimport StateField from './StateField';\nimport CountryField from './CountryField';\nimport { AddressStateError, FieldContainerProps } from '../types';\nimport { useCoreContext } from '../../../../core/Context/CoreProvider';\nimport Language from '../../../../language/Language';\nimport InputText from '../../FormFields/InputText';\n\nfunction getErrorMessage(errors: AddressStateError, fieldName: string, i18n: Language, label: string): string | boolean {\n if (typeof errors[fieldName]?.errorMessage === 'object') {\n const { translationKey, translationObject } = errors[fieldName].errorMessage;\n return i18n.get(translationKey, translationObject);\n }\n // Default error msg: Enter the [label name]\n const errorMsg = i18n.get(errors[fieldName]?.errorMessage, { values: { label: label.toLowerCase() } });\n return errorMsg || !!errors[fieldName];\n}\n\n/**\n * USAGE: Specifically defined as a util to provide a wrapper for fields created within the Address component\n *\n * NOT TO BE USED: if you just want to add a Country or State dropdown outside of an Address component\n * - then you should implement <CountryField> or <StateField> directly\n */\nfunction FieldContainer(props: Readonly<FieldContainerProps>) {\n const { i18n } = useCoreContext();\n const { classNameModifiers = [], data, errors, valid, fieldName, onInput, onBlur, trimOnBlur, maxLength, disabled } = props;\n\n const value: string = data[fieldName];\n const selectedCountry: string = data.country;\n const isOptional: boolean = props.specifications.countryHasOptionalField(selectedCountry, fieldName);\n const labelKey: string = props.specifications.getKeyForField(fieldName, selectedCountry);\n const optionalLabel = isOptional ? ` ${i18n.get('field.title.optional')}` : '';\n const label = `${i18n.get(labelKey)}${optionalLabel}`;\n const errorMessage = getErrorMessage(errors, fieldName, i18n, label);\n\n switch (fieldName) {\n case 'country':\n return (\n <CountryField\n allowedCountries={props.allowedCountries}\n classNameModifiers={classNameModifiers}\n label={label}\n errorMessage={errorMessage}\n onDropdownChange={props.onDropdownChange}\n value={value}\n required={!isOptional}\n />\n );\n case 'stateOrProvince':\n return (\n <StateField\n classNameModifiers={classNameModifiers}\n label={label}\n errorMessage={errorMessage}\n onDropdownChange={props.onDropdownChange}\n selectedCountry={selectedCountry}\n specifications={props.specifications}\n value={value}\n required={!isOptional}\n />\n );\n default:\n return (\n <Field\n label={label}\n classNameModifiers={classNameModifiers}\n errorMessage={errorMessage}\n isValid={valid[fieldName]}\n name={fieldName}\n i18n={i18n}\n onFocus={e => props.onFieldFocusAnalytics(fieldName, e)}\n onBlur={e => props.onFieldBlurAnalytics(fieldName, e)}\n >\n <InputText\n name={fieldName}\n classNameModifiers={classNameModifiers}\n value={value}\n onInput={onInput}\n onBlur={onBlur}\n maxlength={maxLength}\n trimOnBlur={trimOnBlur}\n disabled={disabled}\n required={!isOptional}\n />\n </Field>\n );\n }\n}\n\nexport default FieldContainer;\n"],"names":["FieldContainer","props","i18n","useCoreContext","classNameModifiers","data","errors","valid","
|
|
1
|
+
{"version":3,"file":"FieldContainer.js","sources":["../../../../../../src/components/internal/Address/components/FieldContainer.tsx"],"sourcesContent":["import { h } from 'preact';\nimport Field from '../../FormFields/Field';\nimport StateField from './StateField';\nimport CountryField from './CountryField';\nimport { AddressStateError, AddressType, FieldContainerProps } from '../types';\nimport { useCoreContext } from '../../../../core/Context/CoreProvider';\nimport Language from '../../../../language/Language';\nimport InputText from '../../FormFields/InputText';\nimport { AutocompleteValue } from '../../FormFields/types';\nimport { ADDRESS_FIELD_TOKEN_MAP } from '../constants';\n\nfunction getErrorMessage(errors: AddressStateError, fieldName: string, i18n: Language, label: string): string | boolean {\n if (typeof errors[fieldName]?.errorMessage === 'object') {\n const { translationKey, translationObject } = errors[fieldName].errorMessage;\n return i18n.get(translationKey, translationObject);\n }\n // Default error msg: Enter the [label name]\n const errorMsg = i18n.get(errors[fieldName]?.errorMessage, { values: { label: label.toLowerCase() } });\n return errorMsg || !!errors[fieldName];\n}\n\n/**\n * USAGE: Specifically defined as a util to provide a wrapper for fields created within the Address component\n *\n * NOT TO BE USED: if you just want to add a Country or State dropdown outside of an Address component\n * - then you should implement <CountryField> or <StateField> directly\n */\nfunction getAddressAutocomplete(fieldName: string, addressType: AddressType): AutocompleteValue {\n const token = ADDRESS_FIELD_TOKEN_MAP[fieldName];\n if (!token) return undefined;\n if (addressType === 'billingAddress') return `billing ${token}` as AutocompleteValue;\n if (addressType === 'deliveryAddress') return `shipping ${token}` as AutocompleteValue;\n // Fallback: bare token (no prefix) when address type is unspecified\n return token as AutocompleteValue;\n}\n\nfunction FieldContainer(props: Readonly<FieldContainerProps>) {\n const { i18n } = useCoreContext();\n const { classNameModifiers = [], data, errors, valid, fieldName, onInput, onBlur, trimOnBlur, maxLength, disabled, addressType } = props;\n\n const value: string = data[fieldName];\n const selectedCountry: string = data.country;\n const isOptional: boolean = props.specifications.countryHasOptionalField(selectedCountry, fieldName);\n const labelKey: string = props.specifications.getKeyForField(fieldName, selectedCountry);\n const optionalLabel = isOptional ? ` ${i18n.get('field.title.optional')}` : '';\n const label = `${i18n.get(labelKey)}${optionalLabel}`;\n const errorMessage = getErrorMessage(errors, fieldName, i18n, label);\n\n switch (fieldName) {\n case 'country':\n return (\n <CountryField\n allowedCountries={props.allowedCountries}\n classNameModifiers={classNameModifiers}\n label={label}\n errorMessage={errorMessage}\n onDropdownChange={props.onDropdownChange}\n value={value}\n required={!isOptional}\n />\n );\n case 'stateOrProvince':\n return (\n <StateField\n classNameModifiers={classNameModifiers}\n label={label}\n errorMessage={errorMessage}\n onDropdownChange={props.onDropdownChange}\n selectedCountry={selectedCountry}\n specifications={props.specifications}\n value={value}\n required={!isOptional}\n />\n );\n default:\n return (\n <Field\n label={label}\n classNameModifiers={classNameModifiers}\n errorMessage={errorMessage}\n isValid={valid[fieldName]}\n name={fieldName}\n i18n={i18n}\n onFocus={e => props.onFieldFocusAnalytics(fieldName, e)}\n onBlur={e => props.onFieldBlurAnalytics(fieldName, e)}\n >\n <InputText\n name={fieldName}\n classNameModifiers={classNameModifiers}\n value={value}\n onInput={onInput}\n onBlur={onBlur}\n maxlength={maxLength}\n trimOnBlur={trimOnBlur}\n disabled={disabled}\n required={!isOptional}\n autocomplete={getAddressAutocomplete(fieldName, addressType)}\n />\n </Field>\n );\n }\n}\n\nexport default FieldContainer;\n"],"names":["getAddressAutocomplete","fieldName","addressType","token","ADDRESS_FIELD_TOKEN_MAP","FieldContainer","props","i18n","useCoreContext","classNameModifiers","data","errors","valid","onInput","onBlur","trimOnBlur","maxLength","disabled","value","selectedCountry","country","isOptional","specifications","countryHasOptionalField","labelKey","getKeyForField","optionalLabel","get","label","errorMessage","translationKey","translationObject","values","toLowerCase","getErrorMessage","h","CountryField","allowedCountries","onDropdownChange","required","StateField","Field","isValid","name","onFocus","e","onFieldFocusAnalytics","onFieldBlurAnalytics","InputText","maxlength","autocomplete"],"mappings":"2WA2BA,SAASA,EAAuBC,EAAmBC,GAC/C,MAAMC,EAAQC,EAAwBH,GACtC,GAAKE,EACL,MAAoB,mBAAhBD,EAAyC,WAAWC,IACpC,oBAAhBD,EAA0C,YAAYC,IAEnDA,CACX,CAEA,SAASE,EAAeC,GACpB,MAAMC,KAAEA,GAASC,KACXC,mBAAEA,EAAqB,GAAEC,KAAEA,EAAIC,OAAEA,EAAMC,MAAEA,EAAKX,UAAEA,EAASY,QAAEA,EAAOC,OAAEA,EAAMC,WAAEA,EAAUC,UAAEA,EAASC,SAAEA,EAAQf,YAAEA,GAAgBI,EAE7HY,EAAgBR,EAAKT,GACrBkB,EAA0BT,EAAKU,QAC/BC,EAAsBf,EAAMgB,eAAeC,wBAAwBJ,EAAiBlB,GACpFuB,EAAmBlB,EAAMgB,eAAeG,eAAexB,EAAWkB,GAClEO,EAAgBL,EAAa,IAAId,EAAKoB,IAAI,0BAA4B,GACtEC,EAAQ,GAAGrB,EAAKoB,IAAIH,KAAYE,IAChCG,EAnCV,SAAyBlB,EAA2BV,EAAmBM,EAAgBqB,GACnF,GAA+C,iBAApCjB,EAAOV,IAAY4B,aAA2B,CACrD,MAAMC,eAAEA,EAAcC,kBAAEA,GAAsBpB,EAAOV,GAAW4B,aAChE,OAAOtB,EAAKoB,IAAIG,EAAgBC,EACpC,CAGA,OADiBxB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