//native
type Square = {
token: string;
};
/**
* SwapPlan
* Schedules a `SWAP_PLAN` action to swap a subscription plan variation in an existing subscription.
For more information, see [Swap Subscription Plan Variations](https://developer.squareup.com/docs/subscriptions-api/swap-plan-variations).
*/
export async function main(
auth: Square,
subscription_id: string,
body: {
new_plan_variation_id?: string;
phases?: { ordinal: number; order_template_id?: string }[];
},
) {
const url = new URL(
`https://connect.squareup.com/v2/subscriptions/${subscription_id}/swap-plan`,
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + 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