Usages are not billing

91 views
Skip to first unread message

Adam Wells

unread,
Jul 20, 2021, 3:46:50 AM7/20/21
to Kill Bill users mailing-list
I have set up a catalog that includes a usage component in a plan:

        <plan name="RecurringPlan" prettyName="Recurring plan">
            <product>RecurringProduct</product>
            <recurringBillingMode>IN_ADVANCE</recurringBillingMode>
            <initialPhases/>
            <finalPhase type="EVERGREEN">
                <duration>
                    <unit>UNLIMITED</unit>
                    <number>-1</number>
                </duration>
                <recurring>
                    <billingPeriod>MONTHLY</billingPeriod>
                    <recurringPrice>
                        <price>
                            <currency>AUD</currency>
                            <value>1.00</value>
                        </price>
                    </recurringPrice>
                </recurring>
                <usages>
                    <usage name="bandwidth" billingMode="IN_ARREAR" usageType="CONSUMABLE">
                        <billingPeriod>MONTHLY</billingPeriod>
                        <tiers>
                            <tier>
                                <blocks>
                                    <tieredBlock>
                                        <unit>mbps</unit>
                                        <size>1</size>
                                        <prices>
                                            <price>
                                                <currency>AUD</currency>
                                                <value>1.0</value>
                                            </price>
                                        </prices>
                                        <max>1000000</max>
                                    </tieredBlock>
                                </blocks>
                            </tier>
                        </tiers>
                    </usage>
                    <usage name="data" billingMode="IN_ARREAR" usageType="CONSUMABLE">
                        <billingPeriod>MONTHLY</billingPeriod>
                        <tiers>
                            <tier>
                                <blocks>
                                    <tieredBlock>
                                        <unit>megabytes</unit>
                                        <size>1</size>
                                        <prices>
                                            <price>
                                                <currency>AUD</currency>
                                                <value>1.0</value>
                                            </price>
                                        </prices>
                                        <max>100000</max>
                                    </tieredBlock>
                                </blocks>
                            </tier>
                        </tiers>
                    </usage>
                </usages>
            </finalPhase>
            <plansAllowedInBundle>-1</plansAllowedInBundle>
        </plan>

In testing, this plan bills fine with just its recurring billing component, but the usage parts do not seem to bill.

I am using the API to insert usage records:

curl \
    -X POST \
     -u 'admin:password' \
     -H "Content-Type: application/json" \
     -H 'X-Killbill-CreatedBy: admin' \
     -H "X-Killbill-ApiKey: swoop" \
     -H "X-Killbill-ApiSecret: swoop" \
     -d '{
  "subscriptionId": "e41e22a4-0ce1-49f8-8233-5451ef620c80",
  "trackingId": "my-unique-tracking-id",
  "unitUsageRecords": [
    {
      "unitType": "megabytes",
      "usageRecords": [
        {
          "recordDate": "2021-07-21",
          "amount": 123.33
        }
      ]
    }
  ]
}' \
 
The usage records do appear in the database:

mysql> select * from rolled_up_usage;
+-----------+--------------------------------------+--------------------------------------+-----------+-------------+--------+--------------------------------------+------------+---------------------+-------------------+------------------+
| record_id | id                                   | subscription_id                      | unit_type | record_date | amount | tracking_id                          | created_by | created_date        | account_record_id | tenant_record_id |
+-----------+--------------------------------------+--------------------------------------+-----------+-------------+--------+--------------------------------------+------------+---------------------+-------------------+------------------+
|         1 | 854f22ae-14f8-431c-b7f2-cf9373d61fc3 | e41e22a4-0ce1-49f8-8233-5451ef620c80 | megabytes | 2020-07-21  |    123 | my-unique-tracking-id                | admin      | 2021-07-20 05:44:50 |              4652 |                1 |
|         2 | ddd5ac11-6e8c-4670-8c3f-c3a518e5a980 | f0ba1407-5fb5-47ce-8959-0ebb2351bc2d | megabytes | 2021-07-22  |    123 | c6c8f8ab-c46b-4cdc-a4c7-cb2dd2620c82 | golang app | 2021-07-20 06:41:43 |              4653 |                1 |
|         3 | 99c0511b-d170-45a2-a821-8faa8dd36f9f | 6de2c839-1e0d-4972-958b-cadefe40145f | megabytes | 2021-07-26  |    123 | cf2545ea-fee8-4746-9a00-dad2dfc92a1a | golang app | 2021-07-20 07:03:29 |              4654 |                1 |
|         4 | 397604e3-4630-489f-80ce-8cf0ce0ccb25 | 43409ed1-b1c4-4393-9225-edd111c1eaa4 | megabytes | 2021-07-26  |    123 | fea9b894-6491-4f8f-8bae-23d7668ee9ad | golang app | 2021-07-20 07:09:41 |              4655 |                1 |
|         5 | cabbcecc-f066-47f4-895f-6fa2aca5b8b9 | 43409ed1-b1c4-4393-9225-edd111c1eaa4 | megabytes | 2021-08-26  |    123 | fb46cc6d-5442-4fce-b7ee-3c8e0be243c8 | golang app | 2021-07-20 07:09:42 |              4655 |                1 |
|         6 | b6e3862e-2eec-43d2-962c-1e5737aaaa84 | f7cd7e98-e4bc-4718-bb6d-3de6912ece02 | megabytes | 2021-07-26  |    123 | 0e78bbeb-6608-4ff0-bbf6-ecb7ef966dc7 | golang app | 2021-07-20 07:34:57 |              4656 |                1 |
|         7 | 8bee37ad-c132-45f3-9c68-de4202f67dba | f7cd7e98-e4bc-4718-bb6d-3de6912ece02 | megabytes | 2021-08-26  |    123 | b25ef6d9-32ba-413c-a80d-e3f648f3eed8 | golang app | 2021-07-20 07:34:58 |              4656 |                1 |
+-----------+--------------------------------------+--------------------------------------+-----------+-------------+--------+--------------------------------------+------------+---------------------+-------------------+------------------+

