3

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?

javy
  • 265
  • 1
  • 4
  • 14

3 Answers3

9

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",
}
madx
  • 6,723
  • 4
  • 55
  • 59
Sufyan Ahmad
  • 818
  • 1
  • 13
  • 22
3

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:

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.

colinm
  • 4,258
  • 24
  • 19
  • 2
    I know there are probably reasons for just using ID, but I really find Stripe's lack of data search capabilities to be a bit frustrating at times. If you want to search for anything you are basically stuck with looping thru EVERY record and doing conditions on each one to find what you are looking for. – Lobos Jan 19 '16 at 06:16
  • 1
    I also have a situation where it is not logical to store every single customer ID. I hear what you are saying, colinm, but I still think there should be a way to lookup by email. We're in the 21st century now. – TheStoryCoder Sep 26 '16 at 08:40
0

Yes you can

with api:

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

with laravel cashier:

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

it will return an array if not empty it means the user exists

if(!empty($customers)){
  $user->stripe_id = $customers[0]->id;
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Moode Osman
  • 1,715
  • 18
  • 17