balanced / balanced-js

Javascript client library for Balanced that tokenizes cards and bank accounts.
Other
40 stars 28 forks source link

Better validation of input #65

Open gr0uch opened 10 years ago

gr0uch commented 10 years ago

Validation should be more strict and/or more informative. Examples:

/* I think there should be some sort of warning
   for trying to pass in an object, or if there is a
   clear type mismatch */
balanced.bankAccount.create({
  name: 1010001101010,
  routing_number: 123123123,
  account_number: {
    'omg': 'wtfbbq'
  }
}, function(res) {...}); // 201
/* same issue with functions, it makes the request
   though it does not serialize the `account_number`
   and thus it errors, could have been prevented */
balanced.bankAccount.create({
  name: 'foo bar',
  routing_number: 123123123,
  account_number: function(){}
}, function(res) {...}); // 400
/* it would be nice if `create` could return a promise using
   some lightweight promises lib that implements promises/A+ */
var promise = balanced.bankAccount.create({
  name: 'foo bar',
  routing_number: 123123123,
  account_number: 58294368
}); // cryptic error message due to minification, needs callback function parameter
balanced.bankAccount.create('foo'); // yay cryptic error
mjallday commented 10 years ago
  1. library should not be minified - https://js.balancedpayments.com - let's make a new issue to un-minify that
  2. if you pass a function should we try and evaluate the response?
  3. by warning what do you mean? console.warn or something in the callback?
  4. I agree that promise could be nice.
gr0uch commented 10 years ago

1.) It would be nice to build an unminified version, but we should also not encourage its use in production. 2.) I don't think so, that would be too magical. 3.) console.warn should be sufficient. 4.) What about using Q or RSVP.js? they're both ~2.5kb minified+gzipped.