Edits history of script submission #20848 for ' VoidTransaction (square)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Square = {
      token: string;
    };
    /**
     * VoidTransaction
     * Cancels a transaction that was created with the [Charge](api-endpoint:Transactions-Charge)
    endpoint with a `delay_capture` value of `true`.
    
    
    See [Delayed capture transactions](https://developer.squareup.com/docs/payments/transactions/overview#delayed-capture)
    for more information.
     */
    export async function main(
      auth: Square,
      location_id: string,
      transaction_id: string,
    ) {
      const url = new URL(
        `https://connect.squareup.com/v2/locations/${location_id}/transactions/${transaction_id}/void`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago