Stripe Payment in Javascript createToken callback not calling - javascript

In the following code, I have a problem where Stripe is not processing the payment. I'm getting all the values from the form correctly, however in the stripeResponseHandler function nothing is logging. I'm using the test credit cards available on their website and I successfully used it a couple of times prior to this error.
I loaded the https://js.stripe.com/v2/stripe-debug.js into my javascript and it was logging in the chrome console that "It looks like Stripe.js was loaded more than one time. Please only load it once per page.", however I only setPublishableKey here within this JS file and load
Stripe.setPublishableKey('pk_test_TK18ZwUnK2CT1Wmof8WsQl8S');
var payMeal = function(){
console.log("inside the paymeals function");
var x = document.getElementsByClassName("form-payment");
console.log("Number is " + x[0].value)
console.log("CVC is " + x[1].value)
console.log("Exp_Month is " + x[2].value)
console.log("Exp_Year is " + x[3].value)
console.log("The Stripe Object is",Stripe)
Stripe.card.createToken({
number: x[0].value,
cvc: x[1].value,
exp_month: x[2].value,
exp_year: x[3].value
}, stripeResponseHandler)
window.location.href = "../../meals"
};
var stripeResponseHandler = function(status, response){
console.log("IM IN THE RESPONSE HANDLER!!!!+++++***")
if(response.error){
console.log("THERE IS AN ERROR!!***")
console.log(response);
}
else{
console.log("submitting ajax to server with token");
token = response.id;
ajaxToServer(token);
}
}

Related

Vertx-js Event bus not receiving data from sender

I have used vertx-js event bus example from official github repository under the core examples.
Even though its not sending data from sender to receiver.
Sender.js
var eb = vertx.eventBus();
// Send a message every second
vertx.setPeriodic(1000, function (v) {
eb.send("ping-address", "ping!", function (reply, reply_err) {
if (reply_err == null) {
console.log("Received reply " + reply.body());
} else {
console.log("No reply");
}
});
});
Reciever.js
var eb = vertx.eventBus();
eb.consumer("ping-address", function (message) {
console.log("Received message: " + message.body());
// Now send back reply
message.reply("pong!");
});
console.log("Receiver ready!");
I Have used the following method to run a program .
vertx run reciever.js -cluster
vertx run sender.js -cluster

Notification not displaying supplied image

I'm trying to show a notification using an image I receive over a socket as an arrayBuffer. The notification shows, but without the image supplied. The standard firefox logo/icon is used instead. Any help would be appreciated. The code seems to run without any errors, or rather, no errors are are thrown/stack trace printed when the notification is created.
Here is the code to create the notification:
ps_worker.port.on("notification", function(notification){
//DISPLAY LINK TO USER
var arrayBuffer_icon = notification.icon;
var arrayBuffer_largeicon = notification.largeicon;
var str = String.fromCharCode.apply(null,arrayBuffer_icon);
var base64String = utils.btoa(str).replace(/.{76}(?=.)/g,'$&\n');
var dataUri = "data:image/png;base64,"+ base64String;
notifications.notify({
title: notification.app + ": " + notification.title,
text: notification["subject"] + "\n" + notification.content,
data: "did gyre and gimble in the wabe", // data is a string passed through to the on click listener
iconURL: dataUri,
onClick: function (data) {
console.log(data);
}
});
});
the utils.btoa call is implemented as described here: https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Unit_testing
The relevant server code is (node.js):
function send_notification_to_socket(user, notification, target){
fs.readFile(notification.iconpath, function(err, buf){
if(socketstore.get_socket_by_id(user)){
socket = socketstore.get_socket_by_id(user);
notification["icon"] = buf;
socket.emit('notification', notification);
}else{
console.log("No socket for user " + user);
}
});
}
Any ideas on what I might be doing wrong?

Google+ signinCallback called twice and losing authresult in process

