Braintree/PayPal Version 3 Upgrade issue - braintree

I just tried to upgrade to v3 version of BrainTree/Paypal and getting error on braintree.client.create call (braintree.create is undefined).
I am pointing to the following JS files - https://www.paypalobjects.com/api/checkout.js
https://js.braintreegateway.com/web/3.33.0/js/client.min.js
https://js.braintreegateway.com/web/3.33.0/js/paypal-checkout.min.js
JS code -
braintree.client.create({
authorization: token
}, function (err, clientInstance) {
// ...
});
Any idea why this could be happening?

Related

AJAX posting issue in React JS

I have been doing React JS a while, but only front-end. Now I would like to spice it up with external data. So I tried with AXIOS / FETCH unfortunatelly both of them produced this miserable result. Here is the challenge:
fetch("http://localhost:8080/backend/datatest/src.json", {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Hubot',
login: 'hubot',
})
})
fetch('http://localhost:8080/backend/datatest/src.json')
.then(function(response) {
return response.json()
}).then(function(json) {
console.log(json)
})
Its basicly a copy-paste from GITHUB of fetch, assuring nothing would go badly. "GET" function works perfectly, but i got problems with POST-ing. I keep getting back the same error mesage
POST http://localhost:8080/backend/datatest/src.json 404 (Not Found)
HOWEVER! GET works perfectly.
I am using React JS, Redux, node JS. This JSON file didnt get installed at any server. In your opinion what would be the next step.
Regards,
Koppany

How to configure Twilio on parse server?

