Mbonea Claude Sonnet 4.6 commited on
Commit
caa7c5b
·
1 Parent(s): e7ade78

fix double protocol in webhook URL construction

Browse files

PORTAL_HOST was set with protocol already included, causing URLs like
https://https//... Strip any existing protocol from PORTAL_HOST before
constructing webhookBase. Fixed in portal, devices, and payouts routes.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

src/routes/devices.routes.js CHANGED
@@ -560,7 +560,8 @@ router.post("/:id/renew", async (req, res) => {
560
  );
561
 
562
  // Initiate Snippe payment to tenant's phone
563
- const webhookBase = `${process.env.PORTAL_SCHEME || "http"}://${process.env.PORTAL_HOST}`;
 
564
  try {
565
  await snippe.createPayment({
566
  reference,
 
560
  );
561
 
562
  // Initiate Snippe payment to tenant's phone
563
+ const host = (process.env.PORTAL_HOST || '').replace(/^https?:\/\//, '');
564
+ const webhookBase = `${process.env.PORTAL_SCHEME || "http"}://${host}`;
565
  try {
566
  await snippe.createPayment({
567
  reference,
src/routes/payouts.routes.js CHANGED
@@ -66,7 +66,8 @@ router.post('/', async (req, res) => {
66
  );
67
 
68
  const payoutId = result.insertId;
69
- const webhookBase = `${process.env.PORTAL_SCHEME || 'http'}://${process.env.PORTAL_HOST}`;
 
70
 
71
  // Call Snippe disbursement
72
  try {
 
66
  );
67
 
68
  const payoutId = result.insertId;
69
+ const host = (process.env.PORTAL_HOST || '').replace(/^https?:\/\//, '');
70
+ const webhookBase = `${process.env.PORTAL_SCHEME || 'http'}://${host}`;
71
 
72
  // Call Snippe disbursement
73
  try {
src/routes/portal.routes.js CHANGED
@@ -168,7 +168,8 @@ router.post('/:siteId/purchase', purchaseLimiter, async (req, res) => {
168
  [reference, device.client_id, device.id, plan.id, phone, plan.price, device.commission_rate]
169
  );
170
 
171
- const webhookBase = `${process.env.PORTAL_SCHEME || 'http'}://${process.env.PORTAL_HOST}`;
 
172
  try {
173
  await snippe.createPayment({
174
  reference,
 
168
  [reference, device.client_id, device.id, plan.id, phone, plan.price, device.commission_rate]
169
  );
170
 
171
+ const host = (process.env.PORTAL_HOST || '').replace(/^https?:\/\//, '');
172
+ const webhookBase = `${process.env.PORTAL_SCHEME || 'http'}://${host}`;
173
  try {
174
  await snippe.createPayment({
175
  reference,