import '@vaadin/vaadin-button'; import { PropertyDeclarations, TemplateResult } from 'lit-element'; import { Item } from './private/Item'; import { ItemInterface } from './types'; import { SignableFields } from './private/SignableFields'; export { Item }; /** * A custom element providing a customizable donation form. * * @fires ItemsForm#change - changed form data. * @fires ItemsForm#submit - submitted form data * @fires ItemsForm#load - ProgressEvent instance with server response * * @slot items - items to be added to the form. * * @element foxy-items-form * */ export declare class ItemsForm extends SignableFields { /** @readonly */ static get scopedElements(): Record; /** @readonly */ static get properties(): PropertyDeclarations; /** * **Required** store subdomain, It is similar to mystore.foxycart.com, * unless you use a custom subdomain. * * **Examples:** `"mystore.foxycart.com"` `"custom.mycoolstore.com"` */ store?: string; /** * **Required** 3-letter lowercase currency code. * * **Example:** `"usd"` */ currency?: string; /** * Makes the entire form readonly. */ readonly: boolean; /** * Defines target of the form * * This attribute controls the destination window of the form submission. */ target: string; /** * Defines the next cart step * * It can only be either add or checkout. * If "add" is chosen, this form will add items to the cart and the user will * be directed to the cart with these products added upon submission. * * If set to "checkout" (this is the default) the user will be directed to * checkout. */ cart: string; /** * Optional frequency string encoded as count (integer) + units (one of: `d` * for days, `w` for weeks, `m` for months, `y` for years). A special value * for twice a month is also supported: `.5m`. If set, the form will create a * subscription with the specified frequency in the cart. * * **Example:** `"1m"` */ sub_frequency?: string; /** * Optional subscription start date encoded as four integer for the year, two * for the month and two for the day. If only two or one digits are provided, * it is assumed to be next occurence of that day of the month, from the * current date. * * See [Products wiki for more details](https://wiki.foxycart.com/v/2.0/products#a_complete_list_of_product_parameters) * * ** Example:** `"10"` */ sub_startdate?: string; /** * Optional subscription token, unique URL of a subscription, retrieved from * the API, XML datafeeds or Admin interface. */ sub_token?: string; /** * Optional. Allows the “add to cart” link or form to completely replace the * existing subscription loaded * * Can be either "replace", "append" or "" (a blank string). * Using "append" or "" will result in adding these items to an existing * subscription in addition to the existing ones. * * The "append" value is set for convenience, as it describes the behaviour. * The submitted value, in this case, will be "". The submitted value, in * this case, will be "". * * Using "replace" results in replacing the existing subscription with the * current itmes. * See [Products subscription options](https://wiki.foxycart.com/v/2.0/products/subscriptions#subscription-related_product_options) */ sub_modify: string; /** * Set to "true" to indicate that payment is collectable right now. * Set to "auto" to indicate that payment is collectable right now if the * subscription's past-due amount is greater than 0 */ sub_restart: string; /** * Optional subscription end date encoded as four integer for the year, two * for the month and two for the day. * * The absence of a sub_enddate, together with a sub_frequency, means a * subscription with indefinite and date. * * See [Products wiki for more details](https://wiki.foxycart.com/v/2.0/products#a_complete_list_of_product_parameters) * * ** Example:** `"20221010"` */ sub_enddate?: string; /** * Optional frequency variants in the same format as `frequency`. If this property is set, * the form will render the frequency selection interface. If this array includes * the value of the `frequency` property, it will be pre-selected in the form. * * **Example:** `["7d", ".5m", "1y"]` */ frequencies: string[]; /** * Handles the submission of the form * * - creates a FormData * - fill the FormData with item values * - add order wide fields to the FormData * - submits the form */ private handleSubmit; private __childItemsObserver?; private __hasValidItems; private __total; /** * Handles the user input for frequenty field * - converts week, year, day and month into first letter only * - removes spaces * - removes leading zeroes * - validates input as propper frequency option **/ private __handleFrequency; private __data; constructor(); get items(): ItemInterface[]; /** * Optional an array of ItemInterface objects with at least the following properties: * - name: the name of the item * - price: the price of each of this item * The following optional properties will be used: * - quantity: (defaults to 1) how many of each item are added to the form * - image: an image url to be displayed in the form for this item * - items: an array of other items that are to be treated as bundled with this item * - signatures: an object containing a key value list of previously generated HMAC validation codes * * Other item properties are accepted and sent to foxy cart * See [Products wiki for more details](https://wiki.foxycart.com/v/2.0/products#a_complete_list_of_product_parameters) */ set items(value: ItemInterface[]); /** * The total value of the items to be submitted. */ get total(): number; render(): TemplateResult; /** Add new items */ addItems(newItems: ItemInterface[]): void; /** Remove items */ removeItems(itemIds: number[]): void; updated(): void; createItem(p: ItemInterface): Element; private __submitBtnText; /** * An array with both items created as elements and created parameter */ private get __itemElements(); /** Create child Items from items array */ private __createItemsFromItemArray; /** Removes item from the form based on a condition */ private __removeItems; /** * Adds a signature to a post field * * This method does not compute the signature. It must be provided. * * @argument string name The name of the field * @argument string signature The computed signature to add to the field * @argument string open Whether the field value is customized by the user * @return string signedName the name of the field with the signature */ private __addSignature; /** * Add all items from this.__itemElements to a FormData * * - Iterate of items in itemElements * - Add valid items to Form Data * * @argument FormData fd the FormData instance to fill * @return number the number of items added **/ private __formDataFill; /** * Add custom user provided fields */ private __formDataCustomInputs; private __isAttributeReserved; /** * Adds a item to a form data * * @argument {FormData} fd the FormData to which the item will be added * @argument {Item} the item to add **/ private __formDataAddItem; /** * Adds subscription fields to a FormData * * @argument {FormData} fd the FormData to which subscription fields will be added **/ private __formDataAddSubscriptionFields; /** * Adds cart wide subscription fields to a FormData * * @argument {FormData} fd the FormData to which subscription fields will be added */ private __formDataAddCartWideSubscriptionFields; /** * Adds cart related fields to a FormData * * @argument {FormData} fd the FormData to which the cart fields will be added. */ private __formDataAddCartFields; /** * Validates a string for subscription start date or end date according to * * @argument string strDate the date as a string to be used as start or end date. * * https://wiki.foxycart.com/v/2.0/products#subscription_product_options * See [Products subscription options for more details](https://wiki.foxycart.com/v/2.0/products#subscription_product_options) */ private static __validDate; /** * Checks if a string date is in the future. * * @argument string strdate the date, as a string, to be checked. * @returns boolean the date is a valid future date. */ private static __validDateFuture; /** * Checks if a frequency complies with possible values * * @argument string strFrequency the frequency string to be validated. * @returns boolean the string is a foxy cart frequency string. */ private static __validFrequency; /** Subscribe to late inserted items. * * @argument MutationRecord[] the list of changes occurred. **/ private __observeChildren; /** Updates the form on item change */ private __itemChange; /** Compute the total price of all items in the form */ private __computeTotalPrice; /** Go through all pcroduct elements and executes acknoledges each one */ private __acknowledgeItemElements; /** * Treat this item item element as part of the form: * * - listen to its change events * - set its currency to be the forms currency */ private __acknowledgeItemElement; /** * Checks if item has quantity and price * * @argument Item the item to be validated * @returns boolean the item is valid **/ private __validItem; /** * Translates a frequency string * * @argument string the frequency string to be translated * @returns string the translated string */ private __translateFrequency; /** * Translate a given amount * * @argument number the amount to be translated * @returns string the translated amount */ private __translateAmount; private __updateData; }