如何从Braintree的webhook获取客户的ID?

时间:2017-04-21 02:21:31

标签: node.js braintree

如何从Braintree的webhook通知中获取客户的ID?

例如,我可以执行以下操作来获取其ID:

gateway.webhookNotification.parse(sampleNotification.bt_signature, sampleNotification.bt_payload, (err, webhookNotification) => {
     let customerId = webhookNotification.subject.subscription.transactions[0].customer.id;
});

但这要求用户首先至少拥有一个交易。如果他们还没有任何交易(例如新用户),我如何获得客户的身份证?

以下是记录webhookNotification时的响应:

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: [] 
   } 
}

1 个答案:

答案 0 :(得分:2)

看起来您正在使用订阅webhook。这似乎会在有效负载中返回payment method token,您可以在paymentMethod.find()调用中使用。{/ p>

从该paymentMethod.find('token')结果对象中,您可以检索customer_id。

编辑:看起来因为订阅不成功,该webhook中没有付款方式令牌。但是,您可以在Subscription.find() API调用中使用订阅ID,它肯定会返回包含付款方式令牌的结果对象。

相关问题