How to parse error with Square Connect API example (Node) - javascript

I am trying to learn how to process payments with Square, and am trying to run their examples from GitHub to get a feel regarding how to structure the payments application. I built the node example from here: https://github.com/square/connect-api-examples/tree/master/connect-examples/v2/node_payment using npm install and npm build to get the app up and running.
I am using "4532759734545858" for the card number, "123" for CVV, "0120" for expiration, and "94103" for the zip. I got the card number from here: https://docs.connect.squareup.com/articles/using-sandbox where it states that this is a good number to use for a Visa sandbox.
Also, I have updated the config.json with properties from my developer settings.
When trying to process a payment a get a DOM element that says "Card Declined" without further specifying the error. Is there something I can do to parse the error?
Based on the documentation at: https://docs.connect.squareup.com/articles/using-sandbox#generatingerrorstates it seems the amount_money field of the request is not being populated, but I am having trouble confirming.
Ideally I would like to get to a point where I can add a card as a hash value to my db and use it for recurring billing...

That "card declined" message is actually the error you get back from Square's APIs. You can play around with the error messaging in the app.js file and the `error.jade. Try error.catagory, code, detail.
Keep in mind that this is just a sample app, to show that you can use the APIs with node.js, you probably don't want to use this code in your production system.

Related

ApplicationInsightsTelemetryClient not logging bot identifiers

