# Customer Balance Application Extension

Learn about the Customer Balance Application Extension and its methods.

## ID

`billing.customer_balance_application`

## Methods

### Compute Applied Customer Balance 

Determines how much of the customer’s balance to apply toward a bill total. The script receives the invoice total and current customer balance, then returns how much of that balance to apply.

|  |
| **Implementation types** | Script |
| **Optionality** | You must implement this method. |
| **Retry policy** | Stripe doesn’t retry failed requests. |

#### Parameters 

Properties of the `request` object Stripe passes to this method. Your method also receives `config` (your defined input type) and `context` (Stripe execution metadata).

| Name | Type | Nullable | **Description** |
| --- | --- | --- | --- |
| `customerBalance` | [`Billing.MonetaryAmount`](https://docs.stripe.com/extensions/customer-balance-application-extension.md#compute_applied_customer_balance-billing-monetary-amount) | No | The current customer balance available to apply. Positive values indicate debits (the customer owes money), negative values indicate credits. |
| `totalAmount` | [`Billing.MonetaryAmount`](https://docs.stripe.com/extensions/customer-balance-application-extension.md#compute_applied_customer_balance-billing-monetary-amount) | No | The total amount of the invoice before applying any customer balance. |

#### Return value 

| Name | Type | Nullable | **Description** |
| --- | --- | --- | --- |
| `appliedCustomerBalance` | [`Billing.MonetaryAmount`](https://docs.stripe.com/extensions/customer-balance-application-extension.md#compute_applied_customer_balance-billing-monetary-amount) | No | The amount of customer balance to apply to this invoice. Positive values increase the invoice amount (applying a debit), negative values decrease it (applying a credit). Set to zero to apply no balance. |

#### Examples 

```typescript
export default class MyCustomerBalanceApplication implements Billing.CustomerBalanceApplication<MyCustomerBalanceApplicationConfig> {
  computeAppliedCustomerBalance(
    request: Billing.CustomerBalanceApplication.CustomerBalanceApplicationInput,
    config: MyCustomerBalanceApplicationConfig,
    context: Context,
  ): Billing.CustomerBalanceApplication.CustomerBalanceApplicationResult {
    // Your implementation here
    return {
      appliedCustomerBalance: {
        amount: {},
        currency: 'aed',
      },
    };
  }
}
```

### Types

##### Billing.Currency 

```typescript
export type Currency = 'aed' | 'afn' | 'all' | 'amd' | 'ang' | 'aoa' | 'apt' | 'arb' | 'ars' | 'aud' | 'avax' | 'awg' | 'azn' | 'bam' | 'bbd' | 'bdt' | 'bgn' | 'bhd' | 'bif' | 'bmd' | 'bnb' | 'bnd' | 'bob' | 'bov' | 'brl' | 'bsd' | 'btc' | 'btn' | 'buidl' | 'bwp' | 'byn' | 'byr' | 'bzd' | 'cad' | 'cdf' | 'celo' | 'che' | 'chf' | 'chw' | 'clf' | 'clp' | 'cny' | 'cop' | 'cou' | 'crc' | 'cuc' | 'cup' | 'cve' | 'czk' | 'dai' | 'djf' | 'dkk' | 'dop' | 'dzd' | 'eek' | 'egp' | 'ern' | 'etb' | 'eth' | 'eur' | 'eurc' | 'fjd' | 'fkp' | 'frxusd' | 'gbp' | 'gel' | 'ghc' | 'ghs' | 'gip' | 'gmd' | 'gnf' | 'gtq' | 'gyd' | 'hkd' | 'hnl' | 'hrk' | 'htg' | 'huf' | 'hype' | 'idr' | 'ils' | 'inr' | 'iqd' | 'irr' | 'isk' | 'jmd' | 'jod' | 'jpy' | 'kes' | 'kgs' | 'khr' | 'kmf' | 'kpw' | 'krw' | 'kwd' | 'kyd' | 'kzt' | 'lak' | 'lbp' | 'lkr' | 'lrd' | 'lsl' | 'ltl' | 'lvl' | 'lyd' | 'lzd' | 'm' | 'mad' | 'mdl' | 'mga' | 'mkd' | 'mmk' | 'mnt' | 'mop' | 'mro' | 'mru' | 'mur' | 'mvr' | 'mwk' | 'mxn' | 'mxv' | 'myr' | 'mzn' | 'nad' | 'ngn' | 'nio' | 'nok' | 'npr' | 'nzd' | 'omr' | 'pab' | 'pen' | 'pgk' | 'php' | 'pkr' | 'pln' | 'pol' | 'pyg' | 'pyusd' | 'qar' | 'rd' | 're' | 'ron' | 'rsd' | 'rub' | 'rwf' | 'sar' | 'sbd' | 'scr' | 'sdg' | 'sek' | 'sgd' | 'shp' | 'sle' | 'sll' | 'sol' | 'sos' | 'srd' | 'ssp' | 'std' | 'stn' | 'sui' | 'svc' | 'syp' | 'szl' | 'thb' | 'tjs' | 'tmt' | 'tnd' | 'top' | 'trx' | 'try' | 'ttd' | 'twd' | 'tzs' | 'uah' | 'ugx' | 'usd' | 'usdb' | 'usdc' | 'usdg' | 'usdp' | 'usdt' | 'usn' | 'ustb' | 'uyi' | 'uyu' | 'uzs' | 'vef' | 'ves' | 'vnd' | 'vuv' | 'wst' | 'xaf' | 'xcd' | 'xcg' | 'xeur' | 'xlm' | 'xof' | 'xpf' | 'xpl' | 'xusd' | 'yer' | 'zar' | 'zmk' | 'zmw' | 'zwd' | 'zwg' | 'zwl';
```

##### Billing.MonetaryAmount 

Represents a monetary value with amount and currency.

| Name | Type | Nullable | **Description** |
| --- | --- | --- | --- |
| `amount` | [`Decimal`](https://docs.stripe.com/extensions/customer-balance-application-extension.md#compute_applied_customer_balance-decimal) | No | The numerical value. |
| `currency` | [`Billing.Currency`](https://docs.stripe.com/extensions/customer-balance-application-extension.md#compute_applied_customer_balance-billing-currency) | No | The currency code. |

##### Decimal 

Arbitrary-precision decimal type for billing calculations.

```typescript
export interface Decimal {
}
```
