■CardAuthToken.js
function CardAuthToken() {
this.URL = "http://192.168.0.11:8080/CardAuthStub/token/request",
this.TIMEOUT = 35e3
}
CardAuthToken.prototype = {
createToken: function (merchantId, tokenGenerateKey, card, callBack) {
var caller = this;
try {
var xhr = new XMLHttpRequest;
xhr.onerror = function (e) {
return callBack(caller.createErrObj("7001"))
},
xhr.ontimeout = function (e) {
return callBack(caller.createErrObj("7001"))
},
xhr.onprogress = function () {},
xhr.onload = function () {
var obj;
try {
obj = JSON.parse(xhr.responseText)
} catch (obj) {
return callBack(caller.createErrObj("7001"))
}
return callBack(obj)
},
xhr.open("POST", this.URL, !0), xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8"),
xhr.timeout = this.TIMEOUT,
xhr.send("merchant_id=" + encodeURIComponent(merchantId) +
"&token_generate_key=" + encodeURIComponent(tokenGenerateKey) +
"&card_number=" + encodeURIComponent(card.card_number) +
"&card_expire_year=" + encodeURIComponent(card.expire_year) +
"&card_expire_month=" + encodeURIComponent(card.expire_month) +
"&card_cvc=" + (void 0 === card.cvc? "": encodeURIComponent(card.cvc)) +
"&card_name=" + encodeURIComponent(card.name))
} catch (e) {
return r(caller.createErrObj("7001"))
}
},
createErrObj: function (e) {
return {result: e}
}
};