Edits history of script submission #2451 for ' Post payment links (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post payment links
     * Creates a payment link.
     */
    export async function main(
      auth: Stripe,
      body: {
        after_completion?: {
          hosted_confirmation?: { custom_message?: string; [k: string]: unknown };
          redirect?: { url: string; [k: string]: unknown };
          type: "hosted_confirmation" | "redirect";
          [k: string]: unknown;
        };
        allow_promotion_codes?: boolean;
        application_fee_amount?: number;
        application_fee_percent?: number;
        automatic_tax?: {
          enabled: boolean;
          liability?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        billing_address_collection?: "auto" | "required";
        consent_collection?: {
          payment_method_reuse_agreement?: {
            position: "auto" | "hidden";
            [k: string]: unknown;
          };
          promotions?: "auto" | "none";
          terms_of_service?: "none" | "required";
          [k: string]: unknown;
        };
        currency?: string;
        custom_fields?: {
          dropdown?: {
            options: { label: string; value: string; [k: string]: unknown }[];
            [k: string]: unknown;
          };
          key: string;
          label: { custom: string; type: "custom"; [k: string]: unknown };
          numeric?: {
            maximum_length?: number;
            minimum_length?: number;
            [k: string]: unknown;
          };
          optional?: boolean;
          text?: {
            maximum_length?: number;
            minimum_length?: number;
            [k: string]: unknown;
          };
          type: "dropdown" | "numeric" | "text";
          [k: string]: unknown;
        }[];
        custom_text?: {
          after_submit?: { message: string; [k: string]: unknown } | "";
          shipping_address?: { message: string; [k: string]: unknown } | "";
          submit?: { message: string; [k: string]: unknown } | "";
          terms_of_service_acceptance?:
            | { message: string; [k: string]: unknown }
            | "";
          [k: string]: unknown;
        };
        customer_creation?: "always" | "if_required";
        expand?: string[];
        inactive_message?: string;
        invoice_creation?: {
          enabled: boolean;
          invoice_data?: {
            account_tax_ids?: string[] | "";
            custom_fields?:
              | { name: string; value: string; [k: string]: unknown }[]
              | "";
            description?: string;
            footer?: string;
            issuer?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            metadata?: { [k: string]: string } | "";
            rendering_options?:
              | {
                  amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
                  [k: string]: unknown;
                }
              | "";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        line_items: {
          adjustable_quantity?: {
            enabled: boolean;
            maximum?: number;
            minimum?: number;
            [k: string]: unknown;
          };
          price: string;
          quantity: number;
          [k: string]: unknown;
        }[];
        metadata?: { [k: string]: string };
        on_behalf_of?: string;
        payment_intent_data?: {
          capture_method?: "automatic" | "automatic_async" | "manual";
          description?: string;
          metadata?: { [k: string]: string };
          setup_future_usage?: "off_session" | "on_session";
          statement_descriptor?: string;
          statement_descriptor_suffix?: string;
          transfer_group?: string;
          [k: string]: unknown;
        };
        payment_method_collection?: "always" | "if_required";
        payment_method_types?: (
          | "affirm"
          | "afterpay_clearpay"
          | "alipay"
          | "au_becs_debit"
          | "bacs_debit"
          | "bancontact"
          | "blik"
          | "boleto"
          | "card"
          | "cashapp"
          | "eps"
          | "fpx"
          | "giropay"
          | "grabpay"
          | "ideal"
          | "klarna"
          | "konbini"
          | "link"
          | "oxxo"
          | "p24"
          | "paynow"
          | "paypal"
          | "pix"
          | "promptpay"
          | "sepa_debit"
          | "sofort"
          | "swish"
          | "us_bank_account"
          | "wechat_pay"
        )[];
        phone_number_collection?: { enabled: boolean; [k: string]: unknown };
        restrictions?: {
          completed_sessions: { limit: number; [k: string]: unknown };
          [k: string]: unknown;
        };
        shipping_address_collection?: {
          allowed_countries: (
            | "AC"
            | "AD"
            | "AE"
            | "AF"
            | "AG"
            | "AI"
            | "AL"
            | "AM"
            | "AO"
            | "AQ"
            | "AR"
            | "AT"
            | "AU"
            | "AW"
            | "AX"
            | "AZ"
            | "BA"
            | "BB"
            | "BD"
            | "BE"
            | "BF"
            | "BG"
            | "BH"
            | "BI"
            | "BJ"
            | "BL"
            | "BM"
            | "BN"
            | "BO"
            | "BQ"
            | "BR"
            | "BS"
            | "BT"
            | "BV"
            | "BW"
            | "BY"
            | "BZ"
            | "CA"
            | "CD"
            | "CF"
            | "CG"
            | "CH"
            | "CI"
            | "CK"
            | "CL"
            | "CM"
            | "CN"
            | "CO"
            | "CR"
            | "CV"
            | "CW"
            | "CY"
            | "CZ"
            | "DE"
            | "DJ"
            | "DK"
            | "DM"
            | "DO"
            | "DZ"
            | "EC"
            | "EE"
            | "EG"
            | "EH"
            | "ER"
            | "ES"
            | "ET"
            | "FI"
            | "FJ"
            | "FK"
            | "FO"
            | "FR"
            | "GA"
            | "GB"
            | "GD"
            | "GE"
            | "GF"
            | "GG"
            | "GH"
            | "GI"
            | "GL"
            | "GM"
            | "GN"
            | "GP"
            | "GQ"
            | "GR"
            | "GS"
            | "GT"
            | "GU"
            | "GW"
            | "GY"
            | "HK"
            | "HN"
            | "HR"
            | "HT"
            | "HU"
            | "ID"
            | "IE"
            | "IL"
            | "IM"
            | "IN"
            | "IO"
            | "IQ"
            | "IS"
            | "IT"
            | "JE"
            | "JM"
            | "JO"
            | "JP"
            | "KE"
            | "KG"
            | "KH"
            | "KI"
            | "KM"
            | "KN"
            | "KR"
            | "KW"
            | "KY"
            | "KZ"
            | "LA"
            | "LB"
            | "LC"
            | "LI"
            | "LK"
            | "LR"
            | "LS"
            | "LT"
            | "LU"
            | "LV"
            | "LY"
            | "MA"
            | "MC"
            | "MD"
            | "ME"
            | "MF"
            | "MG"
            | "MK"
            | "ML"
            | "MM"
            | "MN"
            | "MO"
            | "MQ"
            | "MR"
            | "MS"
            | "MT"
            | "MU"
            | "MV"
            | "MW"
            | "MX"
            | "MY"
            | "MZ"
            | "NA"
            | "NC"
            | "NE"
            | "NG"
            | "NI"
            | "NL"
            | "NO"
            | "NP"
            | "NR"
            | "NU"
            | "NZ"
            | "OM"
            | "PA"
            | "PE"
            | "PF"
            | "PG"
            | "PH"
            | "PK"
            | "PL"
            | "PM"
            | "PN"
            | "PR"
            | "PS"
            | "PT"
            | "PY"
            | "QA"
            | "RE"
            | "RO"
            | "RS"
            | "RU"
            | "RW"
            | "SA"
            | "SB"
            | "SC"
            | "SE"
            | "SG"
            | "SH"
            | "SI"
            | "SJ"
            | "SK"
            | "SL"
            | "SM"
            | "SN"
            | "SO"
            | "SR"
            | "SS"
            | "ST"
            | "SV"
            | "SX"
            | "SZ"
            | "TA"
            | "TC"
            | "TD"
            | "TF"
            | "TG"
            | "TH"
            | "TJ"
            | "TK"
            | "TL"
            | "TM"
            | "TN"
            | "TO"
            | "TR"
            | "TT"
            | "TV"
            | "TW"
            | "TZ"
            | "UA"
            | "UG"
            | "US"
            | "UY"
            | "UZ"
            | "VA"
            | "VC"
            | "VE"
            | "VG"
            | "VN"
            | "VU"
            | "WF"
            | "WS"
            | "XK"
            | "YE"
            | "YT"
            | "ZA"
            | "ZM"
            | "ZW"
            | "ZZ"
          )[];
          [k: string]: unknown;
        };
        shipping_options?: { shipping_rate?: string; [k: string]: unknown }[];
        submit_type?: "auto" | "book" | "donate" | "pay";
        subscription_data?: {
          description?: string;
          invoice_settings?: {
            issuer?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          metadata?: { [k: string]: string };
          trial_period_days?: number;
          trial_settings?: {
            end_behavior: {
              missing_payment_method: "cancel" | "create_invoice" | "pause";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        tax_id_collection?: { enabled: boolean; [k: string]: unknown };
        transfer_data?: {
          amount?: number;
          destination: string;
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/payment_links`);
    
      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 links
     * Creates a payment link.
     */
    export async function main(
      auth: Stripe,
      body: {
        after_completion?: {
          hosted_confirmation?: { custom_message?: string; [k: string]: unknown };
          redirect?: { url: string; [k: string]: unknown };
          type: "hosted_confirmation" | "redirect";
          [k: string]: unknown;
        };
        allow_promotion_codes?: boolean;
        application_fee_amount?: number;
        application_fee_percent?: number;
        automatic_tax?: {
          enabled: boolean;
          liability?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        billing_address_collection?: "auto" | "required";
        consent_collection?: {
          payment_method_reuse_agreement?: {
            position: "auto" | "hidden";
            [k: string]: unknown;
          };
          promotions?: "auto" | "none";
          terms_of_service?: "none" | "required";
          [k: string]: unknown;
        };
        currency?: string;
        custom_fields?: {
          dropdown?: {
            options: { label: string; value: string; [k: string]: unknown }[];
            [k: string]: unknown;
          };
          key: string;
          label: { custom: string; type: "custom"; [k: string]: unknown };
          numeric?: {
            maximum_length?: number;
            minimum_length?: number;
            [k: string]: unknown;
          };
          optional?: boolean;
          text?: {
            maximum_length?: number;
            minimum_length?: number;
            [k: string]: unknown;
          };
          type: "dropdown" | "numeric" | "text";
          [k: string]: unknown;
        }[];
        custom_text?: {
          after_submit?: { message: string; [k: string]: unknown } | "";
          shipping_address?: { message: string; [k: string]: unknown } | "";
          submit?: { message: string; [k: string]: unknown } | "";
          terms_of_service_acceptance?:
            | { message: string; [k: string]: unknown }
            | "";
          [k: string]: unknown;
        };
        customer_creation?: "always" | "if_required";
        expand?: string[];
        inactive_message?: string;
        invoice_creation?: {
          enabled: boolean;
          invoice_data?: {
            account_tax_ids?: string[] | "";
            custom_fields?:
              | { name: string; value: string; [k: string]: unknown }[]
              | "";
            description?: string;
            footer?: string;
            issuer?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            metadata?: { [k: string]: string } | "";
            rendering_options?:
              | {
                  amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
                  [k: string]: unknown;
                }
              | "";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        line_items: {
          adjustable_quantity?: {
            enabled: boolean;
            maximum?: number;
            minimum?: number;
            [k: string]: unknown;
          };
          price: string;
          quantity: number;
          [k: string]: unknown;
        }[];
        metadata?: { [k: string]: string };
        on_behalf_of?: string;
        payment_intent_data?: {
          capture_method?: "automatic" | "automatic_async" | "manual";
          description?: string;
          metadata?: { [k: string]: string };
          setup_future_usage?: "off_session" | "on_session";
          statement_descriptor?: string;
          statement_descriptor_suffix?: string;
          transfer_group?: string;
          [k: string]: unknown;
        };
        payment_method_collection?: "always" | "if_required";
        payment_method_types?: (
          | "affirm"
          | "afterpay_clearpay"
          | "alipay"
          | "au_becs_debit"
          | "bacs_debit"
          | "bancontact"
          | "blik"
          | "boleto"
          | "card"
          | "cashapp"
          | "eps"
          | "fpx"
          | "giropay"
          | "grabpay"
          | "ideal"
          | "klarna"
          | "konbini"
          | "link"
          | "oxxo"
          | "p24"
          | "paynow"
          | "paypal"
          | "pix"
          | "promptpay"
          | "sepa_debit"
          | "sofort"
          | "swish"
          | "us_bank_account"
          | "wechat_pay"
        )[];
        phone_number_collection?: { enabled: boolean; [k: string]: unknown };
        restrictions?: {
          completed_sessions: { limit: number; [k: string]: unknown };
          [k: string]: unknown;
        };
        shipping_address_collection?: {
          allowed_countries: (
            | "AC"
            | "AD"
            | "AE"
            | "AF"
            | "AG"
            | "AI"
            | "AL"
            | "AM"
            | "AO"
            | "AQ"
            | "AR"
            | "AT"
            | "AU"
            | "AW"
            | "AX"
            | "AZ"
            | "BA"
            | "BB"
            | "BD"
            | "BE"
            | "BF"
            | "BG"
            | "BH"
            | "BI"
            | "BJ"
            | "BL"
            | "BM"
            | "BN"
            | "BO"
            | "BQ"
            | "BR"
            | "BS"
            | "BT"
            | "BV"
            | "BW"
            | "BY"
            | "BZ"
            | "CA"
            | "CD"
            | "CF"
            | "CG"
            | "CH"
            | "CI"
            | "CK"
            | "CL"
            | "CM"
            | "CN"
            | "CO"
            | "CR"
            | "CV"
            | "CW"
            | "CY"
            | "CZ"
            | "DE"
            | "DJ"
            | "DK"
            | "DM"
            | "DO"
            | "DZ"
            | "EC"
            | "EE"
            | "EG"
            | "EH"
            | "ER"
            | "ES"
            | "ET"
            | "FI"
            | "FJ"
            | "FK"
            | "FO"
            | "FR"
            | "GA"
            | "GB"
            | "GD"
            | "GE"
            | "GF"
            | "GG"
            | "GH"
            | "GI"
            | "GL"
            | "GM"
            | "GN"
            | "GP"
            | "GQ"
            | "GR"
            | "GS"
            | "GT"
            | "GU"
            | "GW"
            | "GY"
            | "HK"
            | "HN"
            | "HR"
            | "HT"
            | "HU"
            | "ID"
            | "IE"
            | "IL"
            | "IM"
            | "IN"
            | "IO"
            | "IQ"
            | "IS"
            | "IT"
            | "JE"
            | "JM"
            | "JO"
            | "JP"
            | "KE"
            | "KG"
            | "KH"
            | "KI"
            | "KM"
            | "KN"
            | "KR"
            | "KW"
            | "KY"
            | "KZ"
            | "LA"
            | "LB"
            | "LC"
            | "LI"
            | "LK"
            | "LR"
            | "LS"
            | "LT"
            | "LU"
            | "LV"
            | "LY"
            | "MA"
            | "MC"
            | "MD"
            | "ME"
            | "MF"
            | "MG"
            | "MK"
            | "ML"
            | "MM"
            | "MN"
            | "MO"
            | "MQ"
            | "MR"
            | "MS"
            | "MT"
            | "MU"
            | "MV"
            | "MW"
            | "MX"
            | "MY"
            | "MZ"
            | "NA"
            | "NC"
            | "NE"
            | "NG"
            | "NI"
            | "NL"
            | "NO"
            | "NP"
            | "NR"
            | "NU"
            | "NZ"
            | "OM"
            | "PA"
            | "PE"
            | "PF"
            | "PG"
            | "PH"
            | "PK"
            | "PL"
            | "PM"
            | "PN"
            | "PR"
            | "PS"
            | "PT"
            | "PY"
            | "QA"
            | "RE"
            | "RO"
            | "RS"
            | "RU"
            | "RW"
            | "SA"
            | "SB"
            | "SC"
            | "SE"
            | "SG"
            | "SH"
            | "SI"
            | "SJ"
            | "SK"
            | "SL"
            | "SM"
            | "SN"
            | "SO"
            | "SR"
            | "SS"
            | "ST"
            | "SV"
            | "SX"
            | "SZ"
            | "TA"
            | "TC"
            | "TD"
            | "TF"
            | "TG"
            | "TH"
            | "TJ"
            | "TK"
            | "TL"
            | "TM"
            | "TN"
            | "TO"
            | "TR"
            | "TT"
            | "TV"
            | "TW"
            | "TZ"
            | "UA"
            | "UG"
            | "US"
            | "UY"
            | "UZ"
            | "VA"
            | "VC"
            | "VE"
            | "VG"
            | "VN"
            | "VU"
            | "WF"
            | "WS"
            | "XK"
            | "YE"
            | "YT"
            | "ZA"
            | "ZM"
            | "ZW"
            | "ZZ"
          )[];
          [k: string]: unknown;
        };
        shipping_options?: { shipping_rate?: string; [k: string]: unknown }[];
        submit_type?: "auto" | "book" | "donate" | "pay";
        subscription_data?: {
          description?: string;
          invoice_settings?: {
            issuer?: {
              account?: string;
              type: "account" | "self";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          metadata?: { [k: string]: string };
          trial_period_days?: number;
          trial_settings?: {
            end_behavior: {
              missing_payment_method: "cancel" | "create_invoice" | "pause";
              [k: string]: unknown;
            };
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        tax_id_collection?: { enabled: boolean; [k: string]: unknown };
        transfer_data?: {
          amount?: number;
          destination: string;
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/payment_links`);
    
      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 links
     * <p>Creates a payment link.</p>
     */
    export async function main(
      auth: Stripe,
      body: {
        after_completion?: {
          hosted_confirmation?: { custom_message?: string; [k: string]: unknown };
          redirect?: { url: string; [k: string]: unknown };
          type: "hosted_confirmation" | "redirect";
          [k: string]: unknown;
        };
        allow_promotion_codes?: boolean;
        application_fee_amount?: number;
        application_fee_percent?: number;
        automatic_tax?: { enabled: boolean; [k: string]: unknown };
        billing_address_collection?: "auto" | "required";
        consent_collection?: {
          promotions?: "auto" | "none";
          terms_of_service?: "none" | "required";
          [k: string]: unknown;
        };
        currency?: string;
        custom_fields?: {
          dropdown?: {
            options: { label: string; value: string; [k: string]: unknown }[];
            [k: string]: unknown;
          };
          key: string;
          label: { custom: string; type: "custom"; [k: string]: unknown };
          numeric?: {
            maximum_length?: number;
            minimum_length?: number;
            [k: string]: unknown;
          };
          optional?: boolean;
          text?: {
            maximum_length?: number;
            minimum_length?: number;
            [k: string]: unknown;
          };
          type: "dropdown" | "numeric" | "text";
          [k: string]: unknown;
        }[];
        custom_text?: {
          shipping_address?: { message: string; [k: string]: unknown } | "";
          submit?: { message: string; [k: string]: unknown } | "";
          terms_of_service_acceptance?:
            | { message: string; [k: string]: unknown }
            | "";
          [k: string]: unknown;
        };
        customer_creation?: "always" | "if_required";
        expand?: string[];
        invoice_creation?: {
          enabled: boolean;
          invoice_data?: {
            account_tax_ids?: string[] | "";
            custom_fields?:
              | { name: string; value: string; [k: string]: unknown }[]
              | "";
            description?: string;
            footer?: string;
            metadata?: { [k: string]: string } | "";
            rendering_options?:
              | {
                  amount_tax_display?: "" | "exclude_tax" | "include_inclusive_tax";
                  [k: string]: unknown;
                }
              | "";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        line_items: {
          adjustable_quantity?: {
            enabled: boolean;
            maximum?: number;
            minimum?: number;
            [k: string]: unknown;
          };
          price: string;
          quantity: number;
          [k: string]: unknown;
        }[];
        metadata?: { [k: string]: string };
        on_behalf_of?: string;
        payment_intent_data?: {
          capture_method?: "automatic" | "automatic_async" | "manual";
          metadata?: { [k: string]: string };
          setup_future_usage?: "off_session" | "on_session";
          statement_descriptor?: string;
          statement_descriptor_suffix?: string;
          [k: string]: unknown;
        };
        payment_method_collection?: "always" | "if_required";
        payment_method_types?: (
          | "affirm"
          | "afterpay_clearpay"
          | "alipay"
          | "au_becs_debit"
          | "bacs_debit"
          | "bancontact"
          | "blik"
          | "boleto"
          | "card"
          | "cashapp"
          | "eps"
          | "fpx"
          | "giropay"
          | "grabpay"
          | "ideal"
          | "klarna"
          | "konbini"
          | "link"
          | "oxxo"
          | "p24"
          | "paynow"
          | "paypal"
          | "pix"
          | "promptpay"
          | "sepa_debit"
          | "sofort"
          | "us_bank_account"
          | "wechat_pay"
        )[];
        phone_number_collection?: { enabled: boolean; [k: string]: unknown };
        shipping_address_collection?: {
          allowed_countries: (
            | "AC"
            | "AD"
            | "AE"
            | "AF"
            | "AG"
            | "AI"
            | "AL"
            | "AM"
            | "AO"
            | "AQ"
            | "AR"
            | "AT"
            | "AU"
            | "AW"
            | "AX"
            | "AZ"
            | "BA"
            | "BB"
            | "BD"
            | "BE"
            | "BF"
            | "BG"
            | "BH"
            | "BI"
            | "BJ"
            | "BL"
            | "BM"
            | "BN"
            | "BO"
            | "BQ"
            | "BR"
            | "BS"
            | "BT"
            | "BV"
            | "BW"
            | "BY"
            | "BZ"
            | "CA"
            | "CD"
            | "CF"
            | "CG"
            | "CH"
            | "CI"
            | "CK"
            | "CL"
            | "CM"
            | "CN"
            | "CO"
            | "CR"
            | "CV"
            | "CW"
            | "CY"
            | "CZ"
            | "DE"
            | "DJ"
            | "DK"
            | "DM"
            | "DO"
            | "DZ"
            | "EC"
            | "EE"
            | "EG"
            | "EH"
            | "ER"
            | "ES"
            | "ET"
            | "FI"
            | "FJ"
            | "FK"
            | "FO"
            | "FR"
            | "GA"
            | "GB"
            | "GD"
            | "GE"
            | "GF"
            | "GG"
            | "GH"
            | "GI"
            | "GL"
            | "GM"
            | "GN"
            | "GP"
            | "GQ"
            | "GR"
            | "GS"
            | "GT"
            | "GU"
            | "GW"
            | "GY"
            | "HK"
            | "HN"
            | "HR"
            | "HT"
            | "HU"
            | "ID"
            | "IE"
            | "IL"
            | "IM"
            | "IN"
            | "IO"
            | "IQ"
            | "IS"
            | "IT"
            | "JE"
            | "JM"
            | "JO"
            | "JP"
            | "KE"
            | "KG"
            | "KH"
            | "KI"
            | "KM"
            | "KN"
            | "KR"
            | "KW"
            | "KY"
            | "KZ"
            | "LA"
            | "LB"
            | "LC"
            | "LI"
            | "LK"
            | "LR"
            | "LS"
            | "LT"
            | "LU"
            | "LV"
            | "LY"
            | "MA"
            | "MC"
            | "MD"
            | "ME"
            | "MF"
            | "MG"
            | "MK"
            | "ML"
            | "MM"
            | "MN"
            | "MO"
            | "MQ"
            | "MR"
            | "MS"
            | "MT"
            | "MU"
            | "MV"
            | "MW"
            | "MX"
            | "MY"
            | "MZ"
            | "NA"
            | "NC"
            | "NE"
            | "NG"
            | "NI"
            | "NL"
            | "NO"
            | "NP"
            | "NR"
            | "NU"
            | "NZ"
            | "OM"
            | "PA"
            | "PE"
            | "PF"
            | "PG"
            | "PH"
            | "PK"
            | "PL"
            | "PM"
            | "PN"
            | "PR"
            | "PS"
            | "PT"
            | "PY"
            | "QA"
            | "RE"
            | "RO"
            | "RS"
            | "RU"
            | "RW"
            | "SA"
            | "SB"
            | "SC"
            | "SE"
            | "SG"
            | "SH"
            | "SI"
            | "SJ"
            | "SK"
            | "SL"
            | "SM"
            | "SN"
            | "SO"
            | "SR"
            | "SS"
            | "ST"
            | "SV"
            | "SX"
            | "SZ"
            | "TA"
            | "TC"
            | "TD"
            | "TF"
            | "TG"
            | "TH"
            | "TJ"
            | "TK"
            | "TL"
            | "TM"
            | "TN"
            | "TO"
            | "TR"
            | "TT"
            | "TV"
            | "TW"
            | "TZ"
            | "UA"
            | "UG"
            | "US"
            | "UY"
            | "UZ"
            | "VA"
            | "VC"
            | "VE"
            | "VG"
            | "VN"
            | "VU"
            | "WF"
            | "WS"
            | "XK"
            | "YE"
            | "YT"
            | "ZA"
            | "ZM"
            | "ZW"
            | "ZZ"
          )[];
          [k: string]: unknown;
        };
        shipping_options?: { shipping_rate?: string; [k: string]: unknown }[];
        submit_type?: "auto" | "book" | "donate" | "pay";
        subscription_data?: {
          description?: string;
          metadata?: { [k: string]: string };
          trial_period_days?: number;
          [k: string]: unknown;
        };
        tax_id_collection?: { enabled: boolean; [k: string]: unknown };
        transfer_data?: {
          amount?: number;
          destination: string;
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(`https://api.stripe.com/v1/payment_links`);
    
      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