WebSocket Integrations

React / React Native

The snippet below connects to channels and subscribes to a channel.

Installation

// For react-native
npm install pusher-js @react-native-community/netinfo

// For react
npm install pusher-js

Examples

import Pusher from 'pusher-js/react-native';
let pusher = new Pusher('1d9ffac87de599c61283', {cluster: 'ap2'});
let orderId = "TRANSAK_ORDER_ID"

//to subscribe
let channel = pusher.subscribe(orderId);

//receive updates of all the events
pusher.bind_global((eventId, orderData) => {
    console.log(`${eventId} ${orderData}`)
});

//receive updates of a specific event
// channel.bind(`ORDER_COMPLETED`, (orderData) => {
//     console.log(orderData)
// });

//to unsubscribe
//pusher.unsubscribe(orderId);

// sample order data

{ status: 'COMPLETED',
  id: '7467f962-0842-4095-ac9e-1689da6e1414',
  walletAddress: '0x3CAdbeB58CB5162439908edA08df0A305b016dA8',
  fiatCurrency: 'EUR',
  fiatAmount: 100,
  cryptoAmount: 0.4581929390176435,
  cryptocurrency: 'ETH',
  isBuyOrSell: 'BUY',
  transactionLink:
   'https://rinkeby.etherscan.io/tx/0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3',
  transactionHash:
   '0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3' 
}
import Pusher from 'pusher-js/react-native';
let pusher = new Pusher('1d9ffac87de599c61283', {cluster: 'ap2'});
let apiKey = "YOUR_TRANSAK_API_KEY"
let partnerOrderId = "YOUR_UNIQUE_ORDER_ID"
let channelName = `${apiKey}_${partnerOrderId}`

//to subscribe
let channel = pusher.subscribe(channelName);

//receive updates of all the events
pusher.bind_global((eventId, orderData) => {
    console.log(`${eventId} ${orderData}`)
});

//receive updates of a specific event
// channel.bind(`ORDER_COMPLETED`, (orderData) => {
//     console.log(orderData)
// });

//to unsubscribe
//pusher.unsubscribe(orderId);

// sample order data

{ status: 'COMPLETED',
  id: '7467f962-0842-4095-ac9e-1689da6e1414',
  walletAddress: '0x3CAdbeB58CB5162439908edA08df0A305b016dA8',
  fiatCurrency: 'EUR',
  fiatAmount: 100,
  cryptoAmount: 0.4581929390176435,
  cryptocurrency: 'ETH',
  isBuyOrSell: 'BUY',
  transactionLink:
   'https://rinkeby.etherscan.io/tx/0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3',
  transactionHash:
   '0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3' 
}
import Pusher from 'pusher-js/react-native'; // For React Native
import jwt from 'jsonwebtoken';

// Initialize Pusher with your app credentials
const pusherApiKey = '1d9ffac87de599c61283';
const pusherCluster = 'ap2';
const pusher = new Pusher(pusherApiKey, { cluster: pusherCluster });

// Define your API key and subscribe to the Pusher channel
const apiKey = 'YOUR_API_KEY';  // Replace with your actual API key
const channel = pusher.subscribe(apiKey);

// Callback function to handle incoming encrypted order data
const handleEncryptedOrderData = (encryptedOrderData) => {
    if (typeof encryptedOrderData === 'string') {
        try {
            // Consider moving this decryption logic to the backend and call it via API,
            // as it contains your access token, which should not be exposed in the client.
            const partnerAccessToken = "YOUR_ACCESS_TOKEN";  // Replace with your actual access token
            const decryptedOrderData = jwt.verify(encryptedOrderData, partnerAccessToken);

            if (decryptedOrderData && decryptedOrderData.id) {
                console.log({ orderData: decryptedOrderData });
            }
        } catch (error) {
            console.error(error);
        }
    }
};

// Subscribe to receive updates for a specific order ID
const orderId = 'YOUR_ORDER_ID';  // Replace with the actual order ID
channel.bind(orderId, (encryptedOrderData) => {
    console.log("Encrypted Order Data", encryptedOrderData);
    handleEncryptedOrderData(encryptedOrderData);
});

// To unsubscribe (if needed)
// channel.unsubscribe(apiKey);



// Sample Decrypted Payload Data

{ 
      "id":"9151faa1-e69b-4a36-b959-3c4f894afb68",
      "walletAddress":"0x86349020e9394b2BE1b1262531B0C3335fc32F20",
      "createdAt":"2020-02-17T01:55:05.095Z",
      "status":"AWAITING_PAYMENT_FROM_USER",
      "fiatCurrency":"INR",
      "userId":"65317131-cd95-419a-a50c-747d142f83e9",
      "cryptocurrency":"CDAI",
      "isBuyOrSell":"BUY",
      "fiatAmount":1110,
      "commissionDecimal":0.0075,
      "fromWalletAddress":"0x085ee67132ec4297b85ed5d1b4c65424d36fda7d",
      "walletLink":"https://rinkeby.etherscan.io/address/0x86349020e9394b2BE1b1262531B0C3335fc32F20#tokentxns",
      "amountPaid":0,
      "partnerOrderId":"2183721893",
      "partnerCustomerId":"2183721893",
      "redirectURL":"https://google.com",
      "conversionPrice":0.663847164368606,
      "cryptoAmount":731.34,
      "totalFee":5.52652764336864,
      "paymentOption":[],
      "autoExpiresAt":"2020-02-16T19:55:05-07:00",
      "referenceCode":226056
}

Node JS

The snippet below connects to channels and subscribes to a channel.

Installation

npm install pusher-js

Examples

const Pusher = require('pusher-js');
let pusher = new Pusher('1d9ffac87de599c61283', {cluster: 'ap2'});
let orderId = "TRANSAK_ORDER_ID"

//to subscribe
let channel = pusher.subscribe(orderId);

//receive updates of all the events
pusher.bind_global((eventId, orderData) => {
    console.log(`${eventId} ${orderData}`)
});

//receive updates of a specific event
// channel.bind(`ORDER_COMPLETED`, (orderData) => {
//     console.log(orderData)
// });

//to unsubscribe
//pusher.unsubscribe(orderId);

// sample order data

{ status: 'COMPLETED',
  id: '7467f962-0842-4095-ac9e-1689da6e1414',
  walletAddress: '0x3CAdbeB58CB5162439908edA08df0A305b016dA8',
  fiatCurrency: 'EUR',
  fiatAmount: 100,
  cryptoAmount: 0.4581929390176435,
  cryptocurrency: 'ETH',
  isBuyOrSell: 'BUY',
  transactionLink:
   'https://rinkeby.etherscan.io/tx/0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3',
  transactionHash:
   '0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3' 
}
const Pusher = require('pusher-js');
let pusher = new Pusher('1d9ffac87de599c61283', {cluster: 'ap2'});
let apiKey = "YOUR_TRANSAK_API_KEY"
let partnerOrderId = "YOUR_UNIQUE_ORDER_ID"
let channelName = `${apiKey}_${partnerOrderId}`

//to subscribe
let channel = pusher.subscribe(channelName);

//receive updates of all the events
pusher.bind_global((eventId, orderData) => {
    console.log(`${eventId} ${orderData}`)
});

//receive updates of a specific event
// channel.bind(`ORDER_COMPLETED`, (orderData) => {
//     console.log(orderData)
// });

//to unsubscribe
//pusher.unsubscribe(orderId);

// sample order data

{ status: 'COMPLETED',
  id: '7467f962-0842-4095-ac9e-1689da6e1414',
  walletAddress: '0x3CAdbeB58CB5162439908edA08df0A305b016dA8',
  fiatCurrency: 'EUR',
  fiatAmount: 100,
  cryptoAmount: 0.4581929390176435,
  cryptocurrency: 'ETH',
  isBuyOrSell: 'BUY',
  transactionLink:
   'https://rinkeby.etherscan.io/tx/0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3',
  transactionHash:
   '0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3' 
}
import Pusher from "pusher-js"; // For React JS
import jwt from 'jsonwebtoken';

// Initialize Pusher with your app credentials
const pusherApiKey = '1d9ffac87de599c61283';
const pusherCluster = 'ap2';
const pusher = new Pusher(pusherApiKey, { cluster: pusherCluster });

// Define your API key and subscribe to the Pusher channel
const apiKey = 'YOUR_API_KEY';  // Replace with your actual API key
const channel = pusher.subscribe(apiKey);

