【问题标题】:Stripe - retrieve Customer ID using email from formStripe - 使用表单中的电子邮件检索客户 ID
【发布时间】:2014-08-05 14:05:06
【问题描述】:

有什么方法可以从他们通过 API 输入支付表单的电子邮件中检索客户 ID?

对于我的应用程序,客户将持续多次付款,但为简单起见,没有登录,他们只需输入付款信息和发票号码。作为一种最佳做法,出于显而易见的原因,我想将他们的所有费用一起保存在 Stripe 中,但这似乎是不可能的?

【问题讨论】:

    标签: php stripe-payments


    【解决方案1】:

    我做了这个 API 请求。此 API 请求在条带文档中不可用。我在仪表板中根据我的要求自定义了他们的搜索请求。

    url :https://api.stripe.com/v1/search?query="+email+"&prefix=false",
    method: GET
    headers: {
      "authorization": "Bearer Your_seceret Key",
      "content-type": "application/x-www-form-urlencoded",
    }
    

    【讨论】:

      【解决方案2】:

      这取决于您是否已经在遵循其他最佳做法。 ;)

      对于 Stripe,与大多数支付解决方案一样,您需要为您将重复使用的资源保留 ID。如果您这样做,那么您的用户数据库应该包含每个用户的 Stripe 客户 ID,您可以:

      听起来您仍在开发中,在这种情况下,您可以轻松添加任何缺失的部分并继续运输。

      例如,如果你使用 Laravel,你可能会这样做:

      // When creating a customer
      $customer = new Customer;
      $customer->name = 'John Smith';
      $customer->email = 'jsmith@example.com';
      
      $stripe_customer = Stripe_Customer::create(array(
        "description" => $customer->name,
        "email" => $customer->email
      ));
      
      $customer->stripe_id = $stripe_customer->id;  // Keep this! We'll use it again!
      $customer->save();
      
      
      // When creating a charge
      Stripe_Charge::create(array(
        "amount" => 2999,
        "currency" => "usd",
        "customer" => Auth::user()->stripe_id,      // Assign it to the customer
        "description" => "Payment for Invoice 4321"
      ));
      

      但我已经启动了!

      如果您已经启动并拥有实时发票,那么您将过去的费用与客户关联起来的能力将随着您迄今为止一直传递给 Stripe 的数据而变化。

      如果没有更多细节,就不可能提供任何具体指导,但the list of all charges 可能是一个不错的起点。

      【讨论】:

      • 我知道只使用 ID 可能是有原因的,但我确实发现 Stripe 缺乏数据搜索功能有时有点令人沮丧。如果您想搜索任何内容,您基本上会陷入循环遍历每条记录并对每条记录执行条件以找到您要查找的内容。
      • 我还遇到过存储每个客户 ID 不合逻辑的情况。我听到你在说什么,科林姆,但我仍然认为应该有一种通过电子邮件查找的方法。我们现在是 21 世纪。
      【解决方案3】:

      是的,你可以

      使用 api:

      $stripe = new \Stripe\StripeClient('stripe_key');
      $customers = $stripe->customers->all(['email' => 'email@doamin.com']);
      

      与 laravel 收银员:

      $customers =  Cashier::stripe()->customers->all(['email' => 'email@doamin.com'])
      

      如果不为空则返回一个数组,表示用户存在

      if(!empty($customers)){
        $user->stripe_id = $customers[0]->id;
      }
      

      【讨论】:

        猜你喜欢
        • 2022-11-25
        • 2020-11-15
        • 1970-01-01
        • 2015-07-10
        • 2014-12-01
        • 2015-01-02
        • 2021-12-28
        • 2015-02-14
        • 2019-09-05
        相关资源
        最近更新 更多