Как установить card_nonce в узле Unirest (квадрат)
Я нахожусь в процессе преобразования API REST Square, найденного здесь: https://docs.connect.squareup.com/api/connect/v2/ в бэкэнд-код, который работает с Node.js. В настоящее время я пытаюсь добавить карту для существующего клиента с CreateCustomerCard
конечная точка.
Тем не менее, при попытке представить card_nonce
Я получаю следующую ошибку:
errors:
[{ category: 'INVALID_REQUEST_ERROR',
code: 'MISSING_REQUIRED_PARAMETER',
detail: 'Field must be set',
field: 'card_nonce'
}]
Я запускаю функцию из test.js следующим образом:
const square = require('./square'),
unirest = require('unirest');
let access_token = 'access-token-string';
square.CustomerCards.createCustomerCard({
"customer_id": 'customer-id-string',
"card_nonce": 'card-nonce-string',
"cardholder_name": 'Name Name'
}).then( response => {
console.log(response.raw_body);
})
Какие ссылки на customerCard.js
const unirest = require('unirest');
module.exports = {
// Adds a card on file to an existing customer
// Requires access_token, customer_id, and card_nonce
createCustomerCard: function({access_token, card_nonce, billing_address, cardholder_name, customer_id}) {
return new Promise((resolve, reject) => {
unirest.post(this.domain + '/customers/' + customer_id + '/cards')
// Required permissions: CUSTOMERS_WRITE
.headers({
'Content-Type': 'application/json',
"Authorization": "Bearer " + access_token
})
.send({
// Required: A card nonce representing the credit card to link to the customer.
"card_nonce": card_nonce,
"billing_address": billing_address,
"cardholder_name": cardholder_name
})
.end(function (response) {
resolve(response)
})
});
}
};
1 ответ
Переменная this.domain
был установлен равным https://connect.squareup.com/v2/
делая регулярное выражение https://connect.squareup.com/v2//customers/' + customer_id + '/cards'
неверный и сбивающий с толку обработчик ошибок Square.