Stripe - retrieve Customer ID using email from form

别来无恙 提交于 2020-01-11 06:35:12

问题


Is there any way to retrieve a Customer ID from the e-mail they enter in the payment form via the API?

For my application customers will pay multiple times on an ongoing basis but for simplicity's sake there are no logins, they just enter their payment info and invoice number. As a best practice I'd like to keep all of their charges together in Stripe for obvious reasons but it doesn't seem this is possible?


回答1:


I did this API request. This API request is not available in stripe docs.I got their search request at dashboard customize according to my requirements.

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:


That depends on whether or not you're already following other best practices. ;)

With Stripe, as with most payment solutions, you're intended to retain the IDs for resources you'll use repeatedly. If you're doing this, then your database of users should contain each user's Stripe Customer ID, and you can:

  • Look up the user locally via email
  • Find their Stripe customer ID in your database
  • Retrieve their Stripe charges (or Stripe invoices) by customer ID
  • Create new Stripe charges (or Stripe invoices) associated with their customer ID

It sounds like you're still in development, in which case you easily add any missing pieces and keep on trucking.

For example, if you're using Laravel, you might do something like this:

// 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"
));

But I've already launched!

If you've already launched and have live invoices, your ability to associate past charges with customers is going to vary with the data you've been passing in to Stripe up to this point.

Without more details it's impossible offer any specific guidance, but the list of all charges is likely a good place to start.



来源:https://stackoverflow.com/questions/24231980/stripe-retrieve-customer-id-using-email-from-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!