【发布时间】:2017-05-12 02:50:41
【问题描述】:
我正在将此处的 Square REST API:https://docs.connect.squareup.com/api/connect/v2/#endpoint-createcustomercard 转换为与 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)
})
});
}
};
【问题讨论】:
-
嗯,没有。当我在 NPM 上搜索“square”时,它并没有出现在前几页。现在就试试...
-
有原生支持promise的版本吗?
-
那是第三方库,我不确定它的功能,但其他人使用它。
标签: javascript node.js node-modules square square-connect