【发布时间】:2014-08-05 14:05:06
【问题描述】:
有什么方法可以从他们通过 API 输入支付表单的电子邮件中检索客户 ID?
对于我的应用程序,客户将持续多次付款,但为简单起见,没有登录,他们只需输入付款信息和发票号码。作为一种最佳做法,出于显而易见的原因,我想将他们的所有费用一起保存在 Stripe 中,但这似乎是不可能的?
【问题讨论】:
标签: php stripe-payments
有什么方法可以从他们通过 API 输入支付表单的电子邮件中检索客户 ID?
对于我的应用程序,客户将持续多次付款,但为简单起见,没有登录,他们只需输入付款信息和发票号码。作为一种最佳做法,出于显而易见的原因,我想将他们的所有费用一起保存在 Stripe 中,但这似乎是不可能的?
【问题讨论】:
标签: php stripe-payments
我做了这个 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",
}
【讨论】:
这取决于您是否已经在遵循其他最佳做法。 ;)
对于 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 可能是一个不错的起点。
【讨论】:
是的,你可以
使用 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;
}
【讨论】: