diff options
author | P. J. McDermott <pj@pehjota.net> | 2015-12-03 18:23:50 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2016-02-17 16:53:02 (EST) |
commit | 6a6eb015cbe4bd983ea5101ae3510c67dabe07f1 (patch) | |
tree | 9dec0f3cd7c18a13393ab0d9729c2c0b16ffcfb4 | |
parent | 5009c93c2dd2d637e27e7895ccc3bf3ecc67595c (diff) | |
download | epirts.js-feature/xhr.zip epirts.js-feature/xhr.tar.gz epirts.js-feature/xhr.tar.bz2 |
Epirts.card.createToken(): Use XHRfeature/xhr
-rw-r--r-- | epirts.js | 48 |
1 files changed, 47 insertions, 1 deletions
@@ -87,6 +87,51 @@ var Stripe = Epirts = (function() { where.parentNode.insertBefore(script, where); }; + _createTokenXHR = function(data, amount, callback) { + var query; + var i; + var prop; + var xhr; + + query = ""; + for (i = 0; i < _properties.length; ++i) { + prop = _properties[i]; + if (data.hasOwnProperty(prop)) { + query += (query == "" ? "" : "&") + + 'card[' + prop + ']=' + + data[prop]; + } + } + if (amount !== undefined) { + query += (query == "" ? "" : "&") + + 'amount=' + amount; + } + /* query += (query == "" ? "" : "&") + "key=" + _key; */ + + alert("Authorization: Basic " + + window.btoa(_key + ":")); + + xhr = new XMLHttpRequest(); + xhr.open("POST", Epirts.endpoint + "/tokens", true); + xhr.setRequestHeader("Authorization", + "Basic " + window.btoa(_key + ":")); + xhr.setRequestHeader("Accept", + "application/vnd.api+json;revision=1.1" + ); + xhr.setRequestHeader("Content-Type", + "application/x-www-form-urlencoded"); + xhr.setRequestHeader("Content-Length", query.length); + xhr.setRequestHeader("Connection", "close"); + xhr.onreadystatechange = function(e) { + if (e.target.readyState !== 4) { + return; + } + callback(e.target.status, JSON.parse( + e.target.responseText)); + }; + xhr.send(query); + }; + pub.createToken = function(data, arg2, arg3) { var callback; var amount; @@ -105,7 +150,8 @@ var Stripe = Epirts = (function() { callback = arg3; } - _createTokenJSONP(data, amount, callback); + /* _createTokenJSONP(data, amount, callback); */ + _createTokenXHR(data, amount, callback); }; pub.validateCardNumber = function(number) { |