I'm using the JavaScript version of the botframework. I've followed the documentation to enable telemetry logging in Application Insights. When I access the logs I can see that custom events are being logged.
The issue is that the bot specific identifiers, such as user_Id, session_Id and conversation_Id are not being logged. This can be seen in the screen capture below
In the applicationInsightsTelemetryClient.js file there is a function called addBotIdentifiers. As far as I can tell, it is this function that is responsible for adding the bot specific identifiers.
The first lines of the function look like this:
function addBotIdentifiers(envelope, context) {
if (context.correlationContext && context.correlationContext.activity) {
Inspecting this function shows that the context argument is always null.
This leads me to my questions.
Why is it null?
Any suggestions on what I need to do to have it set appropriately?
Update
In digging into this further it appears the code starting at line 26 in the applicationInsightsTelemetryClient.js file isn't being called. Could this be the cause of the missing context later on in the addBotIdentifiers function?
Looks like the documentation has a missing line in step 7. We will correct the document ASAP. Meanwhile, please add the below in your index.js following https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/javascript_nodejs/21.corebot-app-insights/index.js#L113
// Enable the Application Insights middleware, which helps correlate all activity
// based on the incoming request.
server.use(restify.plugins.bodyParser());
Further investigation has shown what the issue was. It's not immediately obvious.
I compared the code in my index.js file with the one in the 21.corebot-app-insights BotBuilder sample.
Note that the setup of the Restify server happens after the creation of the adapter bot adapter. It is also after the configuration of the main dialog and the middleware.
In my code the setup of the Restify server and the bot adatper / dialogs was intermingled. This appears to have been the cause of the problem.
The main lesson here for me, and for anyone who stumbles across this post later, is that the setup of the Restify server should be at the end of the index.js file. To ensure all of the bot framework is setup first.

protractor - after browser.restart basePage.js ref is lost

I am automating angularjs application which is based on basic authentication.
after every test i need to delete cookies and restart my browser so that i can login with different user.
To do this i am using browser.restart() method of protractor
However whenever i perform browser.restart(), my basePage.js references are lost and eventually i get 'This driver instance does not have a valid session ID'
my framework structure is as below
features
--feature1
pages
-page1.js
-page2.js
--basePage.js
step_definations
--step1.js
support
--world.js
--hooks.js
i am using
cucumber-js
javascript language
POM
protractor 5 version
nodejs
After reading lots of posts, i got to know about reinitialize basePage.js in world.js so that its references are recreated. But i am not able to understand how to do this?
for session
browser.executeScript('window.sessionStorage.clear();
If you found cookies is only issue
try this
browser.driver.manage().deleteAllCookies();

How to migrate the database in sails.js?

So I created a new Sails.js project, then ran
$ sails generate api user
like the loading page suggested. But now when I fire up the server with sails lift I get an error:
sails lift
info: Starting app...
-----------------------------------------------------------------
Excuse my interruption, but it looks like this app
does not have a project-wide "migrate" setting configured yet.
(perhaps this is the first time you're lifting it with models?)
In short, this setting controls whether/how Sails will attempt to automatically
rebuild the tables/collections/sets/etc. in your database schema.
You can read more about the "migrate" setting here:
http://sailsjs.org/#/documentation/concepts/ORM/model-settings.html?q=migrate
In a production environment (NODE_ENV==="production") Sails always uses
migrate:"safe" to protect inadvertent deletion of your data.
However during development, you have a few other options for convenience:
1. safe - never auto-migrate my database(s). I will do it myself (by hand)
2. alter - auto-migrate, but attempt to keep my existing data (experimental)
3. drop - wipe/drop ALL my data and rebuild models every time I lift Sails
What would you like Sails to do?
info: To skip this prompt in the future, set `sails.config.models.migrate`.
info: (conventionally, this is done in `config/models.js`)
Is there a sails migrate command I have to run? I know in rails I would do something like rake db:migrate. What's the procedure in sails after the generate command?
It's not an error, it just tells you that you did not specify a default migration strategy.
Just open config/models.js
and uncomment the line where it says migrate like in the picture above.
Like the information "popup" tells you, you can choose between
safe
alter
drop
Drop will delete all your tables and recreate them, which is good for a new project and you want to seed new dummy data all the time.
Alter will try to keep your data but will make changes to your tables if you do so in your models. If sails can't keep the data, it will be deleted.
Safe is, like the name says, the safest. It will do just nothing to your tables.
If you want to take different action for different tables, you can specify just the same options within your model directly which will overwrite the default setting for this model only.
So say you have a User model and want to keep that data but want to have all other models recreated everytime you sails lift, you should add
migrate: 'safe'
to the model directly and use drop as default strategy.
I like alter personally, but that might be opinionated.
You do not need to make anything else. If there's a model and migrate is set to drop or alter, it will be migrated when sails lift is run.
You can read more about model settings here
As a sidenote, you can see what sails is doing exactly to your tables during lift by setting
log: 'verbose'
in your config/env/development.js file:

How to make per user base logging with hapi js

I am using winston logging framework and logging on basis of log level, but now i am facing difficulties in tracking down bugs. So we decided to make logging on per user basis, and this is where i ran into problem.
What i want to acheive?
log file for every user will be generated on every hour. (We can skip every hour constraint in this thread) and every user has unique identifier 'uid'.
What i have?
I have followed architecture as used here 'https://github.com/agendor/sample-hapi-rest-api'. Some additional lib modules exist too.
Currently i am using winston library (but i can afford to replace this if needed).
Brief introduction of flow
Currently, i have access to request object in handler function only, but i want to log events in DAO, library functions too ( on per user basis). 'Uid' is available to me in handler function in request object as i put uid in request in authentication middleware.
My solution (which is not elegant)
pass request object ( or only uid) to every function and log (using winston) event. Custom transport will determine where (in which file, on basis of uid) to put the log.
Certainly, this is not elegant way as every function must have uid parameter in order to log event, which seems bad.
What i want from you?
A better, elegant approach which is scalable too.
Related post: https://github.com/hapijs/discuss/issues/51
Try taking a look at Continuation-Local Storage:
https://github.com/othiym23/node-continuation-local-storage
Heres a good article on implementing it within express:
https://datahero.com/blog/2014/05/22/node-js-preserving-data-across-async-callbacks/

Access server files with ArcGIS javascript api

I have a geoprocessing service that takes two parameters: netCDF (file) and Date (str). I'm working off of the demo found here.
The issue I have is getting the netCDF file to the geoprocessing service. By creating an upload feature I can see how I would be able to provide the needed parameter but I already have all the necessary files server side.
How can I get my web application to read local netCDF data into the geoprocessing service?
Any suggestions would be greatly appreciated.
My testing application can be found here.
Service: http://sroarcgis.ducks.org/ducksunlimited/rest/services/wsi_tool/GPServer
I receiver the error message: Error {code: 400, message: "Invalid or missing input parameters.", details: Array[0], log: undefined, httpCode: 400}
Thanks!
I'm not sure if this applies to your geoprocess, but I got this same error message and I finally fixed my problem:
Make sure you have the same fields in the search results as you have in the table the search is linked to.
It was a simple fix that took me awhile to find (as these things usually go). I had included a field that was visible in other tables, but that I had had turned off in this table before publishing the map.
Hope this helps!
After speaking with ESRI support they said that I would need to enable uploads on my web server, then upload each file individually.
Regarding your "Invalid or missing input parameters." error, you may be able to resolve this error using the following steps:
Log into ArcCatalog
Create a database connection as the user who is the owner of the table.
Select the table in the Catalog Tree.
Click the Preview tab. (Not sure if this step is really needed, but it will confirm that the metadata was refreshed properly.)
This error can crop up if the table columns change in some way. I think this process refreshes the SDE Metadata associated with the table.

Categories

Resources