Edits history of script submission #12186 for ' Validate International IBANs and obtain essential information (greip)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Greip = {
      apiKey: string;
    };
    /**
     * Validate International IBANs and obtain essential information
     * This method enables you to validate International Bank Account Numbers (IBANs) and obtain essential information about the country associated with each IBAN.
    
    By using this API, you can ensure that the IBANs are formatted correctly and gain insights into the banking institution, enhancing security and accuracy in financial transactions.
     */
    export async function main(
      auth: Greip,
      iban: string,
      format: string | undefined,
      userID: string | undefined,
      mode: string | undefined,
      callback: string | undefined,
    ) {
      const url = new URL(`https://greipapi.com/lookup/iban`);
      for (const [k, v] of [
        ["iban", iban],
        ["format", format],
        ["userID", userID],
        ["mode", mode],
        ["callback", callback],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.apiKey,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago