Edits history of script submission #14310 for ' network-tokens (basis_theory)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Basistheory = {
      apiKey: string;
    };
    /**
     * network-tokens
     * network-tokens
     */
    export async function main(
      auth: Basistheory,
      body: {
        cardholder_info?: {
          address?: {
            city?: string;
            country_code?: string;
            line1?: string;
            line2?: string;
            line3?: string;
            postal_code?: string;
            state_code?: string;
          };
          name?: string;
        };
        containers?: string[];
        data?: {
          cvc?: string;
          expiration_month?: string;
          expiration_year?: string;
          number?: string;
        };
        merchant_id?: string;
      },
    ) {
      const url = new URL(`https://api.basistheory.com/connections/network-tokens`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          "BT-API-KEY": auth.apiKey,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago