Stripe - retrieve Customer ID using email from form

前端 未结 2 547
梦谈多话
梦谈多话 2021-01-07 02:02

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 on

相关标签:
2条回答
  • 2021-01-07 02:28

    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",
    }
    
    0 讨论(0)
  • 2021-01-07 02:50

    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.

    0 讨论(0)
提交回复
热议问题