how to do nativescript paytm integration - javascript

i have checked the native-script-paytm integration plugin. but both git-hub repository are not running instead it gives stack exception. so i created my own project and some how its doing something. but here i have lot of questions on how to get 'mid', 'order id' etc.
can anyone give step by step details for this.
const createViewModel = require("./main-view-model").createViewModel;
const Paytm = require("#nstudio/nativescript-paytm").Paytm;
const paytm = new Paytm();
exports.pageLoaded = function (args) {
const page = args.object;
page.bindingContext = createViewModel();
}
exports.onPayWithPaytm = function (args) {
console.log("Paying");
paytm.setIOSCallbacks({
didFinishedResponse: function (response) {
console.log("got response");
console.log(response);
},
didCancelTransaction: function () {
console.log("User cancelled transaction");
},
errorMissingParameterError: function (error) {
console.log(error);
}
});
const order = {
// This will fail saying duplicate order id
// generate your own order to test this.
MID: "Tomcas09769922377481",
ORDER_ID: "ORDER8874",
CUST_ID: "CUST6483",
INDUSTRY_TYPE_ID: "Retail",
CHANNEL_ID: "WAP",
TXN_AMOUNT: "10.00",
WEBSITE: "APP_STAGING",
CALLBACK_URL: "https://pguat.paytm.com/paytmchecksum/paytmCallback.jsp",
CHECKSUMHASH:
"NDspZhvSHbq44K3A9Y4daf9En3l2Ndu9fmOdLG+bIwugQ6682Q3JiNprqmhiWAgGUnNcxta3LT2Vtk3EPwDww8o87A8tyn7/jAS2UAS9m+c="
};
paytm.createOrder(order);
paytm.initialize("STAGING");
paytm.startPaymentTransaction({
someUIErrorOccurred: function (inErrorMessage) {
console.log(inErrorMessage);
},
onTransactionResponse: function (inResponse) {
console.log(inResponse);
},
networkNotAvailable: function () {
console.log("Network not available");
},
clientAuthenticationFailed: function (inErrorMessage) {
console.log(inErrorMessage);
},
onErrorLoadingWebPage: function (
iniErrorCode,
inErrorMessage,
inFailingUrl
) {
console.log(iniErrorCode, inErrorMessage, inFailingUrl);
},
onBackPressedCancelTransaction: function () {
console.log("User cancelled transaction by pressing back button");
},
onTransactionCancel: function (inErrorMessage, inResponse) {
console.log(inErrorMessage, inResponse);
}
});
}
For reference

As mentioned in the plugin's ReadMe file,
You will need a working backend server to generate paytm orders. Do not generate the order or checksum in the app.

Related

How can I pass an error message from the server backend to vue frontend

I am working on error handling for an application built in Vue/Vuetify. I am using external pagination for a datatable that links to an API that only allows so many hits in a period of time. Because of that, I'm trying to pass through and display an error of "Too Many Requests" on the front end for users when they hit that limit.
The issue I'm having though is passing that error from the backend server to the frontend. When it errors on the front end, it just gives a 500 error. However, the server log is giving me the actual error happening. How can I get that to pass? Below is the relevant javascript code from the server and the front end.
For note: I've been using eventbus to display errors throughout the project. But up until now, I haven't had to pass any from the back to front.
Backend Server
module.exports = {
async find(ctx) {
var page = ctx.query.page;
var key = '';
var locale = ({ location: '', location_type: '', page: page });
const sdk = require('api')('#');
try {
var response = await sdk.auth(key)['grants_funders'](locale);
}
catch (err) {
console.log(err);
}
;
// .then(res => console.log(res))
// .catch(err => console.error(err));
// console.log(response);
return response
}
};
FRONTEND
export default {
name: "Search",
components: {},
props: ["funderDirectories", "serverItemsLength"],
data() {
return {
page: 1,
usericon: usericon,
greentick: greentick,
listicon: listicon,
training: training,
keyword: null,
funderHeaders: [
{ text: "Organization", value: "funder_name" },
{ text: "City", value: "funder_city" },
{ text: "Country", value: "funder_country" },
{ text: "Count", value: "grant_count" },
],
myloadingvariable: false,
pageCount: 1,
itemsPerPage: 25,
};
},
watch: {
page() {
Vue.$funderService.find({ page: this.page }).then((res) => {
this.funderDirectories = res.data.rows;
this.serverItemsLength = res.data.total_hits;
});
},
},
methods: {},
computed: {
filteredFunderDirectories() {
if (!this.keyword) {
return this.funderDirectories;
}
return this.funderDirectories.filter(
(q) =>
q.funder_name.toLowerCase().indexOf(this.keyword.toLowerCase()) !== -1
);
},
},
};
Ultimately figured it out. added the following to the backend catch
return ctx.send({errorStatus:"Too Many Requests. Please Wait"},429)
And I was able to call