The trouble is that there are no usage items in my billing...

I must be doing something wrong, but I can't see it...

Any help or suggestions appreciated!

Cheers,

Adam

stephane brossier

unread,
Jul 20, 2021, 5:53:17 PM7/20/21
to Adam Wells, Kill Bill users mailing-list
I suspect this is because the target date for the invoice is not set sufficiently in the future: For the recurring, you bill IN_ADVANCE but for the usage piece this is set IN_ARREAR, so until you reach the date up to when we can bill for the first month in arrear, nothing will be billed for.


--
You received this message because you are subscribed to the Google Groups "Kill Bill users mailing-list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to killbilling-us...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/killbilling-users/2089853b-ec2e-4c92-bbc7-fa8bbfc56cb5n%40googlegroups.com.

Adam Wells

unread,
Jul 20, 2021, 6:09:50 PM7/20/21
to Kill Bill users mailing-list
Hi Stephane,

Using the Kaui interface, I have triggered billing several months into the future, but without any usage billing.

For the subscription f7cd7e98-e4bc-4718-bb6d-3de6912ece0 which started 2021-07-20

Screen Shot 2021-07-21 at 7.57.34 am.png
There is usage data for July and August:

mysql> select subscription_id, record_date, amount, created_date from rolled_up_usage where subscription_id = 'f7cd7e98-e4bc-4718-bb6d-3de6912ece02';
+--------------------------------------+-------------+--------+---------------------+
| subscription_id                      | record_date | amount | created_date        |
+--------------------------------------+-------------+--------+---------------------+
| f7cd7e98-e4bc-4718-bb6d-3de6912ece02 | 2021-07-26  |    123 | 2021-07-20 07:34:57 |
| f7cd7e98-e4bc-4718-bb6d-3de6912ece02 | 2021-08-26  |    123 | 2021-07-20 07:34:58 |
+--------------------------------------+-------------+--------+---------------------+

The invoicing does not show any usage data:

mysql> select i.target_date, ii.id, ii.invoice_id, ii.description, ii.amount from invoice_items ii join invoices i on i.id = ii.invoice_id  where subscription_id = 'f7cd7e98-e4bc-4718-bb6d-3de6912ece02';
+-------------+--------------------------------------+--------------------------------------+----------------------------+--------------+
| target_date | id                                   | invoice_id                           | description                | amount       |
+-------------+--------------------------------------+--------------------------------------+----------------------------+--------------+
| 2021-07-16  | f5d2b064-7b3f-4d11-abfe-987b58a3dfd9 | 1ac8085d-0ddb-4d37-bb53-462695de0479 | RecurringPlan-37-evergreen | 25.810000000 |
| 2021-07-16  | d060fc2d-b44c-41b8-b36e-22b99f35cbb7 | 1ac8085d-0ddb-4d37-bb53-462695de0479 | GST                        |  2.580000000 |
| 2021-08-01  | 359dbe84-2381-41ba-b0d6-7f6b248097ab | d73f5aa9-69a5-4081-9c70-48eb7f541673 | RecurringPlan-37-evergreen | 50.000000000 |
| 2021-08-01  | d5e3e9cb-d2ae-418c-a213-9f1fc1065035 | d73f5aa9-69a5-4081-9c70-48eb7f541673 | GST                        |  5.000000000 |
| 2021-09-01  | 5f82ed69-a0f3-4521-850c-92d63c86ab0a | d4b692c8-bfdf-43af-bb5c-8bd0e9929636 | RecurringPlan-37-evergreen | 50.000000000 |
| 2021-09-01  | 9f05eacb-96db-410e-b170-90710c2506c8 | d4b692c8-bfdf-43af-bb5c-8bd0e9929636 | GST                        |  5.000000000 |
+-------------+--------------------------------------+--------------------------------------+----------------------------+--------------+

Any further suggestions on what to look at?

stephane brossier

unread,
Jul 23, 2021, 3:24:40 PM7/23/21
to Adam Wells, Kill Bill users mailing-list
The output of your invoice_items table is not super useful because there is no type now plan id (name) so I don't really know what these items are for.
So assuming they are not usage items, and considering that your Plan only has aRECURRING section for $1, then what are they?

Reply all
Reply to author
Forward
0 new messages