Refund Order
One script reply has been approved by the moderators Verified

This API will reverse a Stripe charge and refund an order back to a customer. It will also set the order's status to refunded.

Required scope | ecommerce:write

Created by hugo697 514 days ago
Submitted by hugo697 Bun
Verified 514 days ago
1
//native
2
type Webflow = {
3
	token: string
4
}
5

6
export async function main(
7
	auth: Webflow,
8
	site_id: string,
9
	order_id: string,
10
	body: { reason?: 'duplicate' | 'fraudulent' | 'requested' }
11
) {
12
	const url = new URL(`https://api.webflow.com/v2/sites/${site_id}/orders/${order_id}/refund`)
13

14
	const response = await fetch(url, {
15
		method: 'POST',
16
		headers: {
17
			'Content-Type': 'application/json',
18
			Authorization: 'Bearer ' + auth.token
19
		},
20
		body: JSON.stringify(body)
21
	})
22

23
	if (!response.ok) {
24
		const text = await response.text()
25
		throw new Error(`${response.status} ${text}`)
26
	}
27

28
	return await response.json()
29
}
30