ravi kumar
ravi kumar

Reputation: 107

How to retrieve the stripe customer id from the stripe object after creation of the customer

enter image description here

<?php
require_once('Stripe/lib/Stripe.php');
Stripe::setApiKey(trim($pkey));

try
{
  $customer = Stripe_Customer::create(array(
    'email' => $_POST['stripeEmail'],
    'source'  => $_POST['stripeToken'],
    'plan' => trim($plan)
  ));

}
catch(Exception $e)
{
  //header('Location:oops.html');
  error_log("unable to sign up customer:" . $_POST['stripeEmail'].
    ", error:" . $e->getMessage());
}
?>

here i want to get the customer id so i print the $customer object it gives the stripe object but i don't know how to retrieve the customer id from that result. If any one knows please help me. Thanks in Advance

Upvotes: 3

Views: 12988

Answers (2)

Oli Girling
Oli Girling

Reputation: 763

You can use the customer object to get the id

$customer = Stripe_Customer::create(array(
    'email' => $_POST['stripeEmail'],
    'source'  => $_POST['stripeToken'],
    'plan' => trim($plan)
));

echo $customer->id;

Upvotes: 5

Manish Silawat
Manish Silawat

Reputation: 905

Just use the following line of code you will get the customer id.

 $customer = $stripe->customers()->create([
       'email' => $_POST['stripeEmail'],
       'source'  => $_POST['stripeToken'],
       'plan' => trim($plan)
    ]);

echo $customer['id'];

This will help you.

Upvotes: 5

Related Questions