paypal invalid negative testing input - node.js

I try to simulate negative testing using paypal rest sdk with nodejs based on here
Hier is my code implementation:
config.headers = {
"PayPal-Mock-Response": {"mock_application_codes":"INSTRUMENT_DECLINED"}
}
paypal.payment.execute(paymentId, data, config, function (error, payment) {
if (error) {
console.log(error.response);
} else {
// success code
}
}});
However I got this following error:
{ name: 'SIMULATION_FRAMEWORK_INVALID_NEGATIVE_TESTING_INPUT',message:'Invalid input found. See the following supported cases.',links: [ { href: 'https://developer.paypal.com/docs/api/nt-rest/',rel: 'information_link' } ],details: [ { issue: 'You must have valid input.' } ],httpStatusCode: 400 }
Can anyone help me what's wrong from my code?
Many Thanks

You have to stringify the object:
headers: {
'PayPal-Mock-Response': JSON.stringify({
"mock_application_codes":"CANNOT_PAY_SELF"
})
},

Related

Amazon Pinpoint SMS For India

I am trying to implement Amazon's Pinpoint SMS. There is a special requirement for India to send SMS. I have followed this Documentation and added EntityId and TemplateId as extra parameters to pinpoint.sendMessages. But when I do, I am getting.
UnexpectedParameter: Unexpected key 'EntityId' found in params.MessageRequest.MessageConfiguration.SMSMessage
UnexpectedParameter: Unexpected key 'TemplateId' found in params.MessageRequest.MessageConfiguration.SMSMessage
Code
Refrence: AWS Official Pinpoint SMS Doc
let params = {
ApplicationId: applicationId,
MessageRequest: {
Addresses: {
[destinationNumber]: {
ChannelType: 'SMS'
}
},
MessageConfiguration: {
SMSMessage: {
Body: body,
EntityId: entityID,
Keyword: registeredKeyword,
MessageType: messageType,
OriginationNumber: originationNumber,
SenderId: senderId,
TemplateId: templateID
},
}
}
};
//Try to send the message.
pinpoint.sendMessages(params, function (err, data) {
// If something goes wrong, print an error message.
if (err) {
console.log(err.message);
// Otherwise, show the unique ID for the message.
} else {
console.log(data)
// console.log("Message sent! "
// + data['MessageResponse']['Result'][destinationNumber]['StatusMessage']);
}
});
Migrating AWS-SDK from 2.467.0 to 2.850 solved my issue.

Firebase fcm sendMulticast Error: "Exactly one of topic, token or condition is required"

I am using version 7.2.0 of firebase admin to send fcm push notification, using sendMutlicast method:
async function sendPushRequest({tokens, title, body, customData}) => {
const message = {
notification: {
title,
body,
},
data: customData,
tokens,
}
return firebase.messaging().sendMulticast(message)
}
This is the error I am getting
Error: Exactly one of topic, token or condition is required
at FirebaseMessagingError.Error (native)
at FirebaseMessagingError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)
...
I tried logging the data and here is the object that sendPushRequest function is called with:
{
tokens: [ null, null, null, 'home-test', null, null ], // this one is a recent sample, I've been getting this error for a while now
title: 'some string',
body: 'some other string',
customData: {
title: 'some string',
body: 'some other string',
bigText: 'again another string',
color: '#9f0e27',
smallIcon: 'notificon',
sound: 'default'
}
}
I'm not sure what is causing the error!
I struggled with this problem too, its quite difficult to configure google admin firebase in nodejs. I find out there is a package that can handle this nicely.
https://www.npmjs.com/package/fcm-notification
but it has some little problem . you can not pass it multiple firebase configuration. here is some example :
const fcm = require('fcm-notification');
const fcm_key = require('../config/customer/fcm.json');
const FcM = new fcm(fcm_key);
module.exports.sendToSingleUser = async (message, token) => {
let message_body = {
notification: {
...message
},
token: token
};
FcM.send(message_body, function (err, response) {
if (err) {
return err
} else {
return response
}
})
}
Facing this error too. Figure out that our tokens array contains null or undefiend value. Resolved by remove that from tokens array and everything works fine.

how to add update multiple response of a dialog node in IBM watson assistant with Nodejs

