Stripe, is it possible to search a customer by their email?

前端 未结 12 1419
暗喜
暗喜 2020-12-08 06:32

Update: Since around January 2018, it is now possible to search using the email parameter on Stripe. See the accepted answer.


I

相关标签:
12条回答
  • 2020-12-08 06:48

    You need to retrieve and store the Stripe customer ID along with the other customer details in your database. You can then search for the email address in your database and retrieve the customer record from Stripe by using the Stripe customer ID.

    0 讨论(0)
  • 2020-12-08 06:51

    Here is The Async- Await Way This Method can Be Used For All Third Party Hits with Nodejs Particularly

        const configuration = {
                headers: {
                    "authorization": `Bearer ${Your stripe test key}`,
                    "content-type": "application/x-www-form-urlencoded",
                }
              };
              const requestUrl = `https://api.stripe.com/v1/search?
        query=${'email you are to use'} &prefix=false`
            const emailPayment = await axios.get(requestUrl, 
        configuration)
    

    Axiom is Npm for creating http requests... very cool and dead simple

    0 讨论(0)
  • 2020-12-08 06:51

    Stripe allows the ability to have more than once customer with the same email. That said, if you wanted to, you can pass a filters hash param to the list method to return a single customer or array of customers.

    Stripe::Customer.list(email: user.email).data
    

    The above will return an array of Stripe::Customer instances with the email

    0 讨论(0)
  • 2020-12-08 06:56

    You can't directly search by email.

    However, you can hack a little bit to list all users, and look after your email.

    Here's my code (PHP) :

    $last_customer = NULL;
    $email = "EmailYou@AreLooking.for";
    while (true) {
        $customers = \Stripe\Customer::all(array("limit" => 100, "starting_after" => $last_customer));
        foreach ($customers->autoPagingIterator() as $customer) {
            if ($customer->email == $email) {
                $customerIamLookingFor = $customer;
                break 2;
            }
        }
        if (!$customers->has_more) {
            break;
        }
        $last_customer = end($customers->data);
    }
    
    0 讨论(0)
  • 2020-12-08 06:59

    Stripe API does not supports any search-by-email feature. They have this search in their dashboard but not released any to API; from the architectural concept it seems that there is no possibility or plan from stripe to include this in API; every object in their API is retrievable only by that specific objects id given by stripe while its created. May be, they have kept it as a scope for third party application developers involvement!!

    So, the obvious solution is to store the customers in your own database that you want to be searchable in future - as Simeon Visser has said above

    btw, for a workaround, if you already have used the stripe API a lot and there are many customer data which you now need to be searchable - the only way is to go thru the 'List all customers' functionality of API & build the database for your own purpose; ofcourse, you've to use pagination shortcut to iterate thru the whole list for doing so.

    $customers = \Stripe\Customer::all(array("limit" => 3));
    foreach ($customers->autoPagingIterator() as $customer) {
      // Do something with $customer
    }
    
    0 讨论(0)
  • 2020-12-08 07:05

    You can try this. It worked for me. Below code will return empty list if not found data matching with email.

         $stripe = new \Stripe\StripeClient("YOUR_STRIPE_SECRET");
    
         $customers = $stripe->customers->all(['email'=>'jane.doe@example.com',
            'limit' => 15,
          ]);
    
    0 讨论(0)
提交回复
热议问题