refactor(members): use helcim helper + fix wrong card-lookup URL
This commit is contained in:
parent
03d6a66b84
commit
0d792c7c70
2 changed files with 33 additions and 155 deletions
|
|
@ -1,12 +1,10 @@
|
|||
// Cancel member subscription
|
||||
import Member from "../../models/member.js";
|
||||
|
||||
const HELCIM_API_BASE = "https://api.helcim.com/v2";
|
||||
import { cancelHelcimSubscription } from "../../utils/helcim.js";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const member = await requireAuth(event);
|
||||
const config = useRuntimeConfig(event);
|
||||
|
||||
// If already on free tier, nothing to cancel
|
||||
if (member.contributionTier === "0" || !member.helcimSubscriptionId) {
|
||||
|
|
@ -18,32 +16,10 @@ export default defineEventHandler(async (event) => {
|
|||
};
|
||||
}
|
||||
|
||||
const helcimToken = config.helcimApiToken;
|
||||
|
||||
try {
|
||||
// Cancel Helcim subscription
|
||||
const response = await fetch(
|
||||
`${HELCIM_API_BASE}/subscriptions/${member.helcimSubscriptionId}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
accept: "application/json",
|
||||
"api-token": helcimToken,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error(
|
||||
"Failed to cancel Helcim subscription:",
|
||||
response.status,
|
||||
errorText,
|
||||
);
|
||||
// Continue anyway - we'll update the member record
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error canceling Helcim subscription:", error);
|
||||
await cancelHelcimSubscription(member.helcimSubscriptionId);
|
||||
} catch (cancelError) {
|
||||
console.error("Error canceling Helcim subscription:", cancelError);
|
||||
// Continue anyway - we'll update the member record
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue