API Reference

Code for Integration

Find the sample code/libraries and test cases for integration

Find the sample libraries for different languages to integrate the ISV’s software with Valor Connect.

Library Name - php-mqtt Library URL - 'https://github.com/php-mqtt/client' PUBLISHER: <?php require "vendor/autoload.php"; use PhpMqttClientMQTTClient; define("MQTT_BROKER", "vc-staging.valorpaytech.com"); // MQTT Broker IP or Domain define("MQTT_PORT", 28883); define("MQTT_CA_CERT_PATH", "../ca.crt"); // CA Certificate File Path define("MQTT_CERT_PATH", "../client.crt"); // Client Certificate File Path define("MQTT_CERT_KEY_PATH", "../client.key"); // Client Key File Path $mqtt = new PhpMqttClientMqttClient(MQTT_BROKER, MQTT_PORT); $connectionSettings = (new PhpMqttClientConnectionSettings()) ->setUseTls(true) ->setTlsVerifyPeer(true) ->setTlsCertificateAuthorityFile(MQTT_CA_CERT_PATH) ->setTlsClientCertificateFile(MQTT_CERT_PATH) ->setTlsClientCertificateKeyFile(MQTT_CERT_KEY_PATH); $mqtt->connect($connectionSettings, true); // Refer API Doc for addtional params in payload $payload = [ "TRAN_MODE" => "1", "TRAN_CODE" => "1", "AMOUNT" => "100", ]; $mqtt->publish( // topic "<Channel ID>/UAT/VC/<EPI>/POS", // payload json_encode($payload) ); // // Replace Channel ID and EPI $mqtt->disconnect(); SUBSCRIBER: <?php require "vendor/autoload.php"; use PhpMqttClientMQTTClient; define("MQTT_BROKER", "vc-staging.valorpaytech.com"); // MQTT Broker IP or Domain define("MQTT_PORT", 28883); define("MQTT_CA_CERT_PATH", "../ca.crt"); // CA Certificate File Path define("MQTT_CERT_PATH", "../client.crt"); // Client Certificate File Path define("MQTT_CERT_KEY_PATH", "../client.key"); // Client Key File Path define("MAX_SUB_TIMEOUT_SEC", 120); $mqtt = new PhpMqttClientMqttClient(MQTT_BROKER, MQTT_PORT); $connectionSettings = (new PhpMqttClientConnectionSettings()) ->setUseTls(true) ->setTlsVerifyPeer(true) ->setTlsCertificateAuthorityFile(MQTT_CA_CERT_PATH) ->setTlsClientCertificateFile(MQTT_CERT_PATH) ->setTlsClientCertificateKeyFile(MQTT_CERT_KEY_PATH); $mqtt->connect($connectionSettings, true); $mqtt->registerLoopEventHandler(function ( MqttClient $client, float $elapsedTime ) { // After MAX_SUB_TIMEOUT_SEC seconds, we quit the loop. if ($elapsedTime > MAX_SUB_TIMEOUT_SEC) { echo "Max Timeout"; $client->interrupt(); } }); $mqtt->subscribe( "<Channel ID>/UAT/VC/<EPI>/APP", function ($topic, $message) use ($mqtt) { echo sprintf("Received message on topic [%s]: %s", $topic, $message); $mqtt->interrupt(); }, 0 ); // Replace Channel ID and EPI $mqtt->loop(true); $mqtt->disconnect(); STATUS: <?php require "vendor/autoload.php"; use PhpMqttClientMQTTClient; define("MQTT_BROKER", "vc-staging.valorpaytech.com"); // MQTT Broker IP or Domain define("MQTT_PORT", 28883); define("MQTT_CA_CERT_PATH", "../ca.crt"); // CA Certificate File Path define("MQTT_CERT_PATH", "../client.crt"); // Client Certificate File Path define("MQTT_CERT_KEY_PATH", "../client.key"); // Client Key File Path define("MAX_SUB_TIMEOUT_SEC", 120); $mqtt = new PhpMqttClientMqttClient(MQTT_BROKER, MQTT_PORT); $connectionSettings = (new PhpMqttClientConnectionSettings()) ->setUseTls(true) ->setTlsVerifyPeer(true) ->setTlsCertificateAuthorityFile(MQTT_CA_CERT_PATH) ->setTlsClientCertificateFile(MQTT_CERT_PATH) ->setTlsClientCertificateKeyFile(MQTT_CERT_KEY_PATH); $mqtt->connect($connectionSettings, true); $mqtt->registerLoopEventHandler(function ( MqttClient $client, float $elapsedTime ) { // After MAX_SUB_TIMEOUT_SEC seconds, we quit the loop. if ($elapsedTime > MAX_SUB_TIMEOUT_SEC) { echo "Max Timeout"; $client->interrupt(); } }); $mqtt->subscribe( "<Channel ID>/UAT/VC/<EPI>/STATUS", function ($topic, $message) use ($mqtt) { echo sprintf("Received message on topic [%s]: %s", $topic, $message); $mqtt->interrupt(); }, 0 ); // Replace Channel ID and EPI $mqtt->loop(true); $mqtt->disconnect();
Library Name - Eclipse Paho Python Library URL - 'https://github.com/eclipse/paho.mqtt.python' PUBLISHER: import paho.mqtt.client as mqtt import json """ global variables """ MQTT_BROKER = "vc-staging.valorpaytech.com" # MQTT Broker IP or Domain MQTT_PORT = 28883 MQTT_CA_CERT_PATH = "../ca.crt" # CA Certificate File Path MQTT_CERT_PATH = "../client.crt" # Client Certificate File Path MQTT_CERT_KEY_PATH = "../client.key" # Client Key File Path payload = {"TRAN_MODE":"1", "TRAN_CODE":"1","AMOUNT":"100"} # Refer API Doc for addtional params # Connection success callback def on_connect(client, userdata, flags, rc): print("Connected to MQTT Broker!") def on_log(client, userdata, level, buf): print(buf) client = mqtt.Client() client.on_connect = on_connect client.on_log = on_log client.tls_set(MQTT_CA_CERT_PATH, MQTT_CERT_PATH, MQTT_CERT_KEY_PATH) client.connect(MQTT_BROKER, MQTT_PORT) # client.loop() client.publish("<Channel ID>/UAT/VC/<EPI>/POS", json.dumps(payload)) # Replace Channel ID and EPI client.loop() client.disconnect() SUBSCRIBER: import paho.mqtt.client as mqtt """ global variables """ MQTT_BROKER = "vc-staging.valorpaytech.com" # MQTT Broker IP or Domain MQTT_PORT = 28883 MQTT_CA_CERT_PATH = "../ca.crt" # CA Certificate File Path MQTT_CERT_PATH = "../client.crt" # Client Certificate File Path MQTT_CERT_KEY_PATH = "../client.key" # Client Key File Path MAX_SUB_TIMEOUT = 120 vc_response = False # Connection success callback def on_connect(client, userdata, flags, rc): print("Connected to MQTT Broker!") # Log information def on_log(client, userdata, level, buf): print(buf) def on_message(client, userdata, msg): global vc_response # Using global variable vc_response = msg.payload.decode() print(msg.payload.decode()) client = mqtt.Client() client.on_connect = on_connect client.on_log = on_log client.on_message = on_message client.tls_set(MQTT_CA_CERT_PATH, MQTT_CERT_PATH, MQTT_CERT_KEY_PATH) client.connect(MQTT_BROKER, MQTT_PORT) # client.loop() client.subscribe("<Channel ID>/UAT/VC/<EPI>/APP") # Replace Channel ID and EPI for i in range(MAX_SUB_TIMEOUT): if vc_response: # Once got response exit break client.loop() client.disconnect() STATUS: import paho.mqtt.client as mqtt """ global variables """ MQTT_BROKER = "vc-staging.valorpaytech.com" # MQTT Broker IP or Domain MQTT_PORT = 28883 MQTT_CA_CERT_PATH = "../ca.crt" # CA Certificate File Path MQTT_CERT_PATH = "../client.crt" # Client Certificate File Path MQTT_CERT_KEY_PATH = "../client.key" # Client Key File Path MAX_SUB_TIMEOUT = 120 vc_response = False # Connection success callback def on_connect(client, userdata, flags, rc): print("Connected to MQTT Broker!") # Log information def on_log(client, userdata, level, buf): print(buf) def on_message(client, userdata, msg): global vc_response # Using global variable vc_response = msg.payload.decode() print(msg.payload.decode()) client = mqtt.Client() client.on_connect = on_connect client.on_log = on_log client.on_message = on_message client.tls_set(MQTT_CA_CERT_PATH, MQTT_CERT_PATH, MQTT_CERT_KEY_PATH) client.connect(MQTT_BROKER, MQTT_PORT) # client.loop() client.subscribe("<Channel ID>/UAT/VC/<EPI>/STATUS") # Replace Channel ID and EPI for i in range(MAX_SUB_TIMEOUT): if vc_response: # Once got response exit break client.loop() client.disconnect()
Library Name - MQTT.js Library URL - 'https://github.com/mqttjs/MQTT.js' PUBLISHER: import mqtt from 'mqtt' import fs from 'fs' const MQTT_BROKER = 'mqtts://vc-staging.valorpaytech.com' // MQTT Broker IP or Domain const MQTT_PORT = 28883 const MQTT_CA_CERT_PATH = "ca.crt" // CA Certificate File Path const MQTT_CERT_PATH = "client.crt" // Client Certificate File Path const MQTT_CERT_KEY_PATH = "client.key" // Client Key File Path // connection option const options = { ca: fs.readFileSync(MQTT_CA_CERT_PATH), cert: fs.readFileSync(MQTT_CERT_PATH), key: fs.readFileSync(MQTT_CERT_KEY_PATH) } const connectUrl = MQTT_BROKER + ':' + MQTT_PORT const client = mqtt.connect(connectUrl, options) // Refer API Doc for addtional params var payload = { "TRAN_MODE": "1", "TRAN_CODE": "1", "AMOUNT": "100" } client.on('connect', function() { client.publish('<Channel ID>/UAT/VC/<EPI>/POS', JSON.stringify(payload), function() { console.log("Message is published"); client.end(); // Close the connection when published }); // Replace Channel ID and EPI }) SUBSCRIBER: import mqtt from 'mqtt' import fs from 'fs' const MQTT_BROKER = 'mqtts://vc-staging.valorpaytech.com' // MQTT Broker IP or Domain const MQTT_PORT = 28883 const MQTT_CA_CERT_PATH = "ca.crt" // CA Certificate File Path const MQTT_CERT_PATH = "client.crt" // Client Certificate File Path const MQTT_CERT_KEY_PATH = "client.key" // Client Key File Path const MAX_SUB_TIMEOUT_SEC = 120 // connection option const options = { ca: fs.readFileSync(MQTT_CA_CERT_PATH), cert: fs.readFileSync(MQTT_CERT_PATH), key: fs.readFileSync(MQTT_CERT_KEY_PATH) } const connectUrl = MQTT_BROKER + ':' + MQTT_PORT const client = mqtt.connect(connectUrl, options) var maxResponseTimeout; client.on('connect', function() { client.subscribe('<Channel ID>/UAT/VC/<EPI>/APP'); // Replace Channel ID and EPI }) client.on('message', function(topic, message) { console.log(topic) console.log(message.toString()) clearTimeout(maxResponseTimeout); client.end(); }) maxResponseTimeout = setTimeout(() => { console.log('Closing connection to MQTT after +MAX_SUB_TIMEOUT_SEC+ seconds.'); client.end(); }, MAX_SUB_TIMEOUT_SEC * 1000); STATUS: import mqtt from 'mqtt' import fs from 'fs' const MQTT_BROKER = 'mqtts://vc-staging.valorpaytech.com' // MQTT Broker IP or Domain const MQTT_PORT = 28883 const MQTT_CA_CERT_PATH = "ca.crt" // CA Certificate File Path const MQTT_CERT_PATH = "client.crt" // Client Certificate File Path const MQTT_CERT_KEY_PATH = "client.key" // Client Key File Path const MAX_SUB_TIMEOUT_SEC = 120 // connection option const options = { ca: fs.readFileSync(MQTT_CA_CERT_PATH), cert: fs.readFileSync(MQTT_CERT_PATH), key: fs.readFileSync(MQTT_CERT_KEY_PATH) } const connectUrl = MQTT_BROKER + ':' + MQTT_PORT const client = mqtt.connect(connectUrl, options) var maxResponseTimeout; client.on('connect', function() { client.subscribe('<Channel ID>/UAT/VC/<EPI>/STATUS'); // Replace Channel ID and EPI }) client.on('message', function(topic, message) { console.log(topic) console.log(message.toString()) clearTimeout(maxResponseTimeout); client.end(); }) maxResponseTimeout = setTimeout(() => { console.log('Closing connection to MQTT after +MAX_SUB_TIMEOUT_SEC+ seconds.'); client.end(); }, MAX_SUB_TIMEOUT_SEC * 1000);
Library Name - paho-mqtt3a - asynchronous (MQTTAsync) paho-mqtt3as - asynchronous with SSL (MQTTAsync) paho-mqtt3c - "classic" / synchronous (MQTTClient) paho-mqtt3cs - "classic" / synchronous with SSL (MQTTClient) Library URL - 'https://github.com/eclipse/paho.mqtt.c' #define ADDRESS 'vc-staging.valorpaytech.com:28883' PUBLISHER: MQTTClient client; MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; MQTTClient_message pubmsg = MQTTClient_message_initializer; MQTTClient_deliveryToken token; MQTTClient_SSLOptions ssl_opts = MQTTClient_SSLOptions_initializer; int rc; MQTTClient_create(&client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); // MQTT Connection parameters conn_opts.keepAliveInterval = 10; conn_opts.cleansession = 1; conn_opts.ssl = &ssl_opts; conn_opts.ssl->trustStore = CA_CRT; // CA_CRT will be an Certificate Authority Certficate file conn_opts.ssl->keyStore = CLIENT_CRT; // CLIENT_CRT will be an Client Certificate file conn_opts.ssl->privateKey = CLIENT_KEY; // CLIENT_KEY will be an Client Key file conn_opts.ssl->enableServerCertAuth = 1; conn_opts.ssl->verify = 1; if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS) { printf("Failed to connect, return code %d", rc); exit(-1); } // Publish message pubmsg.payload = PAYLOAD; pubmsg.payloadlen = strlen(PAYLOAD); pubmsg.qos = QOS; pubmsg.retained = 0; MQTTClient_publishMessage(client, TOPIC, &pubmsg, &token); // Topic will be <channelid>/UAT/VC/<EPI_ID>/POS MQTTClient_disconnect(client, 10000); MQTTClient_destroy(&client); return rc; } SUBSCRIBER: MQTTClient client; MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; MQTTClient_SSLOptions ssl_opts = MQTTClient_SSLOptions_initializer; MQTTClient_create(&client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); // MQTT Connection parameters conn_opts.keepAliveInterval = 20; conn_opts.cleansession = 1; conn_opts.ssl = &ssl_opts; conn_opts.ssl->trustStore = CA_CRT; // CA_CRT will be an Certificate Authority Certficate file conn_opts.ssl->keyStore = CLIENT_CRT; // CLIENT_CRT will be an Client Certificate file conn_opts.ssl->privateKey = CLIENT_KEY; // CLIENT_KEY will be an Client Key file conn_opts.ssl->enableServerCertAuth = 1; conn_opts.ssl->verify = 1; if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS) { printf("Failed to connect, return code %d", rc); exit(-1); } MQTTClient_subscribe(client, TOPIC, QOS); // Topic will be <channelid>/UAT/VC/<EPI_ID>/APP do { ch = getchar(); } while(ch!='Q' && ch != 'q'); printf("New message with topic%s: %s",TOPIC,ch); MQTTClient_disconnect(client, 10000); MQTTClient_destroy(&client); return rc; STATUS: MQTTClient client; MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; MQTTClient_SSLOptions ssl_opts = MQTTClient_SSLOptions_initializer; MQTTClient_create(&client, ADDRESS, CLIENTID, MQTTCLIENT_PERSISTENCE_DEFAULT, NULL); // MQTT Connection parameters conn_opts.keepAliveInterval = 20; conn_opts.cleansession = 1; conn_opts.ssl = &ssl_opts; conn_opts.ssl->trustStore = CA_CRT; // CA_CRT will be an Certificate Authority Certficate file conn_opts.ssl->keyStore = CLIENT_CRT; // CLIENT_CRT will be an Client Certificate file conn_opts.ssl->privateKey = CLIENT_KEY; // CLIENT_KEY will be an Client Key file conn_opts.ssl->enableServerCertAuth = 1; conn_opts.ssl->verify = 1; if ((rc = MQTTClient_connect(client, &conn_opts)) != MQTTCLIENT_SUCCESS) { printf("Failed to connect, return code %d", rc); exit(-1); } MQTTClient_subscribe(client, TOPIC, QOS); // Topic will be <channelid>/UAT/VC/<EPI_ID>/STATUS do { ch = getchar(); } while(ch!='Q' && ch != 'q'); printf("New message with topic%s: %s",TOPIC,ch); MQTTClient_disconnect(client, 10000); MQTTClient_destroy(&client); return rc;
Library Name - MQTTnet Library URL - 'https://github.com/dotnet/MQTTnet' PUBLISHER: using MQTTnet; using MQTTnet.Client; using System; using System.IO; using System.Security.Cryptography.X509Certificates; using System.Text.Json; using System.Threading.Tasks; // Create a new MQTT client instance var mqttFactory = new MqttFactory(); var mqttClient = mqttFactory.CreateMqttClient(); try { var caCertPath = @"certs/ca-chain.crt"; var clientCertPath = @"certs/client.pfx"; var options = new MqttClientOptionsBuilder() .WithTcpServer("vc-staging.valorpaytech.com", 28883) // Replace with MQTT broker details .WithTlsOptions(o => { o.UseTls(true); o.WithAllowUntrustedCertificates(false); o.WithClientCertificates(new[] { new X509Certificate2(caCertPath), new X509Certificate2(clientCertPath) // We created pfx without a password }); o.WithCertificateValidationHandler(args => { return true; }); }) .Build(); await mqttClient.ConnectAsync(options, CancellationToken.None); // Create a JSON object to send var payload = new { TRAN_MODE = "1", TRAN_CODE = "1", AMOUNT = "100" }; // Serialize the JSON object to a string var jsonPayload = JsonSerializer.Serialize(payload); var topic = "<Channel ID>/UAT/VC/<EPI>/POS"; var message = new MqttApplicationMessageBuilder() .WithTopic(topic) .WithPayload(jsonPayload) .Build(); // Publish the message await mqttClient.PublishAsync(message); Console.WriteLine("Message published successfully."); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } finally { if (mqttClient.IsConnected) { await mqttClient.DisconnectAsync(); } } SUBSCRIBER: using MQTTnet; using MQTTnet.Client; using System; using System.IO; using System.Security.Cryptography.X509Certificates; using System.Text.Json; using System.Threading.Tasks; // Create a new MQTT client instance var mqttFactory = new MqttFactory(); var mqttClient = mqttFactory.CreateMqttClient(); var mqttFactory = new MqttFactory(); var mqttClient = mqttFactory.CreateMqttClient(); try { var caCertPath = @"certs/ca-chain.crt"; var clientCertPath = @"certs/client.pfx"; var options = new MqttClientOptionsBuilder() .WithTcpServer("vc-staging.valorpaytech.com", 28883) // Replace with MQTT broker details .WithTlsOptions(o => { o.UseTls(true); o.WithAllowUntrustedCertificates(false); o.WithClientCertificates(new[] { new X509Certificate2(caCertPath), new X509Certificate2(clientCertPath) // We created pfx without a password }); o.WithCertificateValidationHandler(args => { return true; }); }) .Build(); await mqttClient.ConnectAsync(options, CancellationToken.None); var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder() .WithTopicFilter( f => { f.WithTopic("<Channel ID>/UAT/VC/<EPI>/APP"); }) .Build(); var response = await mqttClient.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None); Console.WriteLine("MQTT client subscribed to topic."); mqttClient.ApplicationMessageReceivedAsync += async m => await Console.Out.WriteAsync($"Received message on topic: '{m.ApplicationMessage.Topic}' with content: '{m.ApplicationMessage.ConvertPayloadToString()}' "); Console.WriteLine("Press enter to exit."); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } finally { if (mqttClient.IsConnected) { await mqttClient.DisconnectAsync(); } } STATUS: using MQTTnet; using MQTTnet.Client; using System; using System.IO; using System.Security.Cryptography.X509Certificates; using System.Text.Json; using System.Threading.Tasks; // Create a new MQTT client instance var mqttFactory = new MqttFactory(); var mqttClient = mqttFactory.CreateMqttClient(); var mqttFactory = new MqttFactory(); var mqttClient = mqttFactory.CreateMqttClient(); try { var caCertPath = @"certs/ca-chain.crt"; var clientCertPath = @"certs/client.pfx"; var options = new MqttClientOptionsBuilder() .WithTcpServer("vc-staging.valorpaytech.com", 28883) // Replace with MQTT broker details .WithTlsOptions(o => { o.UseTls(true); o.WithAllowUntrustedCertificates(false); o.WithClientCertificates(new[] { new X509Certificate2(caCertPath), new X509Certificate2(clientCertPath) // We created pfx without a password }); o.WithCertificateValidationHandler(args => { return true; }); }) .Build(); await mqttClient.ConnectAsync(options, CancellationToken.None); var mqttSubscribeOptions = mqttFactory.CreateSubscribeOptionsBuilder() .WithTopicFilter( f => { f.WithTopic("<Channel ID>/UAT/VC/<EPI>/STATUS"); }) .Build(); var response = await mqttClient.SubscribeAsync(mqttSubscribeOptions, CancellationToken.None); Console.WriteLine("MQTT client subscribed to topic."); mqttClient.ApplicationMessageReceivedAsync += async m => await Console.Out.WriteAsync($"Received message on topic: '{m.ApplicationMessage.Topic}' with content: '{m.ApplicationMessage.ConvertPayloadToString()}' "); Console.WriteLine("Press enter to exit."); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } finally { if (mqttClient.IsConnected) { await mqttClient.DisconnectAsync(); } }
Library Name - MQTTnet Library URL - 'https://github.com/njh/ruby-mqtt' PUBLISHER: require 'mqtt' require 'json' MQTT_BROKER = "vc-staging.valorpaytech.com" # MQTT Broker IP or Domain MQTT_PORT = 28883 MQTT_CA_CERT_PATH = "./ca-chain.crt" # CA Certificate File Path MQTT_CERT_PATH = "./client.crt" # Client Certificate File Path MQTT_CERT_KEY_PATH = "./client.key" # Client Key File Path client = MQTT::Client.new client.host = MQTT_BROKER client.port = MQTT_PORT client.ssl = true client.cert_file = MQTT_CERT_PATH client.key_file = MQTT_CERT_KEY_PATH client.ca_file = MQTT_CA_CERT_PATH client.connect() payload = { "TRAN_MODE":"1", "TRAN_CODE":"1", "AMOUNT":"100" } json_payload = payload.to_json # Publish message to terminal client.publish('<Channel ID>/UAT/VC/<EPI>/POS', json_payload) client.disconnect SUBSCRIBER: require 'mqtt' require 'json' MQTT_BROKER = "vc-staging.valorpaytech.com" # MQTT Broker IP or Domain MQTT_PORT = 28883 MQTT_CA_CERT_PATH = "./ca-chain.crt" # CA Certificate File Path MQTT_CERT_PATH = "./client.crt" # Client Certificate File Path MQTT_CERT_KEY_PATH = "./client.key" # Client Key File Path MAX_TIME_OUT_SECONDS = 120 message_received = false client = MQTT::Client.new client.host = MQTT_BROKER client.port = MQTT_PORT client.ssl = true client.cert_file = MQTT_CERT_PATH client.key_file = MQTT_CERT_KEY_PATH client.ca_file = MQTT_CA_CERT_PATH # Subscribe to a topic in a separate thread subscriber_thread = Thread.new do client.connect() client.subscribe('<Channel ID>/UAT/VC/<EPI>/APP') # Change your Channel ID and EPI # Listen for messages client.get do |topic, received_message| puts "Received message on topic '#{topic}': #{received_message}" # Set the flag to indicate that a message has been received message_received = true # Close the client connection client.disconnect subscriber_thread.kill end end puts "Subscription start" # Wait for message or timeout subscriber_thread.join(MAX_TIME_OUT_SECONDS) # If no message received within the timeout, exit the program unless message_received puts "No message received within #{MAX_TIME_OUT_SECONDS} seconds. Exiting subscription." subscriber_thread.kill # Terminate the subscriber thread client.disconnect # Disconnect the client end STATUS: require 'mqtt' require 'json' MQTT_BROKER = "vc-staging.valorpaytech.com" # MQTT Broker IP or Domain MQTT_PORT = 28883 MQTT_CA_CERT_PATH = "./ca-chain.crt" # CA Certificate File Path MQTT_CERT_PATH = "./client.crt" # Client Certificate File Path MQTT_CERT_KEY_PATH = "./client.key" # Client Key File Path MAX_TIME_OUT_SECONDS = 120 message_received = false client = MQTT::Client.new client.host = MQTT_BROKER client.port = MQTT_PORT client.ssl = true client.cert_file = MQTT_CERT_PATH client.key_file = MQTT_CERT_KEY_PATH client.ca_file = MQTT_CA_CERT_PATH # Subscribe to a topic in a separate thread subscriber_thread = Thread.new do client.connect() client.subscribe('<Channel ID>/UAT/VC/<EPI>/STATUS') # Change your Channel ID and EPI # Listen for messages client.get do |topic, received_message| puts "Received message on topic '#{topic}': #{received_message}" # Set the flag to indicate that a message has been received message_received = true # Close the client connection client.disconnect subscriber_thread.kill end end puts "Subscription start" # Wait for message or timeout subscriber_thread.join(MAX_TIME_OUT_SECONDS) # If no message received within the timeout, exit the program unless message_received puts "No message received within #{MAX_TIME_OUT_SECONDS} seconds. Exiting subscription." subscriber_thread.kill # Terminate the subscriber thread client.disconnect # Disconnect the client end
Library Name - paho.mqtt.golang Library URL - 'https://github.com/eclipse/paho.mqtt.golang' PUBLISHER: package main import ( "crypto/tls" "crypto/x509" "encoding/json" "fmt" "log" "os" mqtt "github.com/eclipse/paho.mqtt.golang" ) type Payload struct { TRAN_MODE string `json:"TRAN_MODE"` TRAN_CODE string `json:"TRAN_CODE"` AMOUNT string `json:"AMOUNT"` } var connectHandler mqtt.OnConnectHandler = func(client mqtt.Client) { fmt.Println("Connected") } var connectLostHandler mqtt.ConnectionLostHandler = func(client mqtt.Client, err error) { fmt.Printf("Connect lost: %+v", err) } func NewTlsConfig() *tls.Config { certpool := x509.NewCertPool() ca, err := os.ReadFile("ca-chain.crt") if err != nil { log.Fatalln(err.Error()) } certpool.AppendCertsFromPEM(ca) // Import client certificate/key pair clientKeyPair, err := tls.LoadX509KeyPair("client.crt", "client.key") if err != nil { panic(err) } return &tls.Config{ RootCAs: certpool, ClientAuth: tls.NoClientCert, ClientCAs: nil, InsecureSkipVerify: true, Certificates: []tls.Certificate{clientKeyPair}, } } func main() { var broker = "vc-staging.valorpaytech.com" var port = 28883 opts := mqtt.NewClientOptions() opts.AddBroker(fmt.Sprintf("ssl://%s:%d", broker, port)) tlsConfig := NewTlsConfig() opts.SetTLSConfig(tlsConfig) opts.SetClientID("go_mqtt_client-1") opts.OnConnect = connectHandler opts.OnConnectionLost = connectLostHandler client := mqtt.NewClient(opts) if token := client.Connect(); token.Wait() && token.Error() != nil { panic(token.Error()) } payload := Payload{ TRAN_MODE: "1", TRAN_CODE: "1", AMOUNT: "100", } // Convert payload to JSON jsonData, err := json.Marshal(payload) if err != nil { log.Fatal(err) } token := client.Publish("<Channel ID>/UAT/VC/<EPI>/POS", 0, false, jsonData) token.Wait() if token.Error() != nil { log.Println("Failed to publish message:", token.Error()) } else { fmt.Println("Message published") } client.Disconnect(250) } SUBSCRIBER: package main import ( "crypto/tls" "crypto/x509" "fmt" "log" "os" "time" mqtt "github.com/eclipse/paho.mqtt.golang" ) var connectHandlerSub mqtt.OnConnectHandler = func(client mqtt.Client) { fmt.Println("Connected") } var connectLostHandlerSub mqtt.ConnectionLostHandler = func(client mqtt.Client, err error) { fmt.Printf("Connect lost: %+v", err) } func NewTlsConfigSub() *tls.Config { certpool := x509.NewCertPool() ca, err := os.ReadFile("ca-chain.crt") if err != nil { log.Fatalln(err.Error()) } certpool.AppendCertsFromPEM(ca) // Import client certificate/key pair clientKeyPair, err := tls.LoadX509KeyPair("client.crt", "client.key") if err != nil { panic(err) } return &tls.Config{ RootCAs: certpool, ClientAuth: tls.NoClientCert, ClientCAs: nil, InsecureSkipVerify: true, Certificates: []tls.Certificate{clientKeyPair}, } } func main() { var broker = "vc-staging.valorpaytech.com" var port = 28883 var timeout = 120 * time.Second opts := mqtt.NewClientOptions() opts.AddBroker(fmt.Sprintf("ssl://%s:%d", broker, port)) tlsConfig := NewTlsConfigSub() opts.SetTLSConfig(tlsConfig) opts.SetClientID("go_mqtt_client_sub-1") opts.OnConnect = connectHandlerSub opts.OnConnectionLost = connectLostHandlerSub client := mqtt.NewClient(opts) if token := client.Connect(); token.Wait() && token.Error() != nil { panic(token.Error()) } ch := make(chan mqtt.Message, 1) client.Subscribe("<Channel ID>/UAT/VC/<EPI>/APP", 1, func(client mqtt.Client, msg mqtt.Message) { ch <- msg }) select { case msg := <-ch: fmt.Printf("Received message on topic %s: %s\n", msg.Topic(), msg.Payload()) client.Disconnect(250) // Disconnect after receiving message case <-time.After(timeout): fmt.Println("Timeout reached, no message received") client.Disconnect(250) // Disconnect after timeout } fmt.Println("Exiting...") } STATUS: package main import ( "crypto/tls" "crypto/x509" "fmt" "log" "os" "time" mqtt "github.com/eclipse/paho.mqtt.golang" ) var connectHandlerSub mqtt.OnConnectHandler = func(client mqtt.Client) { fmt.Println("Connected") } var connectLostHandlerSub mqtt.ConnectionLostHandler = func(client mqtt.Client, err error) { fmt.Printf("Connect lost: %+v", err) } func NewTlsConfigSub() *tls.Config { certpool := x509.NewCertPool() ca, err := os.ReadFile("ca-chain.crt") if err != nil { log.Fatalln(err.Error()) } certpool.AppendCertsFromPEM(ca) // Import client certificate/key pair clientKeyPair, err := tls.LoadX509KeyPair("client.crt", "client.key") if err != nil { panic(err) } return &tls.Config{ RootCAs: certpool, ClientAuth: tls.NoClientCert, ClientCAs: nil, InsecureSkipVerify: true, Certificates: []tls.Certificate{clientKeyPair}, } } func main() { var broker = "vc-staging.valorpaytech.com" var port = 28883 var timeout = 120 * time.Second opts := mqtt.NewClientOptions() opts.AddBroker(fmt.Sprintf("ssl://%s:%d", broker, port)) tlsConfig := NewTlsConfigSub() opts.SetTLSConfig(tlsConfig) opts.SetClientID("go_mqtt_client_sub-1") opts.OnConnect = connectHandlerSub opts.OnConnectionLost = connectLostHandlerSub client := mqtt.NewClient(opts) if token := client.Connect(); token.Wait() && token.Error() != nil { panic(token.Error()) } ch := make(chan mqtt.Message, 1) client.Subscribe("<Channel ID>/UAT/VC/<EPI>/STATUS", 1, func(client mqtt.Client, msg mqtt.Message) { ch <- msg }) select { case msg := <-ch: fmt.Printf("Received message on topic %s: %s\n", msg.Topic(), msg.Payload()) client.Disconnect(250) // Disconnect after receiving message case <-time.After(timeout): fmt.Println("Timeout reached, no message received") client.Disconnect(250) // Disconnect after timeout } fmt.Println("Exiting...") }

Test Case Document

Find the documents to test run sale, refund, and void after completing the integration.

Sale

A sale is a transaction between two or more parties in which the buyer receives tangible or intangible goods, services, or assets in exchange for money.

Refund

A refund transaction is a Transfer of settled funds from your merchant account to the customer’s account.

Void

A void transaction is a transaction that is canceled before it settles through a consumer's debit or credit card account.