summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. 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)
commit6a6eb015cbe4bd983ea5101ae3510c67dabe07f1 (patch)
tree9dec0f3cd7c18a13393ab0d9729c2c0b16ffcfb4
parent5009c93c2dd2d637e27e7895ccc3bf3ecc67595c (diff)
downloadepirts.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.js48
1 files changed, 47 insertions, 1 deletions
diff --git a/epirts.js b/epirts.js
index 82d17e7..19fe9c7 100644
--- a/epirts.js
+++ b/epirts.js
@@ -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) {