Edits history of script submission #2796 for ' Post payment methods payment method (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post payment methods payment method
     * Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated.
     */
    export async function main(
      auth: Stripe,
      payment_method: string,
      body: {
        billing_details?: {
          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;
        };
        card?: {
          exp_month?: number;
          exp_year?: number;
          networks?: {
            preferred?: "" | "cartes_bancaires" | "mastercard" | "visa";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        expand?: string[];
        link?: { [k: string]: unknown };
        metadata?: { [k: string]: string } | "";
        us_bank_account?: {
          account_holder_type?: "company" | "individual";
          account_type?: "checking" | "savings";
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/payment_methods/${payment_method}`
      );
    
      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 payment methods payment method
     * Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated.
     */
    export async function main(
      auth: Stripe,
      payment_method: string,
      body: {
        billing_details?: {
          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;
        };
        card?: {
          exp_month?: number;
          exp_year?: number;
          networks?: {
            preferred?: "" | "cartes_bancaires" | "mastercard" | "visa";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        expand?: string[];
        link?: { [k: string]: unknown };
        metadata?: { [k: string]: string } | "";
        us_bank_account?: {
          account_holder_type?: "company" | "individual";
          account_type?: "checking" | "savings";
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/payment_methods/${payment_method}`
      );
    
      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 payment methods payment method
     * <p>Updates a PaymentMethod object. A PaymentMethod must be attached a customer to be updated.</p>
     */
    export async function main(
      auth: Stripe,
      payment_method: string,
      body: {
        billing_details?: {
          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;
        };
        card?: { exp_month?: number; exp_year?: number; [k: string]: unknown };
        expand?: string[];
        link?: { [k: string]: unknown };
        metadata?: { [k: string]: string } | "";
        us_bank_account?: {
          account_holder_type?: "company" | "individual";
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/payment_methods/${payment_method}`
      );
    
      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