Stripe.js was not loaded correctly - javascript

I'm loading stripe into my payment page like so:
<script src="https://js.stripe.com/v3/"></script>
This works perfectly in my local test environment but in production, the following console error appears:
Uncaught Error: It looks like Stripe.js was not loaded correctly
at new e (controller-84824401a25a5595fc578f767b4d5c27.js:1)
at controller-84824401a25a5595fc578f767b4d5c27.js:1
at Object.bnjt (controller-84824401a25a5595fc578f767b4d5c27.js:1)
at t (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
at Object.3 (controller-84824401a25a5595fc578f767b4d5c27.js:1)
at t (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
at window.webpackJsonp (shared-d3604a85e14ef273096e09821a0e4c2a.js:1)
at controller-84824401a25a5595fc578f767b4d5c27.js:1
I can't work out what might be causing the error. I'm using HTTPS in production and can see the JS file source downloading successfully. Any tips?

Solved following advice from #NathanCasebolt. SO mods deleted his original answer:
“For me, the resolution to this error was as simple as spell-checking
my variables. In my backend server code, one of my variables was
wrongly capitalized. Since the misspelled variable was part of the
function that retrieves my publishable key, the key returned from the
server as null. This, in turn, disrupted creation of the Stripe object
and threw this error. If I were you, I'd check to make sure (1) that
the publishable key on your frontend matches the publishable key in
your dashboard, and (2) that you're not doing anything that might
disrupt serving this key to Stripe.”
The StackOverflow mods felt this didn’t answer the question and
required too much clarification. So, to clarify, the problem for me
was this line:
var stripe = Stripe(‘{PUBLISHABLE_KEY}’);
I set things up to retrieve my publishable keys from my server, to
give me more flexibility in switching between test keys and live keys.
Since my one of my server variables was wrong, I was providing Stripe
with a bad key (no key, really), and that’s what threw the error. This
is why I suggest you check the publishable key you’re using to create
the Stripe object, to make sure that the one you’re using to create
the object is there, and that it matches the publishable key you have
on your Stripe dashboard."
In my case, this is exactly what I'd done wrong: provided an empty publishable key when initialising Stripe. Ultimately a very simple mistake compounded Stripe's obtuse error message.

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.

Is it possible to get request information from a rxjs-timeout-error?

I'm trying to improve our current implementation of error handling and one part of it is the better description of errors in general and also in testing environments. I do this for an Ionic app but since my problem lies within the rxjs timeout-method, I think this is neglectable.
One part im currently stuck on is the correct visualization (error message) of timeout errors since they don't seem to contain anything of value at all. I'd like to show to the user which request was the origin of the timeout error when the error happens and the user sees. In the case of testing environments additional thinks like url, device-version, etc. should be shown as well.
But all the Timeout-Error contains seems to be a stacktrace of the javascript library beneath handling the post request.
So, my question is if there is a way to add or retrieve additional information from an rxjs timeout error?
Below you can see how the TimeoutError from rxjs looks for me.
Thanks!
TimeoutError has nothing to do with values emitted by the source Observable. Still, it's thrown when there are no emissions from the source so what how could it contain any information anyway.
What you can do however is use catchError to get the error that produced, turn it into another error and send it further with throwError:
...
catchError(e => throwError({...e, ...whatever}))
You can for example check whether the error is an instance of TimeoutError and if it is the do something with it.

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/

How do I insert a Braintree clientToken?

The Braintree documentation says you create an environment as in their example var gateway=braintree.connect(environmental variables) and then create a clientToken by doing
gateway.clientToken.generate({}, function (err, response) {
var clientToken = response.clientToken;
});
Then their example says to insert the client token into the form used for payment
braintree.setup("CLIENT-TOKEN-FROM-SERVER", "custom", {id: "checkout"});
but they also state that clientToken is an object. I do not see anywhere how to get the token value and the return value is only a boolean. I do find that gateway.clientToken is reported as an object by using typeof().
On Stackoverflow, I see a couple of people saying the clientToken object is supposed to be a base64 encoded value but how you do this? Shouldn't Braintree's code do that?
So I'm missing a step somewhere or I can't find the right documentation but I'm definitely lost.
EDIT: Going by the response from Braintree, in the answers below, clientToken is not being filled by response.clientToken in any of the forms I've attempted this, which is many. Looking at examples from all over the web, which are few,and Braintree's light documentation, looks like I'm doing everything right.
EDIT2: My solution to the problem is in my answer below.
The problem lies in where you put the code to interact with Braintree within any node.js calls you make. In my case, I had it inside http.createServer so I could write values out while debugging this but some part of all this won't let that work. I haven't figured the exact details yet.
Also, the example code from Braintree shows clientToken inside the gateway.clientToken.generate() call which would lead me to think that's where it belongs even while not understanding how I was to extract that token value. So moving clientToken outside of that call, something I thought I once tried, solved this at least in part.
I say "in part" because you are to create a new token with every new customer and that can't be accomplished this way. I still need to determine how to generate a new token with every new customer visit. It may be only a matter of making it another function call but I haven't tried it yet.
In addition, I'm still not clear about whether a new customer needs to be created. I read the answer is no but I've also read the answer is yes so confusion reigns but this is probably a different question topic.
I work at Braintree. If you have more detailed questions, please get in touch with our support team.
It sounds like you're confusing gateway.clientToken which is the object that allows you to get a client token, and the client token itself, which is what is received by gateway.clientToken.generates callback -- response.clientToken.
Once you have the token (here, var clientToken), you need to get it to your client. From the "Hello, Server!" docs:
There are a number of ways to get your client token into JavaScript so you can setup Braintree. Many people choose to interpolate the client token into the view which contains the JavaScript to setup Braintree.

Twitter error with Hello.js

I've seen a few people having problems with the oAuth1.0 using hello.js with Twitter, LinkedIn etc. Unfortunately, I am one of them. Trying everything I can to fix it, but I need help.
To explain:
I have my Twitter credentials initialised:
hello.init({
'twitter' : '*******************'
},
{
redirect_uri:'****************',
oauth_proxy: 'https://auth-server.herokuapp.com/proxy'
});
(I presume that the 'oauth_proxy' in my case here is correct?)
Apart from that, I have tried calling the function in the button tag like so:
onclick="hello.login('twitter');">
I have seen people making errors having skipped the 'https://auth-server.herokuapp.com/#signin' step but I have all my credentials inputted there for the mean time. But, one question:
The 'Reference' section, is that just a nickname kind of thing? And what's the 'Domain' section about?
The error that I'm receiving is a 401 error message.
Another question:
Do I need all of the 'twitter.js' & 'client_id.js', or is including 'hello.js' sufficient?
I appreciate any effort to help me with this. Thank you.
As Andrew said (after all, he is the one who wrote hello.js), one of the problems could be related to the callback URL. I found out after a while that Twitter (unlike Facebook) does not accept 'localhost', so instead one has to write 127.0.0.1.
That solved all my problem when being stuck at the same point.
So yes, the reference is a nickname e.g. "dropbox", and the domain field is the domains e.g. "myapp.com". Its advised to fill both these in for your own reference and their misconfiguration wont lead to a 401.
The 401 is likely that your client id / secret is incorrect. Or the redirect_uri defined in hello.init does not match the Callback URL you assigned to that client id when you registered with a third party service.
The error handler hello(network).login().then(successHandler, errorHandler) should give more information. Can you attach that too your question?
"client_id.js" is a demo script which defines the credentials used for my hellojs demos. Do not include it!
However you may like this approach for maintaining your application credentials in a separate file - this approach is left up to you.
All you need to include to get started is dist/hello.all.js this contains hello js and all the third party configurations listed.

Categories

Resources