From 6a6eb015cbe4bd983ea5101ae3510c67dabe07f1 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 03 Dec 2015 18:23:50 -0500 Subject: Epirts.card.createToken(): Use XHR --- 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) { -- cgit v0.9.1