/** * Constructs a TokenRequest object for creating a token for a Credit Card. * @param {string} name - Card holder’s name on the Credit Card. * @param {string} number - Credit Card number without any separators. * @param {string} cvc - Credit Card's security code. * @param {string} month - Two digit number representing the Credit Card's expiration month. * @param {string} year - Two or four digit number representing the Credit Card's expiration year. * @param {string} [baseUrl='https://api.moyasar.com'] baseUrl - The base URL for Moyasar API. Defaults to 'https://api.moyasar.com'. * @param {string} callbackUrl - The URL to be redirected to after a 3D secure transaction (e.g., https://sdk.moyasar.com/return). * @param {Record | null} [metadata] - Adds searchable key/value pairs to the payment. For example `{"size": "xl"}`. */ export class TokenRequest { name: string; number: string; cvc: string; month: string; year: string; baseUrl: string; callbackUrl: string; metadata?: Record | null; constructor({ name, number, cvc, month, year, baseUrl = 'https://api.moyasar.com', callbackUrl, metadata, }: { name: string; number: string; cvc: string; month: string; year: string; baseUrl?: string; callbackUrl: string; metadata?: Record | null; }) { this.name = name; this.number = number; this.cvc = cvc; this.month = month; this.year = year; const cleanedBaseUrl = baseUrl.replace(/\/+$/, ''); // Removes trailing slashes this.baseUrl = cleanedBaseUrl; this.callbackUrl = callbackUrl; this.metadata = metadata; } toJson(): Record { return { name: this.name, number: this.number, cvc: this.cvc, month: this.month, year: this.year, save_only: true, callback_url: this.callbackUrl, metadata: this.metadata, }; } }