Braintree Webhook成功通知数据库



你好,我是新手编码的新来,但是我试图让自己与braintree/php sdk。

现在,我有一个活跃的braintree webhook URL,但是当订阅成功时,我不知道如何获取braintree订阅属性/参数。

其他问题,我已经实施了一些Braintree给我的代码,但是我仍然不知道是否有效。

我简单地想在成功完成订阅后将客户详细信息保存到我的数据库中。

这是我的Webhook代码。

public static function handleWebhook(){
  Braintree_Configuration::environment('sandbox');
  Braintree_Configuration::merchantId('my_id');
  Braintree_Configuration::publicKey('my_key');
  Braintree_Configuration::privateKey('my_private_key');
  if((Router::$aPost["bt_signature"]) && isset(Router::$aPost["bt_payload"])) {
    $webhookNotification = Braintree_WebhookNotification::parse(
      Router::$aPost["bt_signature"], 
      Router::$aPost["bt_payload"]
    );
    $message = "[Webhook Received " 
               . $webhookNotification->timestamp->format('Y-m-d H:i:s') . "] "
               . "Kind: " . $webhookNotification->kind . " | "
               . "Subscription: " . $webhookNotification->subscription->id . "n";
  }

整个代码仅显示这种代码,而是这样做。成功完成订阅后,我想获取整个客户细节。

谢谢,希望有人可以帮助我。对不起,我的英语不好。

全面披露:我在Braintree工作。如果您还有其他问题,请随时联系支持。

Braintree不会返回订阅Webhook的完整客户对象。在Braintree API中,订阅与付款方式相关,而不是客户,但是,您可以使用Webhook提供的订阅对象访问完整的客户对象。根据订阅的不同,有几种不同的方式。

  1. 如果订阅具有关联的交易,则可以访问订阅对象中的交易数组,然后可以使用该数组来访问该事务对象中的客户详细信息。

    $webhookNotification->subscription->transactions[0]->customerDetails

  2. 从订阅中提取付款方式令牌字符串并运行客户搜索API调用,该调用将返回完整的客户对象。

    $collection = $gateway->customer()->search([
        Braintree_CustomerSearch::cardholderName()->is("John Doe"),
        Braintree_CustomerSearch::paymentMethodToken()->is("the_payment_method_token")]);
    

最新更新