I have a node application which is interacting with IBM watson assistant.
I need to update the response output of a dialog node and I'm using the following watson api
var params = {
workspace_id: //,
dialog_node: 'greeting',
new_dialog_node: 'greeting',
new_output: {
text: 'Hello! What can I do for you?'
//add more than one text
}
};
assistant.updateDialogNode(params, function(err, response) {
if (err) {
console.error(err);
} else {
console.log(JSON.stringify(response, null, 2));
}
});
the API only accepts object type text:'Hello! What can I do for you?' this also overwrites the previous response
the error [ { message: 'output should be of type Object', path: '.output' } ]
How can I update the Dialog and add multiple responses at the same time or update the existing one?
thanks in advance!
Have you tried the following format for new_output?
{
"text": {
"values": [
"first response",
"second response"
],
"selection_policy": "sequential"
}

Issue with Hapi-jwt: Hapi-jwt authentication not running the handler function

I am not sure why, but I am having an issue implementing JWT authentication on my API. I'm using the https://www.npmjs.com/package/hapi-jwt package.
Creating the token works without issue, I'm getting a reply back on my /api/v1/login (auth) route, giving me a status:200 and the token:hash.
However, using my basic validation function on any route causes the route's handler to no longer run, and instead the validation function replies with the {"credentials": ... } object.
I'm also using Good and good-console, but I don't believe they are causing any problems in this.
Here's the server code (in the order it appears in my index.js file):
// SERVER SETUP
var server = new hapi.Server();
server.connection({ port: hapiPortNo });
// JWT SERVER REGISTRATIONS
server.register(require('hapi-jwt'), function(err) {
if(err) throw err;
server.auth.strategy('simple', 'bearer-access-token', {
validateFunc: auth.validateJWT,
secret: jwtCodeString
});
});
function defaultHandler(req, reply) {
reply('success!');
}
server.route({
method: 'GET',
path: '/',
handler: defaultHandler,
config: { auth: 'simple' }
});
server.route({
method: 'POST',
path: '/api/v1/login',
handler: auth.authHandler
});
server.register({
register: good,
options: {
reporters: [{
reporter: require('good-console'),
args: [{ log: '*', response: '*' }]
}]
}
}, function (err) {
if(err) {
throw err;
}
// START SERVER
server.start(function () {
server.log('info', 'Server running at: ' + server.info.uri);
});
});
And these are my auth and validation functions (kept in a seperate file, ./lib/auth.js and imported as a requirement):
//Authentication
function authHandler( request, reply ) {
var data = request.payload;
var tokenData = {
"user": data.user
};
var encoded = jwt.sign( tokenData, _codeString);
reply({ "status": 200, "token": encoded });
}
// Validation
function validateJWT( decoded, request, next ) {
var isValid = false;
if(decoded.user == 'me') {
isValid = true;
}
return next(null, isValid, {token: decoded} );
}
The hapi server runs without issues and replies all my routes' data normally when I drop the config: { auth: 'simple' } but for some reason adding authentication is resulting in every route replying with:
{
"credentials": {
"token": {
"user": "me",
"iat": 1425689201
}
}
}
Any thoughts? I'd be open to switching to another JWT auth package if someone has a recommendation.
The issue is with the hapi-jwt plugin, it hasn't been updated to work with hapi 8. Line 81 should be changed from
return reply(null, { credentials: credentials });
to
return reply.continue({ credentials: session });
You can either create a issue in the repository of hapi-jwt and ask the author to update the module, or you can try to use an other module like hapi-auth-jwt2 which is compatible with hapi 8.

Magento Soap cart.info isn't working for all carts

I am having a node application and I need a few informations about a shopping cart from a magento customer. So I wrote myself a little test script to test the results of the soap api (I am using magento to help me communication with the soap interface).
var MagentoAPI = require('magento');
var magento = new MagentoAPI({
host: '192.168.73.45',
port: 80,
path: '/magento/api/xmlrpc/',
login: 'dev',
pass: '123456'
});
magento.login(function(err, sessId) {
if (err) {
console.log(err);
return;
}
magento.checkoutCart.info({ quoteId: 696 }, magentoCallback);
});
function magentoCallback(err,response) {
if (err) {
return console.log(err);
}
console.log("Result: ");
console.log(response)
}
This script works fine. If I use some old quote ids (which are in the database from the sample data) I get a good result, but if I use an shopping cart from an user I created, then I get the following error:
{
"original": {
"message": "Unknown XML-RPC tag 'BR'",
"name": "Error"
},
"name": "Magento Error",
"message": "An error occurred while calling cart.info"
}

Resources