I am attempting to incorporate Twilio into my application that is running on my parse server deployed with Heroku and MongoLab. I am trying to configure by using this code in my cloud/main.js file
var twilio = require("twilio");
twilio.initialize("87se46bovanw4v5aiwy4o57","ia8o57awyov57yn875vyboe");
Parse.Cloud.define("inviteWithTwilio", function(request, response) {
// Use the Twilio Cloud Module to send an SMS
twilio.sendSMS({
From: "6543211234",
To: 8065456703,
Body: "Start using Parse and Twilio!"
}, {
success: function(httpResponse) { response.success("SMS sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});
});
however, I get this response
UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.} [NSDebugDescription: JSON text did not start with array or object and option to allow fragments not set.]
I have determined that the problem lies in the first two lines when trying to initialize Twilio. I figure this is because the Twilio Cloud Module isn't integrated into my parse server like it was with Parse Hosted cloud code, but I'm not sure. How can I fix this problem? Thanks for your time.
Twilio developer evangelist here.
It sounds like, from our conversation in the comments, like you have not installed the Twilio npm module just yet. On Parse, you didn't have to install the module as it was included by default. To use the Twilio module using Parse server you need it installed.
To install the module, open up your application in the terminal and type:
$ npm install twilio --save
The --save flag is important as it saves the dependency to your package.json file. Check in the updated package.json and deploy your code again. Now, when deploying to Heroku the npm modules, including the Twilio module, will be installed.
Marin, who already answered as well, had a good point. I also recommend using twilio.sendMessage. It uses the newer and better featured Messages resource (rather than the deprecated SMS resource).
Let me know if this helps at all.
I think this is problem for Twilio version.
you should use twilio.sendMessage.
var twilio = require("twilio");
twilio.initialize("87se46bovanw4v5aiwy4o57","ia8o57awyov57yn875vyboe");
Parse.Cloud.define("inviteWithTwilio", function(request, response) {
// Use the Twilio Cloud Module to send an SMS
twilio.sendMessage({
From: "6543211234",
To: 8065456703,
Body: "Start using Parse and Twilio!"
}, {
success: function(httpResponse) { response.success("SMS sent!"); },
error: function(httpResponse) { response.error("Uh oh, something went wrong"); }
});
});
Hope to help you.
Thanks
///////////////////////////////
Here is my code work fine.
Parse.Cloud.define("sendSMS", function(request, response) {
console.log(request);
var twilio = require("twilio")("ACCOUNT_SID","AUTH_TOKEN");
twilio.sendMessage({
to: request.params.number,
from: request.params.from,
body: request.params.message
}, function(err, responseData) {
if (err) {
response.error(err);
} else {
response.success("SMS sent.");
}
});
});

Can't make ajax POST calls with an express site running on Heroku

I've recently deployed an express app to heroku which was working fine locally. Now, on heroku, the parts where I make ajax post call are breaking with 500 Internal Server Errors.
In my JS my POST call looks like this:
$.post('/api/', {
'input': 'input'
}, function(data) {
if (!data) {
return console.log('success');
} else {
return console.log('failed');
}
});
And it's treated by express like this (I'm abstracting here):
app.route('/api/')
.post(function (req, res) {
var input = req.body.input;
x.doSomething(input,function (err,data) {
res.send(err);
}
});
After some googling I suspected it might have to do with Access-Control so I added some code to my express app which enabled Access-Control-Origin from everywhere. This stopped the 500 errors and instead caused the post to hang and then timeout after 30 seconds.
I assume this is something to do with Heroku because it's all working fine locally. Any suggestions would be super helpful.
** EDIT **
I've done some more digging and it turns out it's the line var = req.body.input that's causing all the trouble. If I remove this, I don't the 500 error. Another clue, is that in the breakdown of the 500 error, it seems there's some kind of crossDomain sending going on - jquery states in the first line of the error: l.cors.a.crossDomain.send. So something's clearly amiss here and I'm pretty sure it's not to do with the way I've written the ajax call...

request.xhr undefined in Ext JS

my web site is made using Ext JS 4.1 framework and ASP .Net MVC v3. When new frame is rendered there are 19 separate AJAX requests for retrieving data in JSON-format. All requests are familiar and made by Ext.Ajax.request(). Example:
Ext.Ajax.request({
url: getOrderLink,
method: "GET",
params: { recId: orderRecId },
headers: {
'Accept': 'application/json'
},
success: function (response) {
var order = Ext.decode(response.responseText);
...
}
});
In some cases there are errors in ext-all.js in
onStateChange : function(request) {
if (request.xhr.readyState == 4) {
this.clearTimeout(request);
this.onComplete(request);
this.cleanup(request);
}
},
where request has no property xhr so that request.xhr.readyState throws exception "Cannot read property 'readState' of undefined".
This errors appear not for all requests and don't effect site work(responses are retrieved successfully). Some times this errors don't appear at all. Timeout for all requests is set to 30s by default and they take about 1.5-2 seconds each.
I am using Google Chrome 21.
Could you please give me some idea why it's happening.
The problem seems to occur if and only if you have a breakpoint or a "debugger;" line in anything related to AJAX. For me it happened in Chrome, haven't tried other browsers yet.
In my case it happened when I had set a breakpoint in a load event handler for a store like code example below.
But the error occurrs if you set a breakpoint inside the Ext onStateChange function in the framework itself as well.
If disabling your breakpoints and debugger; calls removes the error you can safely ignore it!
There is a similar thread on ExtJS forums. Sencha might add a fix.
Ext.define('MyApp.controller.MyController', {
extend: 'Ext.app.Controller',
stores: ['Projects'],
init: function () {
this.getProjectsStore().addListener(
"load",
this.onProjectsStoreLoaded,
this
);
},
onProjectsStoreLoaded: function () {
console.log('MyController: onProjectsStoreLoaded');
debugger; // <- this causes the errors to appear in the console
SomeOtherThingsIWantedToDebug();
}
}

Dojo Reading file through xhrGet

I am trying to run an xhrGet like this one:
dojo.provide("test");
dojo.declare("test",null,{
getVersion: function(){
details =
{
url: "../version.txt",
content: "test",
handleAs: "text",
timeout: 4000,
load: function(data)
{
console.log("result" + data);
},
error: function(error)
{
console.log("Error" + error);
}
}
var dfd = dojo.xhrGet(details);
return dfd;
});
and I am getting this error:
Error: Deferred Cancelled: [Exception... "Component returned failure code: 0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIXMLHttpRequest.send]" nsresult: "0x80520012 (NS_ERROR_FILE_NOT_FOUND)" location: "JS frame :: file:///C:/Dojo1.4.3/dojo/_base/_loader/bootstrap.js :: anonymous :: line 1351" data: no]
file:///C:/Dojo1.4.3/dojo/_base/_loader/bootstrap.js
Line 0
The file I am trying to retrieve is relative to dojo, therefore is located under Dojo1.4.3/version.txt
Other note.... I am not running it on a server, I am simply loading the html file with reference to the dojo class I have created.
thank you all for your time
EDIT
SOLUTION
I found the solution
https://developer.mozilla.org/en/Same-origin_policy_for_file%3a_URIs
you need to enable this policy in Firefox
You cannot do AJAX requests if your page is being served directly via file://, for security reasons or something like that. You will need to set up a HTTP server and serve your page via that.
Also, is there any particular reason why you are using an old version of Dojo here? The current version is 1.7

Resources