There is a bug in my code.
I am able to sign in and retrieve user information. But the signinCallback is called again(I don't know how). And it shows User information that I had earlier is gone!
Here is the HTML side:
<span id="signinButton">
<span
class="g-signin"
data-callback="signinCallback"
data-clientid="CLIENT_ID"
data-cookiepolicy="single_host_origin"
data-requestvisibleactions="http://schemas.google.com/AddActivity"
data-scope="https://www.googleapis.com/auth/plus.profile.emails.read"
data-width="standard"
data-height="short">
</span>
</span>
and here is the javascript side:
var AuthStates = {
google: null
};
function signinCallback(authResult) {
console.dir(authResult);
console.log('Sign-in state: ' + authResult['error']+authResult['access_token']);
AuthStates.google = authResult;
console.log('signinCallback');
chooseAuthProvider();
}
function chooseAuthProvider() {
if (AuthStates.google && AuthStates.facebook) {
if (AuthStates.google['access_token']) {
// Signed in with Google, you can now use Google+ APIs.
console.log(AuthStates.google);
gapi.client.load('plus','v1', function(){
var request = gapi.client.plus.people.get({
'userId': 'me'
});
request.execute(function(resp) {
document.getElementById('cname').value =resp.displayName;
document.getElementById('cemail').value =resp.emails[0].value;
console.log('Retrieved profile for:' + resp.displayName + ' ' + resp.emails[0].value);
});
});
}
}
It gives this response to the console on the second signinCallback
Sign-in state: user_signed_outundefined
signinCallback
Try updated instructions at
"Integrating Google Sign-In into your web app" page.
Your call to request.execute() in your callback method is causing the callback method to be re-triggered with "user_signed_out" value in the error property.
If you take a look at the Google documentation "Signing out the user" it reads:
When the user refreshes the page or navigates to another part of your
website, the callback will fire with user_signed_out value in the
error property until the user clicks the sign-in button again.
Hence I believe it is your call to request.execute() which is triggering the second call to the callback method.
You can guard against this second call to the callback by putting a condition within the callback method e.g.
function signinCallback(authResult) {
if (authResult['status']['signed_in']) {
console.dir(authResult);
console.log('Sign-in state: ' + authResult['error']+authResult['access_token']);
AuthStates.google = authResult;
console.log('signinCallback');
chooseAuthProvider();
}
}
See Google's documentation on "Monitoring the user's session state" for an example of the previously mentioned guard conditions.
This might be helpful for you
(function() {
var GOOGLE_PLUS_SCRIPT_URL = 'https://apis.google.com/js/client:plusone.js';
window.oauth2Callback = function(authResult) {
if (authResult['access_token']) {
accessToken = authResult['access_token'];
$(function() {
$.getScript(GOOGLE_PLUS_SCRIPT_URL);}

Facebook post custom action to timeline

I have created a custom action that I want to allow users to post to their timeline with e.g. {User} read {Article}. I can get this to work fine when I do a post using the sample URL like this :
FB.api('/me/fbsite:actionname' +
'?object=http://samples.ogp.me/356694057772404&access_token=abc','post'
But when I replace the sample URL with my own URL I get the error 'The session was invalidated explicitly using an API call'. Can anybody please advise?
EDIT : Changed my Javascript to this, but I now get 'Invalid OAuth Access Token' :
<script type="text/javascript">
function redeem() {
FB.api('/me/fbsite:actionname' +
'?object=http://samples.ogp.me/356694057772404&access_token=\' + <%=UserManager.Current.FB.accessToken %> + \'', 'post',
function (response) {
var msg = 'Error occured';
if (!response || response.error) {
if (response.error) {
msg += "\n\nType: " + response.error.type + "\n\nMessage: " + response.error.message;
}
alert(msg);
}
else {
alert('Post was successful! Action ID: ' + response.id);
}
});
}
That might be because you are using the same access token in same session. So try logging out and log back in, get a new FB access token, and try the query using the new access token you got, that should work as expected.

Facebook FQL returns NaN value

In this script
function fql(){
FB.api('/me', function(response) {
var query = FB.Data.query('select uid, name, email from user where uid={0}', response.id);
query.wait(function(rows) {
document.getElementById('name').innerHTML =
'Your name: ' + rows[0].name + "<br />" +
+ rows[0].email + "<br />" + rows[0].uid;
});
});
}
Function returns name and pic, but email value is NaN. App requires basic data and email (it was set in app properties/Auth dialog) but i cant get user email.
When I tested this query in Facebook test console, I've got email field with correct value.
Check that in Test Console and on your site you use the same application id and ensure that user have granted the email permission to your application!
This can be done with simple Graph API call:
FB.api('/me/permissions', function(response){
if (response && response.data){
var userPermissions = response.data.shift();
if (userPermissions.email){
alert('User is granted email permission');
} else {
alert('User is NOT granted email permission');
}
} else {
// No response or results from the Graph API
}
});
Couple of things you should be aware of!
FB.Data.* is gone! It's deprecated, undocumented and should not be used anymore! It's just a matter of time for it to disappear from the JavaScript SDK code...
You just doesn't want extra call just to figure the id of current user (most chances that you already have it, just check FB.getUserID()), in FQL use me() to refer to current user.
Rewrite your usage of FB.Data.* and query.wait with:
FB.api('/fql', {q:'YOUR_FQL_QUERY_HERE'}, function(response){
var rows = response.data;
});
In your case same results may be received by Graph API call without usage of FQL:
FB.api('/me', {fields: 'id,name,email'}, function(response){
// response -> {id: UID, name: 'User Name', email: 'user#email.dz'}
console.log(response);
});

Categories

Resources