Edits history of script submission #2674 for ' Post sources (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post sources
     * Creates a new source object.
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        currency?: string;
        customer?: string;
        expand?: string[];
        flow?: "code_verification" | "none" | "receiver" | "redirect";
        mandate?: {
          acceptance?: {
            date?: number;
            ip?: string;
            offline?: { contact_email: string; [k: string]: unknown };
            online?: {
              date?: number;
              ip?: string;
              user_agent?: string;
              [k: string]: unknown;
            };
            status: "accepted" | "pending" | "refused" | "revoked";
            type?: "offline" | "online";
            user_agent?: string;
            [k: string]: unknown;
          };
          amount?: number | "";
          currency?: string;
          interval?: "one_time" | "scheduled" | "variable";
          notification_method?:
            | "deprecated_none"
            | "email"
            | "manual"
            | "none"
            | "stripe_email";
          [k: string]: unknown;
        };
        metadata?: { [k: string]: string };
        original_source?: string;
        owner?: {
          address?: {
            city?: string;
            country?: string;
            line1?: string;
            line2?: string;
            postal_code?: string;
            state?: string;
            [k: string]: unknown;
          };
          email?: string;
          name?: string;
          phone?: string;
          [k: string]: unknown;
        };
        receiver?: {
          refund_attributes_method?: "email" | "manual" | "none";
          [k: string]: unknown;
        };
        redirect?: { return_url: string; [k: string]: unknown };
        source_order?: {
          items?: {
            amount?: number;
            currency?: string;
            description?: string;
            parent?: string;
            quantity?: number;
            type?: "discount" | "shipping" | "sku" | "tax";
            [k: string]: unknown;
          }[];
          shipping?: {
            address: {
              city?: string;
              country?: string;
              line1: string;
              line2?: string;
              postal_code?: string;
              state?: string;
              [k: string]: unknown;
            };
            carrier?: string;
            name?: string;
            phone?: string;
            tracking_number?: string;
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        statement_descriptor?: string;
        token?: string;
        type?: string;
        usage?: "reusable" | "single_use";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/sources`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: encodeParams(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    
    function encodeParams(o: any) {
      function iter(o: any, path: string) {
        if (Array.isArray(o)) {
          o.forEach(function (a) {
            iter(a, path + "[]");
          });
          return;
        }
        if (o !== null && typeof o === "object") {
          Object.keys(o).forEach(function (k) {
            iter(o[k], path + "[" + k + "]");
          });
          return;
        }
        data.push(path + "=" + o);
      }
      const data: string[] = [];
      Object.keys(o).forEach(function (k) {
        if (o[k] !== undefined) {
          iter(o[k], k);
        }
      });
      return new URLSearchParams(data.join("&"));
    }
    

    Submitted by hugo697 368 days ago

  • nativets
    type Stripe = {
      token: string;
    };
    /**
     * Post sources
     * Creates a new source object.
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        currency?: string;
        customer?: string;
        expand?: string[];
        flow?: "code_verification" | "none" | "receiver" | "redirect";
        mandate?: {
          acceptance?: {
            date?: number;
            ip?: string;
            offline?: { contact_email: string; [k: string]: unknown };
            online?: {
              date?: number;
              ip?: string;
              user_agent?: string;
              [k: string]: unknown;
            };
            status: "accepted" | "pending" | "refused" | "revoked";
            type?: "offline" | "online";
            user_agent?: string;
            [k: string]: unknown;
          };
          amount?: number | "";
          currency?: string;
          interval?: "one_time" | "scheduled" | "variable";
          notification_method?:
            | "deprecated_none"
            | "email"
            | "manual"
            | "none"
            | "stripe_email";
          [k: string]: unknown;
        };
        metadata?: { [k: string]: string };
        original_source?: string;
        owner?: {
          address?: {
            city?: string;
            country?: string;
            line1?: string;
            line2?: string;
            postal_code?: string;
            state?: string;
            [k: string]: unknown;
          };
          email?: string;
          name?: string;
          phone?: string;
          [k: string]: unknown;
        };
        receiver?: {
          refund_attributes_method?: "email" | "manual" | "none";
          [k: string]: unknown;
        };
        redirect?: { return_url: string; [k: string]: unknown };
        source_order?: {
          items?: {
            amount?: number;
            currency?: string;
            description?: string;
            parent?: string;
            quantity?: number;
            type?: "discount" | "shipping" | "sku" | "tax";
            [k: string]: unknown;
          }[];
          shipping?: {
            address: {
              city?: string;
              country?: string;
              line1: string;
              line2?: string;
              postal_code?: string;
              state?: string;
              [k: string]: unknown;
            };
            carrier?: string;
            name?: string;
            phone?: string;
            tracking_number?: string;
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        statement_descriptor?: string;
        token?: string;
        type?: string;
        usage?: "reusable" | "single_use";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/sources`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: encodeParams(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    
    function encodeParams(o: any) {
      function iter(o: any, path: string) {
        if (Array.isArray(o)) {
          o.forEach(function (a) {
            iter(a, path + "[]");
          });
          return;
        }
        if (o !== null && typeof o === "object") {
          Object.keys(o).forEach(function (k) {
            iter(o[k], path + "[" + k + "]");
          });
          return;
        }
        data.push(path + "=" + o);
      }
      const data: string[] = [];
      Object.keys(o).forEach(function (k) {
        if (o[k] !== undefined) {
          iter(o[k], k);
        }
      });
      return new URLSearchParams(data.join("&"));
    }
    

    Submitted by hugo697 795 days ago

  • nativets
    type Stripe = {
      token: string;
    };
    /**
     * Post sources
     * <p>Creates a new source object.</p>
     */
    export async function main(
      auth: Stripe,
      body: {
        amount?: number;
        currency?: string;
        customer?: string;
        expand?: string[];
        flow?: "code_verification" | "none" | "receiver" | "redirect";
        mandate?: {
          acceptance?: {
            date?: number;
            ip?: string;
            offline?: { contact_email: string; [k: string]: unknown };
            online?: {
              date?: number;
              ip?: string;
              user_agent?: string;
              [k: string]: unknown;
            };
            status: "accepted" | "pending" | "refused" | "revoked";
            type?: "offline" | "online";
            user_agent?: string;
            [k: string]: unknown;
          };
          amount?: number | "";
          currency?: string;
          interval?: "one_time" | "scheduled" | "variable";
          notification_method?:
            | "deprecated_none"
            | "email"
            | "manual"
            | "none"
            | "stripe_email";
          [k: string]: unknown;
        };
        metadata?: { [k: string]: string };
        original_source?: string;
        owner?: {
          address?: {
            city?: string;
            country?: string;
            line1?: string;
            line2?: string;
            postal_code?: string;
            state?: string;
            [k: string]: unknown;
          };
          email?: string;
          name?: string;
          phone?: string;
          [k: string]: unknown;
        };
        receiver?: {
          refund_attributes_method?: "email" | "manual" | "none";
          [k: string]: unknown;
        };
        redirect?: { return_url: string; [k: string]: unknown };
        source_order?: {
          items?: {
            amount?: number;
            currency?: string;
            description?: string;
            parent?: string;
            quantity?: number;
            type?: "discount" | "shipping" | "sku" | "tax";
            [k: string]: unknown;
          }[];
          shipping?: {
            address: {
              city?: string;
              country?: string;
              line1: string;
              line2?: string;
              postal_code?: string;
              state?: string;
              [k: string]: unknown;
            };
            carrier?: string;
            name?: string;
            phone?: string;
            tracking_number?: string;
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        statement_descriptor?: string;
        token?: string;
        type?: string;
        usage?: "reusable" | "single_use";
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/sources`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
          Authorization: "Bearer " + auth.token,
        },
        body: encodeParams(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    
    function encodeParams(o: any) {
      function iter(o: any, path: string) {
        if (Array.isArray(o)) {
          o.forEach(function (a) {
            iter(a, path + "[]");
          });
          return;
        }
        if (o !== null && typeof o === "object") {
          Object.keys(o).forEach(function (k) {
            iter(o[k], path + "[" + k + "]");
          });
          return;
        }
        data.push(path + "=" + o);
      }
      const data: string[] = [];
      Object.keys(o).forEach(function (k) {
        if (o[k] !== undefined) {
          iter(o[k], k);
        }
      });
      return new URLSearchParams(data.join("&"));
    }
    

    Submitted by hugo697 922 days ago