0

This is my first time interacting with Stripe and trying to tie it into CodeIgniter. Currently, when you create an account on my application it adds you to the correct Stripe plan and increases the total amount to be billed on that account.

I'm having a problem trying to work with this subscription plan #. I found in their documentation that this deals with the Subscription plans quantity.

What I need to happen is when you deactivate a user, it needs to update the quantity to 1 less. I can't figure this out.

Playing around with their API I was able to completely delete a subscribed customer by doing:

$this->load->library( 'stripe' );
$this->stripe->customer_delete('cus_1WS0pth6srNf7H');

Now I'm working with:

$this->load->library( 'stripe' );
$customer_id = $company->stripe_id;
$this->stripe->customer_update($customer_id, **WHAT GOES HERE?**);

Any help would be greatly appreciated. To sum this up, I need to update the quantity of my plan to -1 when a user is deactivated. The user is being deactivated fine in my application, but now I need to send a request to Stripe to update my plan to 1 less user.

Perhaps the customer_update function isn't the right one to use for this? There are a lot in the Stripe.php file.

Once I have this solved I can handle applying it to reactivating a user.

Here is the documentation where I think I need to be

2 Answers 2

5

I've been using Jason Horwitz's fork of bcessa's php-stripe library. It appears to be kept up to date with Stripe API changes.

https://github.com/sekati/php-stripe

Anyways, this is what I did for applying a plan to a customer

$request = $this->stripe->customer_subscribe( $stripe_id, $plan );

According to Stripe's API Docs, this will prorate the difference (if changing from one plan to another) by default so if that's what you want, you're good. If not, you can add it to the options array like so:

$request = $this->stripe->customer_subscribe( $stripe_id, $plan, array('prorate' => false) );
2
  • hi dave it doesn't seems to be up to date with the current version of stripe-php docs. For eg it doesn't include the concept of application fees. How to use this feature? Plz help me in this regard Commented May 27, 2014 at 2:30
  • I looked at how that charge works with fees and it requires an OAuth key to be sent with the charge. In that case, you're going to want to use Stripe's PHP library and maybe this PHP Stripe/OAuth library to get you rolling. That scope of project is larger than just a website accepting money, which is what this library is for (and at that, is geared towards the basics over implementing every single option) and to be quite honest, I haven't worked with OAuth so I couldn't program that into it myself.
    – dave
    Commented Jun 13, 2014 at 10:44
3

Not clear if you are using this library or not, but you should check:

https://github.com/bcessa/php-stripe

Written for CI & very simple. I'm going to assume you are.


According to Stripe support (I did this exact same thing recently), you need to actually make a unsubscribe & resubscribe to a new plan.

The steps I want through, roughly, were:

1) Get next invoice - so I could capture the next billing date for the new subscription (we used a trial period, so I needed this. you might be able to skip)

2) Unsubscribe the customer

3) Get my new total user count

4) Create a plan id (can be the same as you had before, I believe)

5) Subscribe with the new count to the new plan

6) Update anything on your own db

Not the answer you're looking for? Browse other questions tagged or ask your own question.