type Shopify = {
token: string;
store_name: string;
};
/**
* Creates a transaction for an order
* Caution For multi-currency orders, the currency property is required when creating refund and capture transactions. The value should be the presentment currency from the order. For more information, see Migrating to support multiple currencies. Creates a transaction for an order.
*/
export async function main(
auth: Shopify,
api_version: string = "2023-10",
order_id: string,
body: {
transaction?: {
amount?: string;
currency?: string;
kind?: string;
parent_id?: number;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/transactions.json`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Shopify-Access-Token": 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 337 days ago
type Shopify = {
token: string;
store_name: string;
};
/**
* Creates a transaction for an order
* Caution For multi-currency orders, the currency property is required when creating refund and capture transactions. The value should be the presentment currency from the order. For more information, see Migrating to support multiple currencies. Creates a transaction for an order.
*/
export async function main(
auth: Shopify,
api_version: string = "2023-10",
order_id: string,
body: {
transaction?: {
amount?: string;
currency?: string;
kind?: string;
parent_id?: number;
[k: string]: unknown;
};
[k: string]: unknown;
}
) {
const url = new URL(
`https://${auth.store_name}.myshopify.com/admin/api/${api_version}/orders/${order_id}/transactions.json`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Shopify-Access-Token": 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 883 days ago