Pro rata billing

Gareth's Avatar

Gareth

23 Mar, 2011 11:25 AM

I have attempted to create an API call that mixes in a future-dated initialBillDate so that the customer will get billed on the first of every month for his subscription, but also added a charge in the same call to bill him right now for the days remaining of the current month (i.e. pro rata). It seems that the initialBillDate was set correctly but the charge i included was not.

Is this expected behaviour and if so, how can I work around this limitation? The initialBillDate MUST be the first of every month for all our customers, but we don't want to force people to have to wait until the start of a new month before they can use their services.

  1. 1 Posted by Gareth on 23 Mar, 2011 11:27 AM

    Gareth's Avatar

    Just a quick correction, the charge was added to be billed on the first of the month along with the plan subscription when we want the charge to be done immediately instead and only the plan subscription on the 1st.

  2. 2 Posted by Gareth on 23 Mar, 2011 12:12 PM

    Gareth's Avatar

    Ok, so if anyone else is looking for an answer to this (before confirmation comes from support staff), I have found a way to do this in a kind of backward way. If support can just confirm this is the best way:

    1. Get the information of the plan the customer wants to subscribe to (either from CG or from your own database).
    2. Create the customer as usual but calculate the number of days already passed in the current month, and using the monthly charge of the plan, calculate the daily charge for the current month.

       $current_day = date('j');
       $days_in_month = date('t');
       $daily_charge = $plan_recurring_price / $days_in_month;
      
    3. Now, what you want to do is actually refund the customer for the days of the month already passed. You can use the CG charge parameter for this in your data array:

              $data['charges'] =  array(
              "chargeCode"=>"YOUR_UNIQUE_CHARGE_CODE"  ,
              "quantity"=>$current_day,
              "eachAmount"=>$daily_charge (-1), //Make it negative by multiplying by -1
              "description"=>"Pro rata credit " );
      
    4. Submit the API call to CG to create customer and they get billed immediately for the recurring fee, minus the credit for the days already passed.

    5. Create a new data array and send an API call to edit a customer subscription with only one parameter:

      $next_month_number = date('m', strtotime(date('Y-m-d'). " +1 month"));
      $data['subscription'] = array('changeBillDate' => date('Y'). '-'.$next_month_number.'-01');
      
    6. Send this API call and now the next invoice date is reset to the 1st of next month.

  3. Support Staff 3 Posted by Marc Guyer on 23 Mar, 2011 02:35 PM

    Marc Guyer's Avatar

    That's exactly correct!

    However, I think your logic is a bit off in (5) since the next month number could be 1 (January) which would make the year wrong (January of last year). Maybe something like this (untested):

    $firstBillDate = date('Y-m-d', mktime(0,0,0,date('n')+1,1));

    mktime() should handle for month number 13 appropriately.

  4. 4 Posted by Gareth on 24 Mar, 2011 09:58 AM

    Gareth's Avatar

    Sure, nice catch, but personally I would use strtotime as it is a little bit clearer:

    $firstBillDate = date('Y-m-d', strtotime(date('Y-m-d') . " +1 month"));

    ;)

  5. Support Staff 5 Posted by Marc Guyer on 24 Mar, 2011 07:09 PM

    Marc Guyer's Avatar

    Yeah, but don't you want it on the first of the month?

  6. Dean closed this discussion on 16 Jan, 2013 04:22 PM.

Discussions are closed to public comments.
If you need help with Cheddar please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

28 Mar, 2024 10:45 PM
24 Jan, 2024 08:33 AM
11 Jan, 2024 07:13 AM
30 Nov, 2023 02:07 AM
22 Nov, 2023 08:41 AM