Edits history of script submission #21996 for ' Update a payment (zoho)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Zoho = {
      token: string;
    };
    /**
     * Update a payment
     * Update an existing payment information.
     */
    export async function main(
      auth: Zoho,
      payment_id: string,
      organization_id: string | undefined,
      body: {
        customer_id: string;
        payment_mode: string;
        amount: number;
        date?: string;
        reference_number?: string;
        description?: string;
        invoices: {
          invoice_id: string;
          amount_applied: number;
          tax_amount_withheld?: number;
        }[];
        exchange_rate?: number;
        payment_form?: string;
        bank_charges?: number;
        account_id?: string;
        tax_account_id?: string;
        location_id?: string;
        custom_fields?: { label?: string; value?: string }[];
      },
    ) {
      const url = new URL(
        `https://www.zohoapis.com/inventory/v1/customerpayments/${payment_id}`,
      );
      for (const [k, v] of [["organization_id", organization_id]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Zoho-oauthtoken " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago