# Currency

Table name: `currencies`

Description: To deal with money (pricing, payment,...)

### Model

```php
use SaasReady\Models\Currency;
```

#### findByCode

Quickly retrieve the `Currency` instance by using CurrencyCode

```php
use SaasReady\Constants\CurrencyCode;

Currency::findByCode(CurrencyCode::UNITED_STATES_DOLLAR);
Currency::findByCode(CurrencyCode::tryFrom('VND'));
```

### The CurrencyCode Enum

Contains every CurrencyCode around the world.

```php
use SaasReady\Constants\CurrencyCode;
```

### Response Entity

<pre class="language-javascript"><code class="lang-javascript"><strong>type Currency = {
</strong>    uuid: string;
    code: string;
    name: string;
    symbol: string;
    decimal_separator: string;
    thousands_separator: string;
    space_after_symbol: boolean;
    is_active: boolean; // v1.0.1
    created_at: string;
    updated_at: string;
    activated_at: string; // v1.0.1
}
</code></pre>

### Endpoints

#### \[GET] saas/currencies

Get a list of Currencies

Request payload:

```javascript
{
    limit: int; // optional, if this limit is null or not exists, will return ALL
    page: int; 
}
```

Response payload:

```javascript
{
    data: Currency[],
}
```

#### \[GET] saas/currencies/{currencyUuid}

Get single Currency

Response payload:

<pre class="language-javascript"><code class="lang-javascript"><strong>{
</strong>    data: Currency,
}
</code></pre>

#### \[POST] saas/currencies

Create a new Currency

Request payload:

```javascript
{
    code: string;
    name: string;
    symbol: string;
    decimal_separator: string;
    thousands_separator: string;
    space_after_symbol: boolean;
    is_active: boolean; // v1.0.1+
}
```

Response payload:

```javascript
{
    uuid: string,
}
```

#### \[PUT] saas/currencies/{currencyUuid}

Update an existing Currency

Request payload:

```javascript
{
    code: string;
    name: string;
    symbol: string;
    decimal_separator: string;
    thousands_separator: string;
    space_after_symbol: boolean;
    is_active: boolean;  // v1.0.1+
}
```

Response payload:

```javascript
{
    uuid: string,
}
```

#### \[DELETE] saas/currencies/{currencyUuid}

Delete an existing Currency (soft)

Response payload:

```javascript
{}
```

### Helper Commands

#### Activate a Currency (v1.0.1+)

```bash
php artisan saas-ready:activate-entity currency {currencyCode}

php artisan saas-ready:activate-entity currency USD
```

#### Deactivate a Currency (v1.0.1+)

```bash
php artisan saas-ready:deactivate-entity currency {currencyCode}

php artisan saas-ready:deactivate-entity currency VND
```