// Callback function to handle incoming encrypted order data
const handleEncryptedOrderData = (encryptedOrderData) => {
    if (typeof encryptedOrderData === 'string') {
        try {
            const partnerAccessToken = "YOUR_ACCESS_TOKEN";  // Replace with your actual access token
            const decryptedOrderData = jwt.verify(encryptedOrderData, partnerAccessToken);

            if (decryptedOrderData && decryptedOrderData.id) {
                console.log({ orderData: decryptedOrderData });
            }
        } catch (error) {
            console.error(error);
        }
    }
};

// Subscribe to receive updates for a specific order ID
const orderId = 'YOUR_ORDER_ID';  // Replace with the actual order ID
channel.bind(orderId, (encryptedOrderData) => {
    console.log("Encrypted Order Data", encryptedOrderData);
    handleEncryptedOrderData(encryptedOrderData);
});

// To unsubscribe (if needed)
// channel.unsubscribe(apiKey);


// Sample Decrypted Payload Data

{ 
      "id":"9151faa1-e69b-4a36-b959-3c4f894afb68",
      "walletAddress":"0x86349020e9394b2BE1b1262531B0C3335fc32F20",
      "createdAt":"2020-02-17T01:55:05.095Z",
      "status":"AWAITING_PAYMENT_FROM_USER",
      "fiatCurrency":"INR",
      "userId":"65317131-cd95-419a-a50c-747d142f83e9",
      "cryptocurrency":"CDAI",
      "isBuyOrSell":"BUY",
      "fiatAmount":1110,
      "commissionDecimal":0.0075,
      "fromWalletAddress":"0x085ee67132ec4297b85ed5d1b4c65424d36fda7d",
      "walletLink":"https://rinkeby.etherscan.io/address/0x86349020e9394b2BE1b1262531B0C3335fc32F20#tokentxns",
      "amountPaid":0,
      "partnerOrderId":"2183721893",
      "partnerCustomerId":"2183721893",
      "redirectURL":"https://google.com",
      "conversionPrice":0.663847164368606,
      "cryptoAmount":731.34,
      "totalFee":5.52652764336864,
      "paymentOption":[],
      "autoExpiresAt":"2020-02-16T19:55:05-07:00",
      "referenceCode":226056
}

Javascript

The snippet below connects to channels and subscribes to a channel.

Installation

add https://js.pusher.com/6.0/pusher.min.js in your script tag in html.

Examples

<!DOCTYPE html>
<head>
  <title>Pusher Test</title>
  <script src="https://js.pusher.com/6.0/pusher.min.js"></script>
  <script>
    // Enable pusher logging - don't include this in production
    Pusher.logToConsole = true;

		let pusher = new Pusher('1d9ffac87de599c61283', {cluster: 'ap2'});
		let orderId = "TRANSAK_ORDER_ID"
		
		//to subscribe
		let channel = pusher.subscribe(orderId);
		
		//receive updates of all the events
		pusher.bind_global((eventId, orderData) => {
		    console.log(`${eventId} ${orderData}`)
		});
		
		//receive updates of a specific event
		// channel.bind(`ORDER_COMPLETED`, (orderData) => {
		//     console.log(orderData)
		// });
		
		//to unsubscribe
		//pusher.unsubscribe(orderId);
  </script>
</head>
<body>
  <h1>Pusher Test</h1>
  <p>
    Try publishing an event to channel <code>my-channel</code>
    with event name <code>my-event</code>.
  </p>
</body>


// Sample order data

