Edits history of script submission #2811 for ' Post charges charge capture (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post charges charge capture
     * Capture the payment of an existing, uncaptured charge that was created with the capture option set to false.
    
    Uncaptured payments expire a set number of days after they are created (7 by default), after which they are marked as refunded and capture attempts will fail.
    
    Don’t use this method to capture a PaymentIntent-initiated charge. Use Capture a PaymentIntent.
     */
    export async function main(
      auth: Stripe,
      charge: string,
      body: {
        amount?: number;
        application_fee?: number;
        application_fee_amount?: number;
        expand?: string[];
        receipt_email?: string;
        statement_descriptor?: string;
        statement_descriptor_suffix?: string;
        transfer_data?: { amount?: number; [k: string]: unknown };
        transfer_group?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/charges/${charge}/capture`);
    
      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 charges charge capture
     * Capture the payment of an existing, uncaptured charge that was created with the capture option set to false.
    
    Uncaptured payments expire a set number of days after they are created (7 by default), after which they are marked as refunded and capture attempts will fail.
    
    Don’t use this method to capture a PaymentIntent-initiated charge. Use Capture a PaymentIntent.
     */
    export async function main(
      auth: Stripe,
      charge: string,
      body: {
        amount?: number;
        application_fee?: number;
        application_fee_amount?: number;
        expand?: string[];
        receipt_email?: string;
        statement_descriptor?: string;
        statement_descriptor_suffix?: string;
        transfer_data?: { amount?: number; [k: string]: unknown };
        transfer_group?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/charges/${charge}/capture`);
    
      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 charges charge capture
     * <p>Capture the payment of an existing, uncaptured charge that was created with the <code>capture</code> option set to false.</p>
    
    <p>Uncaptured payments expire a set number of days after they are created (<a href="/docs/charges/placing-a-hold">7 by default</a>), after which they are marked as refunded and capture attempts will fail.</p>
    
    <p>Don’t use this method to capture a PaymentIntent-initiated charge. Use <a href="/docs/api/payment_intents/capture">Capture a PaymentIntent</a>.</p>
     */
    export async function main(
      auth: Stripe,
      charge: string,
      body: {
        amount?: number;
        application_fee?: number;
        application_fee_amount?: number;
        expand?: string[];
        receipt_email?: string;
        statement_descriptor?: string;
        statement_descriptor_suffix?: string;
        transfer_data?: { amount?: number; [k: string]: unknown };
        transfer_group?: string;
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/charges/${charge}/capture`);
    
      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