Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KillBill allows recording a usage with the wrong unit type #2013

Open
reshmabidikar opened this issue May 2, 2024 · 1 comment
Open

KillBill allows recording a usage with the wrong unit type #2013

reshmabidikar opened this issue May 2, 2024 · 1 comment

Comments

@reshmabidikar
Copy link
Contributor

Steps to reproduce:

  1. Upload the following catalog:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--
  ~ Copyright 2014-2020 Groupon, Inc
  ~ Copyright 2014-2020 The Billing Project, LLC
  ~
  ~ The Billing Project licenses this file to you under the Apache License, version 2.0
  ~ (the "License"); you may not use this file except in compliance with the
  ~ License.  You may obtain a copy of the License at:
  ~
  ~    http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  ~ WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
  ~ License for the specific language governing permissions and limitations
  ~ under the License.
  -->

<catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="CatalogSchema.xsd ">
    <effectiveDate>2010-02-08T00:00:00+00:00</effectiveDate>
    <catalogName>Cloud</catalogName>
    <recurringBillingMode>IN_ARREAR</recurringBillingMode>
    <currencies>
        <currency>USD</currency>
    </currencies>
    <units>
        <unit name="server-hourly-type-1"/>
		<unit name="server-hourly-type-2"/>
    </units>
    <products>
        <product name="Server">
            <category>BASE</category>
        </product>
    </products>
    <rules>
        <changePolicy>
            <changePolicyCase>
                <policy>IMMEDIATE</policy>
            </changePolicyCase>
        </changePolicy>
        <changeAlignment>
            <changeAlignmentCase>
                <alignment>START_OF_BUNDLE</alignment>
            </changeAlignmentCase>
        </changeAlignment>
        <cancelPolicy>
            <cancelPolicyCase>
                <policy>IMMEDIATE</policy>
            </cancelPolicyCase>
        </cancelPolicy>
        <createAlignment>
            <createAlignmentCase>
                <alignment>START_OF_BUNDLE</alignment>
            </createAlignmentCase>
        </createAlignment>
        <billingAlignment>
            <billingAlignmentCase>
                <alignment>ACCOUNT</alignment>
            </billingAlignmentCase>
        </billingAlignment>
        <priceList>
            <priceListCase>
                <toPriceList>DEFAULT</toPriceList>
            </priceListCase>
        </priceList>
    </rules>
    <plans>
        <plan name="server-monthly-standard">
            <product>Server</product>
            <finalPhase type="EVERGREEN">
                <duration>
                    <unit>UNLIMITED</unit>
                </duration>
                <recurring>
                    <billingPeriod>MONTHLY</billingPeriod>
                    <recurringPrice>
                        <price>
                            <currency>USD</currency>
                            <value>100.00</value>
                        </price>
                    </recurringPrice>
                </recurring>
                <usages>
                    <usage name="server-monthly-server-hourly-standard" billingMode="IN_ARREAR" usageType="CONSUMABLE">
                        <billingPeriod>MONTHLY</billingPeriod>
                        <tiers>
                            <tier>
                                <blocks>
                                    <tieredBlock>
                                        <unit>server-hourly-type-1</unit>
                                        <size>1</size>
                                        <prices>
                                            <price>
                                                <currency>USD</currency>
                                                <value>1.00</value>
                                            </price>
                                        </prices>
                                        <max>100000</max>
                                    </tieredBlock>
                                </blocks>
                            </tier>
                        </tiers>
                    </usage>
                </usages>
            </finalPhase>
        </plan>
 		<plan name="server-monthly-premium">
            <product>Server</product>
            <finalPhase type="EVERGREEN">
                <duration>
                    <unit>UNLIMITED</unit>
                </duration>
                <recurring>
                    <billingPeriod>MONTHLY</billingPeriod>
                    <recurringPrice>
                        <price>
                            <currency>USD</currency>
                            <value>0.00</value>
                        </price>
                    </recurringPrice>
                </recurring>
                <usages>
                    <usage name="server-monthly-server-hourly-premium" billingMode="IN_ARREAR" usageType="CONSUMABLE">
                        <billingPeriod>MONTHLY</billingPeriod>
                        <tiers>
                            <tier>
                                <blocks>
                                    <tieredBlock>
                                        <unit>server-hourly-type-2</unit>
                                        <size>1</size>
                                        <prices>
                                            <price>
                                                <currency>USD</currency>
                                                <value>2.00</value>
                                            </price>
                                        </prices>
                                        <max>100000</max>
                                    </tieredBlock>
                                </blocks>
                            </tier>
                        </tiers>
                    </usage>
                </usages>
            </finalPhase>
        </plan>        
    </plans>
    <priceLists>
        <defaultPriceList name="DEFAULT">
            <plans>
                <plan>server-monthly-standard</plan>
                <plan>server-monthly-premium</plan>
            </plans>
        </defaultPriceList>
    </priceLists>
</catalog>
  1. Create a subscription to the server-monthly-standard plan (uses server-hourly-type-1 unitType)
  2. Record a usage with unitType=server-hourly-type-2 as follows:
curl -v \
    -X POST \
    -u admin:password \
    -H "X-Killbill-ApiKey: test" \
    -H "X-Killbill-ApiSecret: test" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H "X-Killbill-CreatedBy: demo" \
    -H "X-Killbill-Reason: demo" \
    -H "X-Killbill-Comment: demo" \
     -d '{"subscriptionId":"c23cebcc-0972-4a66-a779-30a8a697daa0", "trackingId": "t1", "unitUsageRecords":[{"unitType":"server-hourly-type-2","usageRecords":[{"recordDate":"2024-05-03T16:00:00.000Z","amount":1}]}]}' \
    "http://localhost:8080/1.0/kb/usages"

The usage is recorded successfully. Expected Behavior: An error should be displayed indicating that the wrong unit is specified.

  1. Record a usage with unitType=dummy as follows:
curl -v \
    -X POST \
    -u admin:password \
    -H "X-Killbill-ApiKey: test" \
    -H "X-Killbill-ApiSecret: test" \
    -H "Content-Type: application/json" \
    -H "Accept: application/json" \
    -H "X-Killbill-CreatedBy: demo" \
    -H "X-Killbill-Reason: demo" \
    -H "X-Killbill-Comment: demo" \
     -d '{"subscriptionId":"c23cebcc-0972-4a66-a779-30a8a697daa0", "trackingId": "t1", "unitUsageRecords":[{"unitType":"dummy","usageRecords":[{"recordDate":"2024-05-03T16:00:00.000Z","amount":1}]}]}' \
    "http://localhost:8080/1.0/kb/usages"

Again, the usage is recorded successfully, although there is no unitType=dummy in the catalog.

@reshmabidikar reshmabidikar changed the title KB allows recording a usage with the wrong unittype KillBill allows recording a usage with the wrong unit type May 2, 2024
@shaun-forgie
Copy link

shaun-forgie commented May 6, 2024

So summarising the ticket...a subscription based on a server-monthly-standard plan defined in the above catalog currently allows data submitted to the /1.0/kb/usages api to:

  1. Record usage for usage unit type not defined in plan : submitted value [unitType=server-hourly-type-2]
  2. Record usage for non-existant usage unit type : submitted value [unitType=dummy]

May I suggest for clarity we rename the issue Recording Usage - improve unit type validation checks

Also what are the implications on the billing cycle ? Do they result in invoice items being generated or are they ignored?

Validation failures should also return an appropriate error code indicating which validation check they failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants