Subscribe User To A Plan In Stripe

Stripe Subscription
In order to create a customer in stripe, first of all we need vendor library which is avaliable at
Stripe Vendor. Then you have to make a plan on the stripe, for this , goto Stripe Website..
Then after creating some plan write this piece of code to create a new customer and register that customer for a plan. For this you are also required one important thing.
1-Stripe Api Key.
In order to check your stripe Api key goto account settings and there you can find api keys.
Your test api key will be like this: sk_test_now…….

try
{
		$plan='Your plan Id';
		require_once('vendor/Stripe/lib/Stripe.php');
		Stripe::setApiKey("Your Stripe Key");
		$token = $_POST['stripeToken'];

		$customer = Stripe_Customer::create(array(
		"source" => $token,
		"plan" => $plan,
		"email" => $_POST['stripeEmail']
	)
	);
}
catch(Stripe_CardError $e) 
{
}
catch (Stripe_InvalidRequestError $e) {
		// Invalid parameters were supplied to Stripe's API
} catch (Stripe_AuthenticationError $e) {
		// Authentication with Stripe's API failed
		// (maybe you changed API keys recently)
} catch (Stripe_ApiConnectionError $e) {
		// Network communication with Stripe failed
} catch (Stripe_Error $e) {
// Display a very generic error to the user, and maybe send
		// yourself an email
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
}

This Api call to stripe will create a new customer on stripe and it will also register that customer for your plan..Now the same customer have the subscription according to this plan..