From 5009c93c2dd2d637e27e7895ccc3bf3ecc67595c Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 03 Dec 2015 17:13:25 -0500 Subject: Epirts.card.createToken(): Split out JSONP code --- diff --git a/epirts.js b/epirts.js index 68f9cbc..82d17e7 100644 --- a/epirts.js +++ b/epirts.js @@ -49,9 +49,7 @@ var Stripe = Epirts = (function() { 'address_country']; var _cb_time = (new Date()).getTime(); - pub.createToken = function(data, arg2, arg3) { - var callback; - var amount; + _createTokenJSONP = function(data, amount, callback) { var where; var script; var func; @@ -59,19 +57,6 @@ var Stripe = Epirts = (function() { var i; var prop; - if (!data || typeof data !== 'object') { - throw new Error("Invalid card"); - } else if (_key === undefined) { - throw new Error("Publishable key not set"); - } - if (typeof arg2 === 'function') { - callback = arg2; - } else if (typeof arg2 === 'number' || - typeof arg2 === 'string') { - amount = arg2; - callback = arg3; - } - where = document.getElementsByTagName('script')[0]; script = document.createElement('script'); script.type = 'text/javascript'; @@ -102,6 +87,27 @@ var Stripe = Epirts = (function() { where.parentNode.insertBefore(script, where); }; + pub.createToken = function(data, arg2, arg3) { + var callback; + var amount; + + if (!data || typeof data !== 'object') { + throw new Error("Invalid card"); + } else if (_key === undefined) { + throw new Error("Publishable key not set"); + } + if (typeof arg2 === 'function') { + amount = undefined; + callback = arg2; + } else if (typeof arg2 === 'number' || + typeof arg2 === 'string') { + amount = arg2; + callback = arg3; + } + + _createTokenJSONP(data, amount, callback); + }; + pub.validateCardNumber = function(number) { number = (number + '').replace(/\s|-/g); if (number.match(/\D/)) { -- cgit v0.9.1