# Billing

This class defines the Billing information for a [[User]].

The Billing information includes the plan, the admin email, and the billing portal URL.

## Extends

- `Resource`\<`bkper.Billing`\>

### Constructor

```ts
new Billing(json?, config?): Billing;
```

#### Parameters

| Parameter | Type |
| :------ | :------ |
| `json?` | `Billing` |
| `config?` | [`Config`](https://bkper.com/docs/api/bkper-js/interfaces/config.md) |

#### Returns

`Billing`

#### Overrides

```ts
Resource<bkper.Billing>.constructor
```

### payload

```ts
payload: Billing;
```

The underlying payload data for this resource

#### Inherited from

```ts
Resource.payload
```

### getAdminEmail()

```ts
getAdminEmail(): string | undefined;
```

Gets the admin email for this User's billing account.

#### Returns

`string` \| `undefined`

The billing admin email

***

### getCheckoutUrl()

```ts
getCheckoutUrl(
   plan, 
   successUrl?, 
   cancelUrl?, 
cycle?): Promise<string | undefined>;
```

Gets the URL to redirect the User to the billing checkout.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `plan` | `string` | The plan to checkout |
| `successUrl?` | `string` | The URL to redirect to after the User has successfully checked out |
| `cancelUrl?` | `string` | The URL to redirect to in case the checkout is cancelled |
| `cycle?` | `string` | The billing cycle to checkout - "monthly" (default) or "yearly" |

#### Returns

`Promise`\<`string` \| `undefined`\>

The URL to redirect the User to the billing checkout

***

### getCounts()

```ts
getCounts(): Promise;
```

Gets the transaction counts associated to the User's billing account.

#### Returns

`Promise`\<`Counts`\>

The transaction counts associated to the User's billing account

***

### getDaysLeftInTrial()

```ts
getDaysLeftInTrial(): number | undefined;
```

Gets the number of days left in User's trial period.

#### Returns

`number` \| `undefined`

The number of days left in trial period

***

### getEmail()

```ts
getEmail(): string | undefined;
```

Gets the email for the User.

#### Returns

`string` \| `undefined`

The User's email

***

### getHostedDomain()

```ts
getHostedDomain(): string | undefined;
```

Gets the hosted domain for the User.

#### Returns

`string` \| `undefined`

The User's hosted domain

***

### getPlan()

```ts
getPlan(): string | undefined;
```

Gets the current plan of the User.

#### Returns

`string` \| `undefined`

The User's plan

***

### getPortalUrl()

```ts
getPortalUrl(returnUrl): Promise<string | undefined>;
```

Gets the URL to redirect the User to the billing portal.

#### Parameters

| Parameter | Type | Description |
| :------ | :------ | :------ |
| `returnUrl` | `string` | The URL to return to after the User has been redirected to the billing portal |

#### Returns

`Promise`\<`string` \| `undefined`\>

The URL to redirect the User to the billing portal

***

### getTotalTransactionsThisMonth()

```ts
getTotalTransactionsThisMonth(): number | undefined;
```

Gets the number of total transactions this month for the User's billing account.

#### Returns

`number` \| `undefined`

The number of total transactions this month

***

### getTotalTransactionsThisYear()

```ts
getTotalTransactionsThisYear(): number | undefined;
```

Gets the number of total transactions this year for the User's billing account.

#### Returns

`number` \| `undefined`

The number of total transactions this year

***

### hasStartedTrial()

```ts
hasStartedTrial(): boolean | undefined;
```

Tells if the User has started the trial period.

#### Returns

`boolean` \| `undefined`

True if the User has started the trial period

***

### isEnabled()

```ts
isEnabled(): boolean | undefined;
```

Tells if billing is enabled for the User.

#### Returns

`boolean` \| `undefined`

True if billing is enabled for the User

***

### isPlanOverdue()

```ts
isPlanOverdue(): boolean | undefined;
```

Tells if the User's current plan payment is overdue.

#### Returns

`boolean` \| `undefined`

True if the plan payment is overdue

***

### json()

```ts
json(): Billing;
```

Gets an immutable copy of the JSON payload for this resource.

#### Returns

`Billing`

An immutable copy of the json payload

#### Inherited from

```ts
Resource.json
```
