summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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) {