UNPKG

@square/web-payments-sdk-types

Version:

Types for Square's Web Payments SDK

80 lines (79 loc) 2.47 kB
import type { MethodType } from '../types/payment-method/payment-method-types'; import { SqError } from './types'; /** * Exception thrown when a Payment Method instance is attached more than once. * @example * try { * await card.attach('#card'); * await card.attach('#card'); * } * catch (e) { * if (e instanceof PaymentMethodAlreadyAttachedError){ * alert("The Card payment method is already attached to the page"); * } * } */ declare class PaymentMethodAlreadyAttachedError extends SqError { constructor(paymentMethod: string); } /** * A method was called on a payment method before it is attached * to a page HTML DOM element. * @example * try { * card.addEventListener("cardBrandChanged", async (cardInputEvent) => { * alert(`Card brand changed to ${cardInputEvent.cardBrand}`); * }); * } * catch (e) { * if (e instanceof PaymentMethodNotAttachedError){ * alert("The Card payment method has not been attached to the page"); * } * } */ declare class PaymentMethodNotAttachedError extends SqError { constructor(paymentMethod: string); } /** * Exception thrown when a Payment Method instance is already destroyed. * @example * try { * await card.destroy(); * await card.attach('#card'); * } * catch (e) { * if (e instanceof PaymentMethodAlreadyDestroyedError){ * alert("The Card payment method has been destroyed"); * } * } */ declare class PaymentMethodAlreadyDestroyedError extends SqError { constructor(paymentMethod: string); } /** * The developer attempted to attach a payment method with an invalid selector or element type. * @example * try { * const result = await card.attach('input'); * } * catch(e) { * alert(`Card not attached: ${e.name} ${e.message}`); * } */ declare class InvalidElementTypeError extends SqError { constructor(element: HTMLElement | string, allowedElements: Set<string>); } /** * The developer has an element with a forbidden/clashing ID on the page. * @example * try { * payments.googlePay(paymentReq); * } * catch(e) { * alert(`Google Pay could not be initiated due to: ${e.name} ${e.message}`); * } */ declare class InvalidElementPresentError extends SqError { constructor(paymentMethod: MethodType, elementIds: string); } export { PaymentMethodAlreadyAttachedError, PaymentMethodNotAttachedError, PaymentMethodAlreadyDestroyedError, InvalidElementTypeError, InvalidElementPresentError, };