我尝试使用条带化发布密钥获取卡令牌。但是我得到了错误。代码是:
submitForm(){
var cardDetails = {
'card[number]': '4242424242424242',
'card[exp_month]': '01',
'card[exp_year]': '2022',
'card[cvc]': '123'
};
var formBody = [];
for (var property in cardDetails) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(cardDetails[property]);
formBody.push(encodedKey + '=' + encodedValue);
}
formBody = formBody.join('&');
fetch('https://api.stripe.com/v1/tokens', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Authorization': `Bearer ${publish-key}`,
'Content-Type': 'application/x-www-form-urlencoded',
},
body: formBody,
})
.then(response => response.json())
.then((responseJson) => {
console.log(responseJson, 'responseJson')
})
.catch(error => console.log(error, 'error')); //to catch the errors if any
}
错误
SyntaxError: Unexpected token o in JSON at position 1
at parse (<anonymous>)
at tryCallOne (core.js:37)
at core.js:123
at JSTimers.js:289
at _callTimer (JSTimers.js:146)
at _callImmediatesPass (JSTimers.js:194)
at Object.callImmediates (JSTimers.js:458)
at MessageQueue.__callImmediates (MessageQueue.js:407)
at MessageQueue.js:143
at MessageQueue.__guard (MessageQueue.js:384)
注意:为了进行测试,我使用了条纹测试密钥来获取令牌。
要求:用户输入卡号,有效期,有效期和信用卡。保存后,获取条带生成的条带令牌。将此令牌发送到我的自定义API。
我在react和react-native上使用了最新版本。我不仅为此需要一个库,还可以获得一个令牌。请告诉我如何从使用条纹支付网关获取卡令牌。