Calculating next billing date from web hook

Rob McCann's Avatar

Rob McCann

17 Oct, 2012 07:12 PM

Hi,

Am I right in thinking I can calculate the next billing date by using subscription[invoice][createdDatetime] as the last billing date?

Thanks for your assistance in advance,

Rob McCann

  1. Support Staff 1 Posted by Marc Guyer on 18 Oct, 2012 02:31 PM

    Marc Guyer's Avatar

    Hi Rob -- The invoice bill date is subscription['invoice']['billingDatetime']. If you want to know the next one, you can calculate it as long as it's a 'subscription' type invoice. Here's a PHP example:

    $nextStamp = strtotime(
        "+ {$subscription['plan']['billingFrequencyUnit']} {$subscription['plan']['billingFrequencyQuantity']}", 
        strtotime(subscription['invoice']['billingDatetime'])
    );
    
  2. Rob McCann closed this discussion on 19 Oct, 2012 10:35 PM.

  3. Rob McCann re-opened this discussion on 19 Oct, 2012 10:35 PM

  4. 2 Posted by Rob McCann on 19 Oct, 2012 10:35 PM

    Rob McCann's Avatar

    Thans for your help, exactly what I'm after :)

  5. Rob McCann closed this discussion on 19 Oct, 2012 10:35 PM.

  6. Rob McCann re-opened this discussion on 30 Oct, 2012 11:52 PM

  7. 3 Posted by Rob McCann on 30 Oct, 2012 11:52 PM

    Rob McCann's Avatar

    Hi Marc,

    I'm having some trouble with this so I'll explain what I'm trying to do, what I'm actually doing and what is happening:

    I'm trying to let a user set the day in the month that they're being billed on. There's no API method to just set the day so I'm calculating the next billing date if they want to be billed on that day. It needs to handle bi-monthly subscriptions too.

    Here's the api calls I'm making:
    1. User subscribes on 28th Oct.
    2. User updates billing date via API to 29th Nov.
    3. User updates billing date via API to 30th Nov.

    The problem lies in how I calculate the date in (3).
    After (2) a new invoice is created in the system (although unpaid). I can't then use subscription[0]['invoice']['billingDatetime'] to calculate the last billing date because it now reflects 29th Nov.

    Am I making sense?

  8. Support Staff 4 Posted by Marc Guyer on 31 Oct, 2012 01:05 PM

    Marc Guyer's Avatar

    After (2) a new invoice is created in the system (although unpaid).

    I don't think this is accurate. There's never more than one pending/current invoice.

    Can you link me an example customer? It will help to know exactly what plan, etc, that we're talking about. It will also help if you describe the result you want to achieve and the hook type and data of the hook you're using.

  9. 5 Posted by Rob McCann on 31 Oct, 2012 01:29 PM

    Rob McCann's Avatar

    Hi Marc,

    Thanks for your help in solving this, we'll get there eventually! It's much
    appreciated :)

    Here's the customer ID
    e1183f74-20fd-11e2-9d18-40403c39f8d9

    How do I calculate the next invoice date if there is a pending invoice? Is
    there a way I can tell the difference between a pending and a paid invoice?

    Rob

  10. Support Staff 6 Posted by Marc Guyer on 31 Oct, 2012 01:52 PM

    Marc Guyer's Avatar

    How do I calculate the next invoice date if there is a pending invoice?

    There is always a pending invoice. The billingDatetime of the pending invoice is the next invoice date.

    Is there a way I can tell the difference between a pending and a paid invoice?

    The pending invoice is always the first one in the list of the customers/get API response. A pending invoice is one that has a billingDatetime in the future (or doesn't have a billingDatetime).

    A paid invoice has a paidTransactionId. An "outstanding" invoice is one that has a billingDatetime in the past and doesn't have a paidTransactionId.

  11. Marc Guyer closed this discussion on 27 Nov, 2012 12:50 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