【发布时间】:2014-09-19 09:14:42
【问题描述】:
我正在使用 Stripe 处理费用和客户订阅,我想将这些处理用作 Hoodie 插件。
付款和客户的注册和订阅正常显示在 Stripe Dashboard 中,但我想做的是在 CouchDB 中更新我的 _users 数据库,以确保客户的信息保存在某处。
我想要做的是更新org.couchdb.user:user/bill 文档中的stripeCustomerId 字段,该字段来自我使用Hoodie 登录时创建的_users 数据库。如果可能,如果它不存在,则创建此字段。
在 hoodie-plugin 的文档中,更新功能对我来说似乎很模糊。
// update a document in db
db.update(type, id, changed_attrs, callback)
我假设type 是CouchDB 文档中提到的那个,或者是我们在添加一个带有db.add(type, attrs, callback) 的文档时指定的那个。
id 似乎是 couchdb 中的文档 ID。就我而言,它是org.couchdb.user:user/bill。但我不确定我应该在我的更新函数中传递这个 id。
我假设 changed_attrs 是一个 Javascript 对象,其中包含更新或新的属性,但我再次对此表示怀疑。
所以我在我的worker.js 中尝试了这个:
function handleCustomersCreate(originDb, task) {
var customer = {
card: task.card
};
if (task.plan) {
customer.plan = task.plan;
}
stripe.customers.create(customer, function(error, response) {
var db = hoodie.database(originDb);
var o = {
id: 'bill',
stripeCustomerId: 'updatedId'
};
hoodie.database('_users').update('user', 'bill', o, function(error) {
console.log('Error when updating');
addPaymentCallback(error, originDb, task);
});
db.add('customers.create', {
id: task.id,
stripeType: 'customers.create',
response: response,
}, function(error) {
addPaymentCallback(error, originDb, task);
});
});
}
在其他消息之间,我得到了这个错误日志:
TypeError: Converting circular structure to JSON
我的文件没有更新:stripeCustomerId 字段保持在null。
我尝试JSON.stringify 我的o 对象,但它并没有改变任何事情。
我希望你们中的一些人比我更了解这个 db.update 函数。
【问题讨论】:
标签: node.js couchdb stripe-payments hoodie