Edits history of script submission #2718 for ' Post customers customer subscriptions subscription exposed id (stripe)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Stripe = {
      token: string;
    };
    /**
     * Post customers customer subscriptions subscription exposed id
     * Updates an existing subscription on a customer to match the specified parameters. When changing plans or quantities, we will optionally prorate the price we charge next month to make up for any price changes. To preview how the proration will be calculated, use the upcoming invoice endpoint.
     */
    export async function main(
      auth: Stripe,
      customer: string,
      subscription_exposed_id: string,
      body: {
        add_invoice_items?: {
          price?: string;
          price_data?: {
            currency: string;
            product: string;
            tax_behavior?: "exclusive" | "inclusive" | "unspecified";
            unit_amount?: number;
            unit_amount_decimal?: string;
            [k: string]: unknown;
          };
          quantity?: number;
          tax_rates?: string[] | "";
          [k: string]: unknown;
        }[];
        application_fee_percent?: number;
        automatic_tax?: {
          enabled: boolean;
          liability?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        billing_cycle_anchor?: "now" | "unchanged";
        billing_thresholds?:
          | {
              amount_gte?: number;
              reset_billing_cycle_anchor?: boolean;
              [k: string]: unknown;
            }
          | "";
        cancel_at?: number | "";
        cancel_at_period_end?: boolean;
        cancellation_details?: {
          comment?: string | "";
          feedback?:
            | ""
            | "customer_service"
            | "low_quality"
            | "missing_features"
            | "other"
            | "switched_service"
            | "too_complex"
            | "too_expensive"
            | "unused";
          [k: string]: unknown;
        };
        collection_method?: "charge_automatically" | "send_invoice";
        coupon?: string;
        days_until_due?: number;
        default_payment_method?: string;
        default_source?: string | "";
        default_tax_rates?: string[] | "";
        expand?: string[];
        invoice_settings?: {
          account_tax_ids?: string[] | "";
          issuer?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        items?: {
          billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
          clear_usage?: boolean;
          deleted?: boolean;
          id?: string;
          metadata?: { [k: string]: string } | "";
          price?: string;
          price_data?: {
            currency: string;
            product: string;
            recurring: {
              interval: "day" | "month" | "week" | "year";
              interval_count?: number;
              [k: string]: unknown;
            };
            tax_behavior?: "exclusive" | "inclusive" | "unspecified";
            unit_amount?: number;
            unit_amount_decimal?: string;
            [k: string]: unknown;
          };
          quantity?: number;
          tax_rates?: string[] | "";
          [k: string]: unknown;
        }[];
        metadata?: { [k: string]: string } | "";
        off_session?: boolean;
        pause_collection?:
          | {
              behavior: "keep_as_draft" | "mark_uncollectible" | "void";
              resumes_at?: number;
              [k: string]: unknown;
            }
          | "";
        payment_behavior?:
          | "allow_incomplete"
          | "default_incomplete"
          | "error_if_incomplete"
          | "pending_if_incomplete";
        payment_settings?: {
          payment_method_options?: {
            acss_debit?:
              | {
                  mandate_options?: {
                    transaction_type?: "business" | "personal";
                    [k: string]: unknown;
                  };
                  verification_method?: "automatic" | "instant" | "microdeposits";
                  [k: string]: unknown;
                }
              | "";
            bancontact?:
              | {
                  preferred_language?: "de" | "en" | "fr" | "nl";
                  [k: string]: unknown;
                }
              | "";
            card?:
              | {
                  mandate_options?: {
                    amount?: number;
                    amount_type?: "fixed" | "maximum";
                    description?: string;
                    [k: string]: unknown;
                  };
                  network?:
                    | "amex"
                    | "cartes_bancaires"
                    | "diners"
                    | "discover"
                    | "eftpos_au"
                    | "interac"
                    | "jcb"
                    | "mastercard"
                    | "unionpay"
                    | "unknown"
                    | "visa";
                  request_three_d_secure?: "any" | "automatic" | "challenge";
                  [k: string]: unknown;
                }
              | "";
            customer_balance?:
              | {
                  bank_transfer?: {
                    eu_bank_transfer?: { country: string; [k: string]: unknown };
                    type?: string;
                    [k: string]: unknown;
                  };
                  funding_type?: string;
                  [k: string]: unknown;
                }
              | "";
            konbini?: { [k: string]: unknown } | "";
            us_bank_account?:
              | {
                  financial_connections?: {
                    permissions?: (
                      | "balances"
                      | "ownership"
                      | "payment_method"
                      | "transactions"
                    )[];
                    prefetch?: ("balances" | "transactions")[];
                    [k: string]: unknown;
                  };
                  verification_method?: "automatic" | "instant" | "microdeposits";
                  [k: string]: unknown;
                }
              | "";
            [k: string]: unknown;
          };
          payment_method_types?:
            | (
                | "ach_credit_transfer"
                | "ach_debit"
                | "acss_debit"
                | "au_becs_debit"
                | "bacs_debit"
                | "bancontact"
                | "boleto"
                | "card"
                | "cashapp"
                | "customer_balance"
                | "eps"
                | "fpx"
                | "giropay"
                | "grabpay"
                | "ideal"
                | "konbini"
                | "link"
                | "p24"
                | "paynow"
                | "paypal"
                | "promptpay"
                | "sepa_debit"
                | "sofort"
                | "us_bank_account"
                | "wechat_pay"
              )[]
            | "";
          save_default_payment_method?: "off" | "on_subscription";
          [k: string]: unknown;
        };
        pending_invoice_item_interval?:
          | {
              interval: "day" | "month" | "week" | "year";
              interval_count?: number;
              [k: string]: unknown;
            }
          | "";
        promotion_code?: string;
        proration_behavior?: "always_invoice" | "create_prorations" | "none";
        proration_date?: number;
        transfer_data?:
          | { amount_percent?: number; destination: string; [k: string]: unknown }
          | "";
        trial_end?: "now" | number;
        trial_from_plan?: boolean;
        trial_settings?: {
          end_behavior: {
            missing_payment_method: "cancel" | "create_invoice" | "pause";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/customers/${customer}/subscriptions/${subscription_exposed_id}`
      );
    
      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 customers customer subscriptions subscription exposed id
     * Updates an existing subscription on a customer to match the specified parameters. When changing plans or quantities, we will optionally prorate the price we charge next month to make up for any price changes. To preview how the proration will be calculated, use the upcoming invoice endpoint.
     */
    export async function main(
      auth: Stripe,
      customer: string,
      subscription_exposed_id: string,
      body: {
        add_invoice_items?: {
          price?: string;
          price_data?: {
            currency: string;
            product: string;
            tax_behavior?: "exclusive" | "inclusive" | "unspecified";
            unit_amount?: number;
            unit_amount_decimal?: string;
            [k: string]: unknown;
          };
          quantity?: number;
          tax_rates?: string[] | "";
          [k: string]: unknown;
        }[];
        application_fee_percent?: number;
        automatic_tax?: {
          enabled: boolean;
          liability?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        billing_cycle_anchor?: "now" | "unchanged";
        billing_thresholds?:
          | {
              amount_gte?: number;
              reset_billing_cycle_anchor?: boolean;
              [k: string]: unknown;
            }
          | "";
        cancel_at?: number | "";
        cancel_at_period_end?: boolean;
        cancellation_details?: {
          comment?: string | "";
          feedback?:
            | ""
            | "customer_service"
            | "low_quality"
            | "missing_features"
            | "other"
            | "switched_service"
            | "too_complex"
            | "too_expensive"
            | "unused";
          [k: string]: unknown;
        };
        collection_method?: "charge_automatically" | "send_invoice";
        coupon?: string;
        days_until_due?: number;
        default_payment_method?: string;
        default_source?: string | "";
        default_tax_rates?: string[] | "";
        expand?: string[];
        invoice_settings?: {
          account_tax_ids?: string[] | "";
          issuer?: {
            account?: string;
            type: "account" | "self";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
        items?: {
          billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
          clear_usage?: boolean;
          deleted?: boolean;
          id?: string;
          metadata?: { [k: string]: string } | "";
          price?: string;
          price_data?: {
            currency: string;
            product: string;
            recurring: {
              interval: "day" | "month" | "week" | "year";
              interval_count?: number;
              [k: string]: unknown;
            };
            tax_behavior?: "exclusive" | "inclusive" | "unspecified";
            unit_amount?: number;
            unit_amount_decimal?: string;
            [k: string]: unknown;
          };
          quantity?: number;
          tax_rates?: string[] | "";
          [k: string]: unknown;
        }[];
        metadata?: { [k: string]: string } | "";
        off_session?: boolean;
        pause_collection?:
          | {
              behavior: "keep_as_draft" | "mark_uncollectible" | "void";
              resumes_at?: number;
              [k: string]: unknown;
            }
          | "";
        payment_behavior?:
          | "allow_incomplete"
          | "default_incomplete"
          | "error_if_incomplete"
          | "pending_if_incomplete";
        payment_settings?: {
          payment_method_options?: {
            acss_debit?:
              | {
                  mandate_options?: {
                    transaction_type?: "business" | "personal";
                    [k: string]: unknown;
                  };
                  verification_method?: "automatic" | "instant" | "microdeposits";
                  [k: string]: unknown;
                }
              | "";
            bancontact?:
              | {
                  preferred_language?: "de" | "en" | "fr" | "nl";
                  [k: string]: unknown;
                }
              | "";
            card?:
              | {
                  mandate_options?: {
                    amount?: number;
                    amount_type?: "fixed" | "maximum";
                    description?: string;
                    [k: string]: unknown;
                  };
                  network?:
                    | "amex"
                    | "cartes_bancaires"
                    | "diners"
                    | "discover"
                    | "eftpos_au"
                    | "interac"
                    | "jcb"
                    | "mastercard"
                    | "unionpay"
                    | "unknown"
                    | "visa";
                  request_three_d_secure?: "any" | "automatic" | "challenge";
                  [k: string]: unknown;
                }
              | "";
            customer_balance?:
              | {
                  bank_transfer?: {
                    eu_bank_transfer?: { country: string; [k: string]: unknown };
                    type?: string;
                    [k: string]: unknown;
                  };
                  funding_type?: string;
                  [k: string]: unknown;
                }
              | "";
            konbini?: { [k: string]: unknown } | "";
            us_bank_account?:
              | {
                  financial_connections?: {
                    permissions?: (
                      | "balances"
                      | "ownership"
                      | "payment_method"
                      | "transactions"
                    )[];
                    prefetch?: ("balances" | "transactions")[];
                    [k: string]: unknown;
                  };
                  verification_method?: "automatic" | "instant" | "microdeposits";
                  [k: string]: unknown;
                }
              | "";
            [k: string]: unknown;
          };
          payment_method_types?:
            | (
                | "ach_credit_transfer"
                | "ach_debit"
                | "acss_debit"
                | "au_becs_debit"
                | "bacs_debit"
                | "bancontact"
                | "boleto"
                | "card"
                | "cashapp"
                | "customer_balance"
                | "eps"
                | "fpx"
                | "giropay"
                | "grabpay"
                | "ideal"
                | "konbini"
                | "link"
                | "p24"
                | "paynow"
                | "paypal"
                | "promptpay"
                | "sepa_debit"
                | "sofort"
                | "us_bank_account"
                | "wechat_pay"
              )[]
            | "";
          save_default_payment_method?: "off" | "on_subscription";
          [k: string]: unknown;
        };
        pending_invoice_item_interval?:
          | {
              interval: "day" | "month" | "week" | "year";
              interval_count?: number;
              [k: string]: unknown;
            }
          | "";
        promotion_code?: string;
        proration_behavior?: "always_invoice" | "create_prorations" | "none";
        proration_date?: number;
        transfer_data?:
          | { amount_percent?: number; destination: string; [k: string]: unknown }
          | "";
        trial_end?: "now" | number;
        trial_from_plan?: boolean;
        trial_settings?: {
          end_behavior: {
            missing_payment_method: "cancel" | "create_invoice" | "pause";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/customers/${customer}/subscriptions/${subscription_exposed_id}`
      );
    
      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 customers customer subscriptions subscription exposed id
     * <p>Updates an existing subscription on a customer to match the specified parameters. When changing plans or quantities, we will optionally prorate the price we charge next month to make up for any price changes. To preview how the proration will be calculated, use the <a href="#upcoming_invoice">upcoming invoice</a> endpoint.</p>
     */
    export async function main(
      auth: Stripe,
      customer: string,
      subscription_exposed_id: string,
      body: {
        add_invoice_items?: {
          price?: string;
          price_data?: {
            currency: string;
            product: string;
            tax_behavior?: "exclusive" | "inclusive" | "unspecified";
            unit_amount?: number;
            unit_amount_decimal?: string;
            [k: string]: unknown;
          };
          quantity?: number;
          tax_rates?: string[] | "";
          [k: string]: unknown;
        }[];
        application_fee_percent?: number;
        automatic_tax?: { enabled: boolean; [k: string]: unknown };
        billing_cycle_anchor?: "now" | "unchanged";
        billing_thresholds?:
          | {
              amount_gte?: number;
              reset_billing_cycle_anchor?: boolean;
              [k: string]: unknown;
            }
          | "";
        cancel_at?: number | "";
        cancel_at_period_end?: boolean;
        cancellation_details?: {
          comment?: string | "";
          feedback?:
            | ""
            | "customer_service"
            | "low_quality"
            | "missing_features"
            | "other"
            | "switched_service"
            | "too_complex"
            | "too_expensive"
            | "unused";
          [k: string]: unknown;
        };
        collection_method?: "charge_automatically" | "send_invoice";
        coupon?: string;
        days_until_due?: number;
        default_payment_method?: string;
        default_source?: string | "";
        default_tax_rates?: string[] | "";
        expand?: string[];
        items?: {
          billing_thresholds?: { usage_gte: number; [k: string]: unknown } | "";
          clear_usage?: boolean;
          deleted?: boolean;
          id?: string;
          metadata?: { [k: string]: string } | "";
          price?: string;
          price_data?: {
            currency: string;
            product: string;
            recurring: {
              interval: "day" | "month" | "week" | "year";
              interval_count?: number;
              [k: string]: unknown;
            };
            tax_behavior?: "exclusive" | "inclusive" | "unspecified";
            unit_amount?: number;
            unit_amount_decimal?: string;
            [k: string]: unknown;
          };
          quantity?: number;
          tax_rates?: string[] | "";
          [k: string]: unknown;
        }[];
        metadata?: { [k: string]: string } | "";
        off_session?: boolean;
        pause_collection?:
          | {
              behavior: "keep_as_draft" | "mark_uncollectible" | "void";
              resumes_at?: number;
              [k: string]: unknown;
            }
          | "";
        payment_behavior?:
          | "allow_incomplete"
          | "default_incomplete"
          | "error_if_incomplete"
          | "pending_if_incomplete";
        payment_settings?: {
          payment_method_options?: {
            acss_debit?:
              | {
                  mandate_options?: {
                    transaction_type?: "business" | "personal";
                    [k: string]: unknown;
                  };
                  verification_method?: "automatic" | "instant" | "microdeposits";
                  [k: string]: unknown;
                }
              | "";
            bancontact?:
              | {
                  preferred_language?: "de" | "en" | "fr" | "nl";
                  [k: string]: unknown;
                }
              | "";
            card?:
              | {
                  mandate_options?: {
                    amount?: number;
                    amount_type?: "fixed" | "maximum";
                    description?: string;
                    [k: string]: unknown;
                  };
                  network?:
                    | "amex"
                    | "cartes_bancaires"
                    | "diners"
                    | "discover"
                    | "eftpos_au"
                    | "interac"
                    | "jcb"
                    | "mastercard"
                    | "unionpay"
                    | "unknown"
                    | "visa";
                  request_three_d_secure?: "any" | "automatic";
                  [k: string]: unknown;
                }
              | "";
            customer_balance?:
              | {
                  bank_transfer?: {
                    eu_bank_transfer?: { country: string; [k: string]: unknown };
                    type?: string;
                    [k: string]: unknown;
                  };
                  funding_type?: string;
                  [k: string]: unknown;
                }
              | "";
            konbini?: { [k: string]: unknown } | "";
            us_bank_account?:
              | {
                  financial_connections?: {
                    permissions?: (
                      | "balances"
                      | "ownership"
                      | "payment_method"
                      | "transactions"
                    )[];
                    prefetch?: "balances"[];
                    [k: string]: unknown;
                  };
                  verification_method?: "automatic" | "instant" | "microdeposits";
                  [k: string]: unknown;
                }
              | "";
            [k: string]: unknown;
          };
          payment_method_types?:
            | (
                | "ach_credit_transfer"
                | "ach_debit"
                | "acss_debit"
                | "au_becs_debit"
                | "bacs_debit"
                | "bancontact"
                | "boleto"
                | "card"
                | "cashapp"
                | "customer_balance"
                | "fpx"
                | "giropay"
                | "grabpay"
                | "ideal"
                | "konbini"
                | "link"
                | "paynow"
                | "paypal"
                | "promptpay"
                | "sepa_debit"
                | "sofort"
                | "us_bank_account"
                | "wechat_pay"
              )[]
            | "";
          save_default_payment_method?: "off" | "on_subscription";
          [k: string]: unknown;
        };
        pending_invoice_item_interval?:
          | {
              interval: "day" | "month" | "week" | "year";
              interval_count?: number;
              [k: string]: unknown;
            }
          | "";
        promotion_code?: string;
        proration_behavior?: "always_invoice" | "create_prorations" | "none";
        proration_date?: number;
        transfer_data?:
          | { amount_percent?: number; destination: string; [k: string]: unknown }
          | "";
        trial_end?: "now" | number;
        trial_from_plan?: boolean;
        trial_settings?: {
          end_behavior: {
            missing_payment_method: "cancel" | "create_invoice" | "pause";
            [k: string]: unknown;
          };
          [k: string]: unknown;
        };
      }
    ) {
      const url = new URL(
        `https://api.stripe.com/v1/customers/${customer}/subscriptions/${subscription_exposed_id}`
      );
    
      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