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

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post sources source
     * Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
    
    This request accepts the metadata and owner as arguments. It is also possible to update type specific information for selected payment methods. Please refer to our payment method guides for more detail.
     */
    export async function main(
      auth: Stripe,
      source: string,
      body: {
        amount?: number;
        expand?: string[];
        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 } | "";
        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;
        };
        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;
        };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/sources/${source}`);
    
      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 source
     * Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.
    
    This request accepts the metadata and owner as arguments. It is also possible to update type specific information for selected payment methods. Please refer to our payment method guides for more detail.
     */
    export async function main(
      auth: Stripe,
      source: string,
      body: {
        amount?: number;
        expand?: string[];
        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 } | "";
        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;
        };
        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;
        };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/sources/${source}`);
    
      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 source
     * <p>Updates the specified source by setting the values of the parameters passed. Any parameters not provided will be left unchanged.</p>
    
    <p>This request accepts the <code>metadata</code> and <code>owner</code> as arguments. It is also possible to update type specific information for selected payment methods. Please refer to our <a href="/docs/sources">payment method guides</a> for more detail.</p>
     */
    export async function main(
      auth: Stripe,
      source: string,
      body: {
        amount?: number;
        expand?: string[];
        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 } | "";
        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;
        };
        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;
        };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/sources/${source}`);
    
      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