【问题标题】:braintree webhook success notification to databaseBraintree webhook 成功通知到数据库
【发布时间】:2018-04-24 16:24:13
【问题描述】:

您好,我是编码新手,但我正在尝试让自己参与到 Braintree/php sdk 中。

现在,我有一个活动的 Braintree Webhook 网址,但我不知道如何在订阅成功时获取 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";
  }

整个代码只显示种类,而不是那样做。 订阅成功后,我想获取完整的客户详细信息。

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

【问题讨论】:

    标签: php braintree


    【解决方案1】:

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

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

    1. 如果订阅有关联交易,您可以访问订阅对象中的transactions array,然后您可以使用它访问该交易对象中的customer details

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

    2. 从订阅中提取payment method token 字符串并运行customer search api call,这将返回完整的客户对象。

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

    【讨论】:

    • 感谢您的回复,即使迟到了 :) 已经找到了关于此问题的解决方案,但谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 2017-09-15
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多