#kleindesignwebsites
1 messages · Page 1 of 1 (latest)
Hi there! Could you share more details on what exactly is returning the 403 error?
Every request sent through the webhook is getting 403. checkout.session.expired, etc etc etc etc
This is the code I've added to the backend of my site.
import { ok } from 'wix-http-functions';
import stripe from 'stripe';
import express from 'express';
import wixData from 'wix-data';
import bodyParser from 'body-parser';
const key = stripe('sk_****'); // replace with your own secret key from Stripe
const endpointSecret = 'whsec_****'; // replace with your own signing secret key from Stripe
const app = express();
app.use(bodyParser.raw({ type: 'application/json' }));
let responseBody = { // to send back to Stripe
"status": 200,
};
export function post_checkoutUpdate(request) {
console.log('Incoming request:', request); // added log statement
if (!request) {
console.error('Request object is null.');
return ok({ "error": "Request object is null." });
}
const sig = request.headers['stripe-signature'];
let event;
try {
event = key.webhooks.constructEvent(request.body, sig, endpointSecret);
} catch (err) {
console.error(`Webhook Error: ${err.message}`);
return ok({ "error": err.message });
}
if (event.type === 'checkout.session.expired') {
const session = event.data.object;
stripeWebhookHandler(session);
}
return ok(responseBody); // add this line to send the response back to Stripe with a 200 status
}
function stripeWebhookHandler(content) {
let currentItem = {
"webhookData": content
};
wixData.insert("MyCollection", currentItem)
.then((results) => {
let item = results;
responseBody = {
"status": 200,
"body": item
};
})
.catch((err) => {
console.error(`WixData Error: ${err}`);
});
}
app.listen(8000, () => console.log('Running on port 8000'));
I'm not familiar with wixData but can try to take a look. Could you share your account ID? It should look like acct_...
acct_1DGII8Gzl8UaRHvz
hm, I see there are three live mode endpoints receiving checkout.session.expired events. two of the endpoints are returning 403, while one is successfully responding with a 200
the one that's responding successfully is the one that includes wixapps in the domain
Do you have different webhook handler code for the non-wix endpoints?
What was being used previously was woocommerce subscriptions plugin.
@azure bolt please delete or edit the above to remove your live secret key. Since this is a sensitive value, I also highly recommend rolling your API key since this is a public channel
Sorry, wrong one. Will do.
import { ok } from 'wix-http-functions';
import stripe from 'stripe';
import express from 'express';
import bodyParser from 'body-parser';
const key = stripe('sk_****'); // replace with your own secret key from Stripe
const endpointSecret = 'whsec_****'; // replace with your own signing secret key from Stripe
const app = express();
app.use(bodyParser.raw({ type: 'application/json' }));
let responseBody = { // to send back to Stripe
"status": 200,
};
export function post_checkoutUpdate(request) {
console.log('Incoming request:', request); // added log statement
if (!request) {
console.error('Request object is null.');
return ok({ "error": "Request object is null." });
}
const sig = request.headers['stripe-signature'];
let event;
try {
event = key.webhooks.constructEvent(request.body, sig, endpointSecret);
} catch (err) {
console.error(`Webhook Error: ${err.message}`);
return ok({ "error": err.message });
}
if (event.type === 'checkout.session.expired') {
const session = event.data.object;
stripeWebhookHandler(session);
}
return ok(responseBody); // add this line to send the response back to Stripe with a 200 status
}
function stripeWebhookHandler(content) {
let currentItem = {
"webhookData": content
};
return ok(responseBody);
}
app.listen(8000, () => console.log('Running on port 8000'));
So what do I do?
@mental snow ?
Hi, stepping in and catching up here
Thank you. @flat galleon
The error response returned from the server is 403 Forbidden. You would need debug this on your end as your server is returning this. There is not much I can here to help debug I'm afraid.
So you're saying that the code should work but the server is blocking it?
From the error code that is correct