这里的要求是我想一次性添加dwolla
上的客户数量。通过运行dwolla
循环创建客户。但事情是一些客户添加因错误而失败,
Error: {“code”:“ServerError”,“message”:“A server error occurred. Error ID: 6188070b-8a1b-4d94-90a5-eb1333d3cd9e.”}
法典:
const client = new dwolla.Client({
key : dwollaCredentials.appKey,
secret : dwollaCredentials.appSecret,
environment : 'sandbox' // optional - defaults to production
});
client.auth.client().then(Meteor.bindEnvironment(function(appToken) {
var spaceProviders = getListofSpaceProvidersWithNoDwollaAcc();
console.log(spaceProviders.length);
for (var i = 0 ; i<spaceProviders.length ; i++) {
var spaceProviderId = spaceProviders[i].id;
var routingNumberUser = spaceProviders[i].routingNo;
var accountNumberUser = spaceProviders[i].accountNumber;
var bankName = spaceProviders[i].firstName+' '+spaceProviders[i].lastName+' Bank';
if (spaceProviders[i]) {
var requestBody = {
firstName : spaceProviders[i].firstName,
lastName : spaceProviders[i].lastName,
email : spaceProviders[i].email
};
console.log('requestBody: ',requestBody);
appToken
.post('customers', requestBody)
.then((res)=> {
var dwollaLocation = res.headers.get('location');
return Promise.resolve(dwollaLocation);
})
.then(Meteor.bindEnvironment((dloc) => {
console.log("dloc"+i+' '+dloc);
return Promise.resolve(dloc);
}))
.catch(error => console.log("Handled Exceptions user",i+' - '+error));
}
}//i
})
);
不知何故批量客户帐户创建失败,可能是这在 dwolla 创建持续调用,它无法处理这么多大数字,可能是一个请求开始处理,另一个请求正在达到明智的,所以最后我为每个客户解决了单独的"添加"按钮,并在点击事件时调用创建 dwolla 客户 api。