DialogFlow and contexts with voximplant

I try to set Contexts in DialogFlow with Voximplant intergration described here:
https://cogint.ai/voximplant-dialogflow-connector-2019/#settingcontexts
require(Modules.AI);
const languageCode = "en-US";
const agentId = 247;
let agent,
call,
conversation,
endUserParticipant,
isConversationCreated = false,
isCallCreated = false,
isCallConnected = false,
isParticipantCreated = false;
VoxEngine.addEventListener(AppEvents.Started,
function (ev) {
agent = new CCAI.Agent(agentId);
agent.addEventListener(CCAI.Events.Agent.Started, () => {
conversation = new CCAI.Conversation({ agent: agent });
conversation.addEventListener(CCAI.Events.Conversation.Created, () => {
isConversationCreated = true;
createParticipant();
});
});
});
VoxEngine.addEventListener(AppEvents.CallAlerting,
function (ev) {
isCallCreated = true;
createParticipant();
call = ev.call;
call.answer();
call.addEventListener(CallEvents.Connected,
function () {
isCallConnected = true;
//Script whith phone number to contexts must be added here somehow. Probably in setupMedia function.
setupMedia();
});
call.addEventListener(CallEvents.Disconnected,
function () {
conversation.stop();
VoxEngine.terminate();
});
});
function createParticipant() {
if (!isConversationCreated || !isCallCreated) return;
endUserParticipant = conversation.addParticipant({
call: call,
options: { role: "END_USER" },
dialogflowSettings: {
lang: languageCode,
singleUtterance: true,
replyAudioConfig: { audioEncoding: "OUTPUT_AUDIO_ENCODING_OGG_OPUS" },
},
});
endUserParticipant.addEventListener(CCAI.Events.Participant.Created, () => {
isParticipantCreated = true;
setupMedia();
});
}
function setupMedia() {
if (!isParticipantCreated || !isCallConnected) return;
endUserParticipant.analyzeContent({
eventInput: { name: "WELCOME", languageCode: languageCode },
});
endUserParticipant.addEventListener(
//Script whith phone number to contexts must be added here somehow.
phoneContext = {
name: "phone",
lifespanCount: 99,
parameters: {
caller_id: call.callerid(),
called_number: call.number()
}
},
//endUserParticipant.setQueryParameters({contexts: [phoneContext]})
//Script whith phone number to contexts must be added here somehow.
CCAI.Events.Participant.PlaybackFinished,
() => {
//Added by and call works, but hang up
VoxEngine.setQueryParameters({contexts: [phoneContext]});
//Added by and call works, but hang up
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
);
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
The Voximplant number is forwarded to Dialogflow but after 20 seconds the voicebot become silent, but call is not terminated. I remove contexts part and the call and voicebot works as it is intended to.
What is wrong?
I ended up rewrite my code. I was able to pass on the caller_id / caller_number parameters to DialogFlow not as a Contexts by script. However, I added the two variables as Contexts in my Welcome intent.
function setupMedia() {
if (!isParticipantCreated || !isCallConnected) return;
endUserParticipant.analyzeContent({
eventInput: {
name: "WELCOME",
languageCode: languageCode,
parameters: {
//phone: call.callerid(),
caller_id: call.callerid(),
called_number: call.number()}
},
});
endUserParticipant.addEventListener(
CCAI.Events.Participant.PlaybackFinished,
() => {
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
);
VoxEngine.sendMediaBetween(call, endUserParticipant);
}
I recommend using Voximplant's Modules.AI integration instead of Modules.CCAI as I used in the cogint.ai article you mentioned. Modules.CCAIis used automatically through Dialogflow's One-click integrations, but it is not as well supported beyond that from what I have seen.
They have instructions for that here and a walkthrough video here. Unfortunately the API is very different that what you have with the CCAI module, but you will find many more references and examples to that (like what I have on cogint.ai).
Modules.AI only works with Dialogflow ES.

How to get the revision history of user from Rally using Node js scripting

My requirement is to get the exact date/time when a user gets disabled.
To achieve this, I need to query for the line 'user set to INACTIVE' in the Revision History to find the date the user was switched from enabled to disabled.
How can I get the revision history using node js ?
I tried below code, but its not working as Rally support team mentioned that its older code and i have to try with v2.0.
Can somebody help me to achieve my requirement ?
var revisions = story.RevisionHistory.Revisions;
revisions.sort(byRevisionNumber);
var story_was_blocked = false;
// it doesn't matter how many revs have been in BLOCKED state, presence of one is sufficient
for (var rix = 0; rix < revisions.length && story_was_blocked === false; rix++) {
var rev = revisions[rix];
if (rev.Description.indexOf("BLOCKED changed from ") >= 0) {
story_was_blocked = true;
}
}
Here's a brief example of how this might be accomplished. Note that this just shows how to fetch all revisions in the collection on a User, you'd need to iterate through them and match the Description field on 'Disabled':
var rally = require('rally'),
queryUtils = rally.util.query,
rallyApi = rally({
// Example key, not valid
apiKey: '_UkMasZfjPZfquDIMExfEKnAboQUlyT2SP4UppMHir',
server: 'https://rally1.rallydev.com',
requestOptions: {
headers: {
'X-RallyIntegrationName': 'Query User Revisions',
'X-RallyIntegrationVendor': 'Stackoverflow user4211235',
'X-RallyIntegrationVersion': '1.0'
}
}
});
function onError(error) {
console.log('Failure!', error);
}
function queryUserRevisions(result) {
var revisions = result.Revisions;
rallyApi.query({
ref: revisions,
start: 1,
limit: Infinity,
order: 'RevisionNumber',
fetch: ['RevisionNumber','Description','CreationDate']
}, function(error, result) {
if(error) {
onError(error);
} else {
console.log('Success querying User Revisions...');
console.log('Summary of revisions on User:')
console.log(result);
}
});
}
function queryUserRevisionHistory(result) {
rallyApi.query({
ref: result.Results[0].RevisionHistory,
start: 1,
limit: Infinity,
fetch: ['Revisions','RevisionNumber','Description','CreationDate']
}, function(error, result) {
if(error) {
onError(error);
} else {
console.log('Success querying User Revision History. Querying Revisions...');
queryUserRevisions(result);
}
});
}
function queryUser(callback) {
rallyApi.query({
type: 'user',
start: 1,
pageSize: 2,
limit: 10,
order: 'CreationDate',
fetch: ['UserName', 'EmailAddress', 'RevisionHistory'],
query: queryUtils.where('UserName', '=', "user#company.com")
}, function(error, result) {
if(error) {
onError(error);
} else {
console.log('Success querying User. Querying Revision History...');
callback(result);
}
});
}
queryUser(queryUserRevisionHistory);

Angular-Toaster not working in my service?

I have got to know toaster.js from this site and trying to implement it in my web app. I have done it according to the example but it doesn't work.
Here is my service where I Implemented:
function () {
angular
.module('FoursquareApp')
.factory('DataService', DataService);
DataService.$inject = ['$http','toaster'];
function DataService($http, toaster) {
.id,
venueName: venue.name,var serviceBase = '/api/places/';
var placesDataFactory = {};
var userInContext = null;
var _getUserInCtx = function () {
return userInContext;
};
var _setUserInCtx = function (userInCtx) {
userInContext = userInCtx;
};
var _savePlace = function (venue) {
//process venue to take needed properties
var minVenue = {
userName: userInContext,
venueID: venue
address: venue.location.address,
category: venue.categories[0].shortName,
rating: venue.rating
};
return $http.post(serviceBase, minVenue).then(
function (results) {
toaster.pop('success', "Bookmarked Successfully", "Place saved to your bookmark!");
},
function (results) {
if (results.status == 304) {
toaster.pop('note', "Faield to Bookmark", "Something went wrong while saving :-(");
}
else {
toaster.pop('error', "Failed to Bookmark", "Something went wrong while saving :-(");
}
return results;
});
};
I have called the library scripts in index.html and also the css files.
Any ideas of what I might be doing wrong?
Are you sure that you use toaster.js library? The popular one is toastr.js
Try to modify your code to
DataService.$inject = ['$http','toastr'];
function DataService($http, toastr) {
...
Also ensure, that you link this js file in you index.html and also refer this package in main app module definition as a second (dependency) parameter

GCM Android notification received on device but not displaying

GCM Cloud messaging notifications for my Ionic Android app are not appearing in my device's home screen, despite the notification registering in the app itself.
I'm using the npm module node-gcm to send push notifications.
var gcm = require('node-gcm');
var message = new gcm.Message({
priority: 'high',
contentAvailable: true,
delayWhileIdle: true,
timeToLive: 10,
dryRun: false,
data: {
key1: 'message1',
key2: 'message2'
},
notification: {
title: "Hello, World",
body: "This is a notification that will be displayed ASAP."
}
});
var regIds = ['*device id*'];
var sender = new gcm.Sender('*api key*');
sender.send(message, { registrationIds: regIds }, function (err, result) {
if(err) console.error(err);
else console.log(result);
});
When I send a push notification to my device's ID, I get a successful response:
{ multicast_id: 8406385547051869000,
success: 1,
failure: 0,
canonical_ids: 0,
results: [ { message_id: '0:1441962697347777%b67ee170f9fd7ecd' } ] }
I then get the following message in my Android Studio console:
V/GCMBroadcastReceiver﹕ onReceive: com.google.android.c2dm.intent.RECEIVE
V/GCMBroadcastReceiver﹕ GCM IntentService class: com.plugin.gcm.GCMIntentService
V/GCMBaseIntentService﹕ Acquiring wakelock
V/GCMBaseIntentService﹕ Intent service name: GCMIntentService-GCMIntentService-5
D/GCMIntentService﹕ onMessage - context: android.app.Application#2dc6dbff
V/GCMBaseIntentService﹕ Releasing wakelock
In the Google Play Developer Console GCM Debugger, my notifications also to appear to have been confirmed.
0: 1441899623073525% b67ee170f9fd7ecd Confirmed
Other than this I receive no error message in the Android Studio console when a notification has been received.
The Ionic app itself registers the notification once I've sent one. However when I'm out of the app. no notification is displayed in the home screen.
$rootScope.$on('$cordovaPush:notificationReceived', function (event, notification) {
alert(notification);
if (ionic.Platform.isAndroid() && notification.event == "registered") {
window.localStorage['token'] = notification.regid;
var params = {
deviceType: 'android',
tokenId: notification.regid
};
NotificationService.registerDevice(params);
}
if (notification.badge) {
$cordovaPush.setBadgeNumber(notification.badge);
}
//notifications payload
if (notification.foreground == '0') {
if (notification.view) {
$timeout(function () {
$state.go('app.notifications');
});
} else {
if (notification.id) {
NotificationService.markNotificationAsRead(notification.id).success(function () {
$rootScope.$emit('notifications-read');
});
}
if (notification.chat) {
$timeout(function () {
$state.go('app.message', {id: notification.chat});
});
} else if (notification.post) {
$timeout(function () {
$state.go('app.singlePost', {id: notification.post});
});
} else if (notification.group) {
$timeout(function () {
$state.go('app.group', {id: notification.group});
});
}
}
}
});
You must add icon field in your notification block:
notification: {
title: "Hello, World",
body: "This is a notification that will be displayed ASAP.",
icon: "#drawable/ic_launcher"
}
I was having the same issue, using the sample provided at the node-gcm page. After struggling for quite some time i came across this blogpost: http://devgirl.org/2012/10/25/tutorial-android-push-notifications-with-phonegap/
and modified my code according to the example provided in the blog post.
i guess there is an issue with "notification" object on node-gcm code, using message.addData seems to make it work,
in short replacing the message creation and sending logic as below worked for my application :
// For Android
if (row.device === "Android" && row.deviceToken) {
console.log(row.deviceToken);
var sender = new gcm.Sender(serverApiKey);
var message = new gcm.Message();
message.addData('title','İş Geliştirme Platformu');
message.addData('message','Yeni İleti');
message.addData('msgcnt','1');
//message.collapseKey = 'demo';
message.delayWhileIdle = true;
message.timeToLive = 3;
var registrationIds = [];
registrationIds.push(row.deviceToken);
sender.send(message, registrationIds, 4, function (err, result) {
console.log(result);
res.send(200,result);
});
}
add your server IP to white list and try again:
console.developers.google.com > APIs & auth > credential > select your server key > and add your server IP

Categories

Resources