Braintree client-token validation error - ruby-on-rails

I am using braintree Drop-in UI with angularjs(frontend) and rails(Backend). I am creating a clientToken and sending it to braintree setup.
The client-token method,
#client_token = Braintree::ClientToken.generate(customer_id: current_user.braintree_customer_id,options: {
verify_card: true,
fail_on_duplicate_payment_method: true
})
So as you can see, I have taken 'fail_on_duplicate_payment_method' option. And trying to add the same payment method again.
Then, with that validation I am getting an error on the dropin saying "There was an error processing your request", but it is not coming to the error callback.
This is the setup, which is fine,
braintree.setup(vm.clientToken, 'dropin', {
container: 'dropin-container',
onPaymentMethodReceived: function(data)
{
alert('came recieved')
// console.log($scope.paymentForm)
vm.submit($scope.paymentForm, data.nonce)
},
onReady: function () {
vm.disablePay = false;
},
onError: function(type, message) {
alert('came error')
vm.serverError = message;
}
});
Here is the Image of the error,
The error in the network is,
callback_jsona7f3c885267b4f49aa13fbf01cecdb60({"error":{"message":"Credit card is invalid"},<br>"fieldErrors":[{"field":"creditCard","fieldErrors":[{"field":"number","code":"81724","message":"Duplicate card exists in the vault"}]}],"status":422})
I want to fetch this error into my view. I searched many links, but didn't get the answer I needed. Any help is appreciable.
Thankyou in Advance.

Full Disclosure: I work as a developer for Braintree
The onError callback is only triggered by client side errors and this is actually a server side error; however, the team is aware of this need and is working on a solution that will be available in a future release.

Related

Twilio chat member online status is always null

In my chat application I want to know if a channel member is online, but 'userInfoUpdated' never fires when a new member comes and member.userInfo.online is always null whenever I want to get it. What am I doing wrong?
UPD:
Here the code is paused on member "updated" even, the member's userInfo.online field is still null
UPD2:
Now I've found this line from the documentaion
Extended user information Note that UserInfo#online and UserInfo#notifiable properties are eligible to use only if reachability function enabled. You may check if it is enabled by reading value of Client~reachabilityEnabled docs
Finally setting reachabilityEnabled on the backend solved my problem
setting reachabilityEnabled on the backend solved my problem
Twilio developer evangelist here.
From your comment you say that your code is:
client.getChannelByUniqueName(uniqueName).then(channel => {
channel.getMembers().forEach(member => {
member.on('userInfoUpdated', ()=>{ //nothing happening })
})
})
I think I see the issue. channel.getMembers() returns a Promise that will asynchronously resolve with an array of Member objects. You're just calling forEach on the Promise itself. Try something like:
client.getChannelByUniqueName(uniqueName).then(channel => {
return channel.getMembers()
}).then(members => {
members.forEach(member => {
member.on('userInfoUpdated', ()=>{ // something happening? })
})
})
Let me know if that helps at all.
Yes, members will be null if you didn't synchronized chat client at client startup.
So you need to override this callback and make sure that client synchronization is completed before using chat client methods -like getChannels or getMessages-.
override fun onClientSynchronization(status: ChatClient.SynchronizationStatus?) {
if (status == ChatClient.SynchronizationStatus.COMPLETED) {
// You can use chat client now
}
}
You will receive an event to the client's listener or delegate via the synchronizationStatusUpdated method with a value of StatusCompleted. This is your indication the client is ready for business, and all User Channels have been obtained and subscribed to.
For more details please check this: Initializing SDK Clients

Parse Server + Stripe Connect - iOS

How do you setup Parse Server with Stripe Connect? I'm having a miserable time...
I'm trying to integrate my Parse Server (hosted on Heroku) with Stripe Connect (this is different that standard Stripe, in it allows you (the app) to transfer payments to a third party while taking a 'processing fee' while ONLY USING Parse Server + Xcode (as this is all that I'm familiar with).
For example, Lyft charges the customer's credit card, takes a percentage of the ride, and the remaining balance is transferred to the driver. How do I do this in Stripe automatically?!
Stripe's documentation did not give me an explicit example and I struggled for hours... Well, I finally got it and wanted to share it with you. Hope you all find this useful:
Assumptions:
You have an account on Stripe
You've added Stripe to your Parse Server example here. If you don't understand, message me for details.
You've added Stripe SDK to your Xcode project
You've setup Cloud Code on your Parse Server (again message if confused)
OK, so we are going to charge a credit card, pay the third party, but keep a 'fee'. First you'll go to the Stripe.com dashboard (click the top right of the screen, to view all of the options). Then click CONNECT and fill out the info.
IMPORTANT: YOU DO NOT NEED TO FILL OUT THE FIELDS "REDIRECT URI".
OK so now we need to create a CONNECTED STRIPE ACCOUNT. We do this by cloud code:
Parse.Cloud.define("createConnectedAccount", function(request, response) {
var stripe = require('stripe')('YOUR_SECRET_KEY');
stripe.accounts.create({
managed: false,
country: 'US',
email: 'example#gmail.com' //THIS IS YOUR THIRD PARTY ACCOUNT EMAIL ADDRESS
}, function(err, account) {
// asynchronously called
if (err) {
//other errror
response.error(err); // return error
} else {
//no error
response.success(account); // return charge success
}
});
});
This account is managed by the THIRD PARTY. When you run this code, it will create a Stripe account for this third party and send them an email (to the email listed). Basically, the email instructs them to Login, enter a password, and enter a bank account. When they activate the account, it will be 'connected' to your account.
Once connected, now it's time to write the "charge the card" method:
Parse.Cloud.define("charge", function(request, response) {
var stripe = require('stripe')('YOUR_SECRET_KEY');
stripe.charges.create({
amount: 100, //in CENTS
currency: "usd",
customer: request.params.customer, //customer is the id given by stripe when you create a customer. example: cus_EXAMPLE398FMFJKEP876
description: "example for people",
application_fee: 25, //again, in CENTS
}, {stripe_account: "3RD_PARTY_ACCOUNT_NUMBER"}, function(err, charge) { //the third party account number looks something like this acct_EXAMPLE352JFLE3207ME and can be found by clicking "Connected Accounts" (left side pane option after you set it up).
// asynchronously called
if (err && err.type === 'StripeCardError') {
// The card has been declined
response.error(err); // card declineded
} else if (err) {
//other errror
response.error(err); // return error
} else {
//no error
response.success(charge); // return charge success
}
});
});
Lastly, a quick picture of the "connected accounts" option on the left navigation pane:
Walah. You are done.
Hope this helps. Let me know if you have any questions.

How to use Braintree V Zero on IOS app?

I am coding an IOS app with Payment feature.
I decided to use Braintree V Zero.
At the very beginning, I use their excellent DropIn UI feature, and everything works fine.
But when payment happen, the Drop In UI required end-user to input his credit card or Paypal information every time.
Does any expect know how to implement one automatic charge solution by BrainTree V zero?
Like Uber's charge solution.
I guess maybe need to mark the user's credit card information from app side or service side?
router.get('/token', function (req, res) {
console.log('Kevin in token be called %s', req.param('aCustomerId'));
var aCustomerId = req.param('aCustomerId');
console.log('Kevin %s', aCustomerId);
gateway.clientToken.generate({customerId: aCustomerId}, function (error, response) {
res.send(response.clientToken);
console.log(response.clientToken);
});
});
Thank you in advanced!
Full disclosure: I work for Braintree.
The Braintree drop-in will display previously used payment methods for a customer, if you pass the customer_id in when generating a client token on your server.
​
Here's an example of how to do it in Node:
gateway.clientToken.generate({
customerId: aCustomerId
}, function (err, response) {
var clientToken = response.clientToken
});
​
Once a payment method is used, it will be saved in the drop-in and the customer will not have to enter it again. Pass the token of the saved payment method when creating a transaction:
​
gateway.transaction.sale({
amount: "10.00",
paymentMethodToken: theToken,
options: {
submitForSettlement: true
}
}, function (err, result) {
});
If you have any further questions, please feel free to contact Braintree support.
3133e

Subscribing email address to MailChimp from iOS app

I have added a contact form to my app that allows users to send feedback to me directly via email. I'm using Mandrill and Parse, and it works well!
On the contact form is an "Add me to mailing list…" option, and I'm looking for a way to add the user's email to MailChimp automatically if this option is checked.
I understand that there's a MailChimp API that's accessible by Objective C through a wrapper, though I'm wondering if there's not a more straightforward way to simply add an email to a MailChimp mailing list in iOS/Objective C?
Thanks for reading.
EDIT #1: Progress, but not yet success.
1) I've added cloud code from this answer to Parse (substituting in the two keys, where KEY2 is last three characters of MailChimp key):
var mailchimpApiKey = "MY_MAILCHIMP_KEY";
Parse.Cloud.define("subscribeUserToMailingList", function(request, response) {
if (!request.params ||
!request.params.email){
response.error("Must supply email address, firstname and lastname to Mailchimp signup");
return;
}
var mailchimpData = {
apikey : mailchimpApiKey,
id : request.params.listid,
email : {
email : request.params.email
},
merge_vars : request.params.mergevars
}
var url = "https://KEY2.api.mailchimp.com/2.0/lists/subscribe.json";
Parse.Cloud.httpRequest({
method: 'POST',
url: url,
body: JSON.stringify(mailchimpData),
success: function(httpResponse) {
console.log(httpResponse.text);
response.success("Successfully subscribed");
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
console.error(httpResponse.text);
response.error('Mailchimp subscribe failed with response code ' + httpResponse.status);
}
});
});
2) And I've added this Objective-C code to my iOS project (adding in my MailChimp list ID):
[PFCloud callFunctionInBackground:#"subscribeUserToMailingList" withParameters:#{#"listid":#"MY_LIST_ID",#"email":userEmail,#"mergevars":#{#"FNAME":firstName,#"LNAME":lastName}}
block:^(NSString *result, NSError *error){
if (error) {
//error
} else {
}
}];
The result? This error:
Error Domain=Parse Code=141 "The operation couldn’t be completed. (Parse error 141.)" … {error=Mailchimp subscribe failed with response code 500, code=141}
EDIT #2: More progress, but not yet success.
The previous error was being caused by an attempt to add an email address to the mailing list that was already there. I am now getting no errors and a "Successfully subscribed" result in the block above. However, logging in to MailChimp, the new address is still not there.
OK, turns out the code is fine! Please use, share, and enjoy.
The issue was that MailChimp (smartly) requires double opt-in for mailing lists.
The first opt-in is running this code with a specific userEmail, and it results in an email being sent to your to-be-added user.
The email asks them to confirm their subscription, and if they do so (it's a link in the email), that's the second opt-in. Then, their email is added to your list.
So, bottom line is that the code doesn't automatically add a user to your mailing list—their confirmation is still required. It's a nice way to make sure people on your mailing list actually want to be there (i.e., have a chance of reading your emails)!

Preventing strangers accessing WEBRTC pages

I am creating a sample application to tryout WEBRTC. I came across a tutorial that explains the process. I tried copying the code and it seems to work.
Question is:
I ONLY want a few people to access the page that containing the stream. How can i prevent other unauthorised users from accessing my page. A tutorial that walks through the process would be ideal.
the language i am using to develop is Grails.
You can use authentication plugin for the grails to deny unauthorized request. You can even use Socket.io over Node.js to prevent unauthorized users where you can check "userid":
// socket.io nodejs side code
io.sockets.on('connection', function (socket) {
var userid = socket.handshake.query.userid;
// verify userid
if (typeof objUserArrays[userid] == 'undefined') {
// don't broadcast messages; so that user can NEVER join any room.
return;
}
});
and browser side code:
var socket = io.connect('http://your-domain.com/?userid=something');
For last snippet; you can check meeting.js's openSignalingChannel method:
meeting.openSignalingChannel = function(callback) {
return io.connect('http://your-domain.com/?userid=something').on('message', callback);
};

Resources