在以下脚本中,我利用Braintree JS API尝试并标记其沙盒有效的信用卡信息。但是,我遇到了错误:
/..../js/braintree.js:25
clientInstance.request({
^
TypeError: Cannot read property 'request' of undefined
at /..../js/braintree.js:25:25
at null._onTimeout (/..../js/node_modules/braintree-web/lib/deferred.js:9:10)
at Timer.listOnTimeout (timers.js:92:15)
表明我的clientInstance未定义。有人能帮助我注意到我所缺少的东西吗?
var createClient = require('braintree-web/client').create;
function generateNonce(generatedToken, ccnum, cccvv, ccexp, postal) {
createClient({
authorization: generatedToken
}, function (createErr, clientInstance) {
var data = {
creditCard: {
number: ccnum,
cvv: cccvv,
expirationDate: ccexp,
billingAddress: {
postalCode: postal
},
options: {
validate: false
}
}
};
// Warning: For a merchant to be eligible for the easiest level of PCI compliance (SAQ A),
// payment fields cannot be hosted on your checkout page.
// For an alternative to the following, use Hosted Fields.
clientInstance.request({
endpoint: 'payment_methods/credit_cards',
method: 'post',
data: data
}, function (requestErr, response) {
// More detailed example of handling API errors: https://codepen.io/braintree/pen/MbwjdM
if (requestErr) { throw new Error(requestErr); }
console.log('Got nonce:', response.creditCards[0].nonce);
this.onRetrieval(response.creditCards[0].nonce);
});
});
}
generateNonce("valid-client-token", "4111111111111111", "123", "10/20", "1337");