如何使用Braintree从webhook获取客户的ID?
如何从Braintree的webhook通知中获得客户的ID?
例如,我可以执行以下操作来获取ID:
gateway.webhookNotification.parse(sampleNotification.bt_signature, sampleNotification.bt_payload, (err, webhookNotification) => { let customerId = webhookNotification.subject.subscription.transactions[0].customer.id; });
但是这要求用户至less有一个事务。 如果没有任何交易(例如新用户),我如何获得客户ID?
这是loggingwebhookNotification
时的响应:
WebhookNotification { timestamp: '2017-04-30T11:01:33Z', kind: 'subscription_charged_unsuccessfully', subject: { subscription: { id: 'jywgnr', transactions: [], addOns: [], discounts: [] } }, subscription: Subscription { id: 'jywgnr', transactions: [], addOns: [], discounts: [] } }
看起来你正在使用订阅webhook。 这看起来是在有效负载中返回一个付款方式令牌 ,您可以在paymentMethod.find()调用中使用该令牌 。
从该paymentMethod.find('token')结果对象中,可以检索到customer_id。
编辑:看起来像是因为订阅不成功,那个webhook没有付款方式令牌。 但有一个订阅ID,您可以在Subscription.find() API调用中使用该ID,该ID肯定会返回包含付款方法标记的结果对象。