Post issuing disputes dispute

Updates the specified Issuing Dispute object by setting the values of the parameters passed. Any parameters not provided will be left unchanged. Properties on the evidence object can be unset by passing in an empty string.

Script stripe Verified

by hugo697 ยท 10/30/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 368 days ago
1
type Stripe = {
2
  token: string;
3
};
4
/**
5
 * Post issuing disputes dispute
6
 * Updates the specified Issuing Dispute object by setting the values of the parameters passed. Any parameters not provided will be left unchanged. Properties on the evidence object can be unset by passing in an empty string.
7
 */
8
export async function main(
9
  auth: Stripe,
10
  dispute: string,
11
  body: {
12
    amount?: number;
13
    evidence?: {
14
      canceled?:
15
        | {
16
            additional_documentation?: string | "";
17
            canceled_at?: number | "";
18
            cancellation_policy_provided?: boolean | "";
19
            cancellation_reason?: string | "";
20
            expected_at?: number | "";
21
            explanation?: string | "";
22
            product_description?: string | "";
23
            product_type?: "" | "merchandise" | "service";
24
            return_status?: "" | "merchant_rejected" | "successful";
25
            returned_at?: number | "";
26
            [k: string]: unknown;
27
          }
28
        | "";
29
      duplicate?:
30
        | {
31
            additional_documentation?: string | "";
32
            card_statement?: string | "";
33
            cash_receipt?: string | "";
34
            check_image?: string | "";
35
            explanation?: string | "";
36
            original_transaction?: string;
37
            [k: string]: unknown;
38
          }
39
        | "";
40
      fraudulent?:
41
        | {
42
            additional_documentation?: string | "";
43
            explanation?: string | "";
44
            [k: string]: unknown;
45
          }
46
        | "";
47
      merchandise_not_as_described?:
48
        | {
49
            additional_documentation?: string | "";
50
            explanation?: string | "";
51
            received_at?: number | "";
52
            return_description?: string | "";
53
            return_status?: "" | "merchant_rejected" | "successful";
54
            returned_at?: number | "";
55
            [k: string]: unknown;
56
          }
57
        | "";
58
      not_received?:
59
        | {
60
            additional_documentation?: string | "";
61
            expected_at?: number | "";
62
            explanation?: string | "";
63
            product_description?: string | "";
64
            product_type?: "" | "merchandise" | "service";
65
            [k: string]: unknown;
66
          }
67
        | "";
68
      other?:
69
        | {
70
            additional_documentation?: string | "";
71
            explanation?: string | "";
72
            product_description?: string | "";
73
            product_type?: "" | "merchandise" | "service";
74
            [k: string]: unknown;
75
          }
76
        | "";
77
      reason?:
78
        | "canceled"
79
        | "duplicate"
80
        | "fraudulent"
81
        | "merchandise_not_as_described"
82
        | "not_received"
83
        | "other"
84
        | "service_not_as_described";
85
      service_not_as_described?:
86
        | {
87
            additional_documentation?: string | "";
88
            canceled_at?: number | "";
89
            cancellation_reason?: string | "";
90
            explanation?: string | "";
91
            received_at?: number | "";
92
            [k: string]: unknown;
93
          }
94
        | "";
95
      [k: string]: unknown;
96
    };
97
    expand?: string[];
98
    metadata?: { [k: string]: string } | "";
99
  }
100
) {
101
  const url = new URL(`https://api.stripe.com/v1/issuing/disputes/${dispute}`);
102

103
  const response = await fetch(url, {
104
    method: "POST",
105
    headers: {
106
      "Content-Type": "application/x-www-form-urlencoded",
107
      Authorization: "Bearer " + auth.token,
108
    },
109
    body: encodeParams(body),
110
  });
111
  if (!response.ok) {
112
    const text = await response.text();
113
    throw new Error(`${response.status} ${text}`);
114
  }
115
  return await response.json();
116
}
117

118
function encodeParams(o: any) {
119
  function iter(o: any, path: string) {
120
    if (Array.isArray(o)) {
121
      o.forEach(function (a) {
122
        iter(a, path + "[]");
123
      });
124
      return;
125
    }
126
    if (o !== null && typeof o === "object") {
127
      Object.keys(o).forEach(function (k) {
128
        iter(o[k], path + "[" + k + "]");
129
      });
130
      return;
131
    }
132
    data.push(path + "=" + o);
133
  }
134
  const data: string[] = [];
135
  Object.keys(o).forEach(function (k) {
136
    if (o[k] !== undefined) {
137
      iter(o[k], k);
138
    }
139
  });
140
  return new URLSearchParams(data.join("&"));
141
}
142