{ status: 'COMPLETED',
  id: '7467f962-0842-4095-ac9e-1689da6e1414',
  walletAddress: '0x3CAdbeB58CB5162439908edA08df0A305b016dA8',
  fiatCurrency: 'EUR',
  fiatAmount: 100,
  cryptoAmount: 0.4581929390176435,
  cryptocurrency: 'ETH',
  isBuyOrSell: 'BUY',
  transactionLink:
   'https://rinkeby.etherscan.io/tx/0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3',
  transactionHash:
   '0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3' 
}
<!DOCTYPE html>
<head>
  <title>Pusher Test</title>
  <script src="https://js.pusher.com/6.0/pusher.min.js"></script>
  <script>
    // Enable pusher logging - don't include this in production
    Pusher.logToConsole = true;

		let pusher = new Pusher('1d9ffac87de599c61283', {cluster: 'ap2'});
		let apiKey = "YOUR_TRANSAK_API_KEY"
		let partnerOrderId = "YOUR_UNIQUE_ORDER_ID"
		let channelName = `${apiKey}_${partnerOrderId}`
		
		//to subscribe
		let channel = pusher.subscribe(channelName);
		
		//receive updates of all the events
		pusher.bind_global((eventId, orderData) => {
		    console.log(`${eventId} ${orderData}`)
		});
		
		//receive updates of a specific event
		// channel.bind(`ORDER_COMPLETED`, (orderData) => {
		//     console.log(orderData)
		// });
		
		//to unsubscribe
		//pusher.unsubscribe(orderId);
  </script>
</head>
<body>
  <h1>Pusher Test</h1>
  <p>
    Try publishing an event to channel <code>my-channel</code>
    with event name <code>my-event</code>.
  </p>
</body>



// sample order data

{ status: 'COMPLETED',
  id: '7467f962-0842-4095-ac9e-1689da6e1414',
  walletAddress: '0x3CAdbeB58CB5162439908edA08df0A305b016dA8',
  fiatCurrency: 'EUR',
  fiatAmount: 100,
  cryptoAmount: 0.4581929390176435,
  cryptocurrency: 'ETH',
  isBuyOrSell: 'BUY',
  transactionLink:
   'https://rinkeby.etherscan.io/tx/0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3',
  transactionHash:
   '0x2952a2449e2ee905a238bedce383a6f3ebfb26b1483b9e46218b376a9fdd05f3' 
}
<!DOCTYPE html>
<head>
  <title>Pusher Test</title>
  <script src="https://js.pusher.com/6.0/pusher.min.js"></script>
  <script>
    // Enable pusher logging - don't include this in production
    Pusher.logToConsole = true;

    var pusher = new Pusher('1d9ffac87de599c61283', {
      cluster: 'ap2'
    });

   let partnerApiKey = 'YOUR_API_KEY';
	 let partnerApiSecret = 'YOUR_API_SECRET'
   let channel = pusher.subscribe(partnerApiKey);

   let callback = function (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 all the orders
		pusher.bind_global((orderId, encryptedOrderData) => {
		    console.log(`Order update ${orderId}`)
		    return callback(encryptedOrderData)
		});

		//receive updates of a specific order
		// let user_order_id = "YOUR_USER_ORDER_ID"
		// channel.bind(`${user_order_id}`, (encryptedOrderData) => {
		//     return callback(encryptedOrderData)
		// });
		
		//to unsubscribe
		//pusher.unsubscribe(partnerApiKey);
  </script>
</head>
<body>
  <h1>Pusher Test</h1>
  <p>
    Try publishing an event to channel <code>my-channel</code>
    with event name <code>my-event</code>.
  </p>
</body>


// Sample decrypted order data

{ 
      "id":"9151faa1-e69b-4a36-b959-3c4f894afb68",
      "walletAddress":"0x86349020e9394b2BE1b1262531B0C3335fc32F20",
      "createdAt":"2020-02-17T01:55:05.095Z",
      "status":"AWAITING_PAYMENT_FROM_USER",
      "fiatCurrency":"INR",
      "userId":"65317131-cd95-419a-a50c-747d142f83e9",
      "cryptocurrency":"CDAI",
      "isBuyOrSell":"BUY",
      "fiatAmount":1110,
      "commissionDecimal":0.0075,
      "fromWalletAddress":"0x085ee67132ec4297b85ed5d1b4c65424d36fda7d",
      "walletLink":"https://rinkeby.etherscan.io/address/0x86349020e9394b2BE1b1262531B0C3335fc32F20#tokentxns",
      "amountPaid":0,
      "partnerOrderId":"2183721893",
      "partnerCustomerId":"2183721893",
      "redirectURL":"https://google.com",
      "conversionPrice":0.663847164368606,
      "cryptoAmount":731.34,
      "totalFee":5.52652764336864,
      "paymentOption":[],
      "autoExpiresAt":"2020-02-16T19:55:05-07:00",
      "referenceCode":226056
}

Java (Android)

iOS

Flutter