# UnbundledDiscount

## Program ID

MetraPipeline.MTUBDplugin.1

## Description

Unbundled discounts are "real time" discounts that take place while processing a session. Usually, an unbundled discount is a set of rules that may or may not apply to the current session. For instance, an unbundled discount might to give all transactions that occur on Thanksgiving a 20% discount. Another example might be a $2 discount on all dial-in calls.

The unbundled discount plugin is different from the bundled discount plugin because it attempts to apply all unbundled discounts to the current session. For instance, if the system is configured with 10 unbundled discounts, the unbundled discount plugin will evaluate the rules for all 10 discounts to see if they apply or not.

The UnbundledDiscounts attempts to apply all unbundled discounts to the current session. For instance, you might have two unbundled discounts: 1) 10% Off if you have used over $100.00 during this billing cycle and 2) and 10% off if you are a new subscriber. In this case, the UnbundledDiscount plugin would determine that both discounts apply and you get a total 20% discount. Since multiple discounts apply, the StringForMultipleDiscounts value is set as the discount name.

The Unbundled discount plug-in can recalculate the amount in the pipeline if PostDiscountAmount is set to _Amount. However, it does not run in its own pipeline.

## Required Input Properties

Tag name | Value type | Description
TariffID | Long | The ID of the Tariff for the account we are currently processing.
Amount | decimal | The amount that will be discounted.

## Required Output Properties

Tag name | Value type | Description
DiscountTrigger | Boolean | The plugin will set this value to true if any discounts were calculated. This property triggers the pipeline to write information to the unbundled discount table.
DiscountID | long | The ID of the calculated discounts.
DiscountName | string | The name of the applied discount.
DiscountTaxAmount | decimal | Unused. Will allways be 0.
PostDiscountAmount | decimal | Amount - DiscountAmount.

## Additional Configuration Tags

Tag name | Value type | Description
DiscountsDirectory | String | This value should always be "discounts" unless you are changing the location of discounts.xml.
discount_filename | String | Should be discounts.xml
InvertDiscountAmount | Boolean | If true, the calculated discount will be a negative amount.
StringForMultipleDiscounts | String | Multiple discounts may apply for a given session. This is the string that the user will see in MPS if multiple discounts were calculated.
IDForMultipleDiscounts | long | The discount ID for multiple discounts.

## Configuration Example

<configdata>
<DiscountsDirectory>Discounts</DiscountsDirectory>
<discount_filename>Discounts.xml</discount_filename>
<DiscountAmount>DiscountAmount</DiscountAmount>
<PostDiscountAmount>PostDiscountAmount</PostDiscountAmount>
<DiscountTrigger>DiscountTrigger</DiscountTrigger>
<DiscountID>DiscountID</DiscountID>
<DiscountName>DiscountName</DiscountName>
<DiscountTaxAmount>discounttaxamount</DiscountTaxAmount>
<TariffID>tariffID</TariffID>
<Amount>_Amount</Amount>
<InvertDiscountAmount ptype="BOOLEAN">true</InvertDiscountAmount>
<StringForMultipleDiscounts>multiple discounts apply
</StringForMultipleDiscounts>
<IDForMultipleDiscounts ptype="INTEGER">1000</IDForMultipleDiscounts>
</configdata>

## Remarks

- The string for multiple discounts will likely be replaced in the near future with an enumerated type fully qualified name.

- If the system is configured with multiple unbundled discounts performance may suffer. This is because all the unbundled discounts must be evaluated when processing a session and because additional database writes may be required.