#strike_dev_
1 messages · Page 1 of 1 (latest)
hello! Generally 404 response status code indicates that the server cannot find the requested resource., are you sure the endpoint/route in your code is setup correctly?
Yes, I'm pretty sure. But when I go to that route on browser I just get this message{"message":"Unexpected Server Error"}
Can I share the webghook file's code with you?
you can paste the code here
It doesnt fir in one message just so know.
onst badStatuses = ["incomplete", "incomplete_expired", "canceled"];
export const action = async ({ request }: ActionArgs) => {
const sig = request.headers.get("stripe-signature") as string;
let event;
const payload = await request.text();
try {
event = stripe.webhooks.constructEvent(payload, sig, stripeSigningSecret);
} catch (err) {
return new Response("Invalid server error", {
status: 400,
});
}
let user;
switch (event.type) {
case "customer.subscription.updated":
case "customer.subscription.created":
let updated: any = event.data.object;
let previousStatus = updated?.previous_attributes?.status;
let currentStatus = updated?.status;
if (
badStatuses.includes(previousStatus) ||
badStatuses.includes(currentStatus)
) {
return json({
subscriptionChanged: false,
error: "Incomplete payment.",
});
}
user = await User.getUserByCustomerId(updated.customer);
const update = {
subscription_id: updated.id,
subscription_price: updated.plan.amount / 100,
subscription_will_renew: !updated.cancel_at_period_end,
};
await User.updateUserById(user.id, update);
return json({
subscriptionChanged: true,
});```
case "customer.subscription.deleted":
let deleted: any = event.data.object;
user = await User.getUserByCustomerId(deleted.customer);
await User.updateUserById(user.id, {
subscription_id: null,
subscription_price: 0,
subscription_will_renew: null,
});
return json({
subscriptionChanged: true,
});
default:
console.log(`Unhandled event type ${event.type}`);
break;
}
return json({
subscriptionChanged: false,
});
};
where are you defining the route?
Since I'm using the remix framework this file is in the routes folder and it's name is api.webhooks.stripe.tsx so I can access it by https://random/api/webhooks/stripe