Discussions

Ask a Question
Back to All

Event is not getting triggered after placing an order?

I have integrated the event in Nodejs as per the documentation(channel 3) . I want to save the payload response received after placing any order successfully. But i am getting payload as empty . Looks like event is not getting triggered . after some interval i getting response as pong message with empty payload.

Below i am sharing the code for reference. Please let me know if i have made any mistake while integration.

require("dotenv").config();
const axios = require("axios");
const Pusher = require('pusher-js');
const jwt = require('jsonwebtoken');
const express = require("express");

const app = express();
app.use(express.json());

let pusher = new Pusher('1d9ffac87de599c61283', {cluster: 'ap2', params:{apiKey: process.env.TRANSAK_API_KEY}});
// console.log("new pusher data", pusher.timeline.events);
let apiKey = process.env.TRANSAK_API_KEY;
let partnerApiSecret = process.env.TRANSAK_API_SECRET;
let channel = pusher.subscribe(apiKey);
// console.log("channel----------------",channel.pusher);

let callback = function (encryptedOrderData) {
console.log(pushed data,encryptedOrderData);
if (encryptedOrderData && typeof encryptedOrderData === 'string') {
try {
let decryptedOrderData = jwt.verify(encryptedOrderData, partnerApiSecret);
if (decryptedOrderData && decryptedOrderData.id) {
console.log({orderData: decryptedOrderData})
}
} catch (e) {
console.error(e)
}
}
};

//receive updates of a specific order
let user_order_id = "df93d768-2231-4261-9e31-91f0ceb80356";
channel.bind(user_order_id, (encryptedOrderData) => {
console.log("processing");
return callback(encryptedOrderData)
});
//receive updates of all the orders
channel.bind_global((orderId, encryptedOrderData) => {
console.log(Order update ${orderId});
return callback(encryptedOrderData)
});

pusher.bind_global((orderId, encryptedOrderData) => {
console.log(Order update ${orderId});
return callback(encryptedOrderData)
});

ο»Ώ