# ows-payment

Handles payment records for the abacus system.

## Requirements
- Python 3.13
- Docker
- uv

## Getting Started

Install `uv` if missing. See [Installing uv](https://docs.astral.sh/uv/getting-started/installation/) for details.

  - Homebrew: ```brew install uv```

  - Curl: ```curl -LsSf https://astral.sh/uv/install.sh | sh```

Create your python env and install dependencies:

```bash
$ make dev_env
```

### Setting Up Your Environment

Create a `.env` file from the existing `.env.shadow` file: `cp .env.shadow .env`.
This is where you can set your environment variables:

- `MYSQL_DB_HOST`: 127.0.0.1
- `MYSQL_DB_USER`: copied from [here](https://github.com/theorchard/ows-payment/blob/master/docker-compose.yml#L10)
- `MYSQL_DB_PASS`: copied from [here](https://github.com/theorchard/ows-payment/blob/master/docker-compose.yml#L11)
- `MYSQL_DB_NAME`: copied from [here](https://github.com/theorchard/ows-payment/blob/master/docker-compose.yml#L9)
- `MYSQL_DB_PORT`: 6250
- `MYSQL_TEST_DB_NAME`: add `_test` to the end of the DB Name

### Local Database

To develop using a local database:

```bash
make local_start_db
```

### Snowflake
To connect to Snowflake Cortex Search locally, you will need to set the following environment variables in your `.env` file:

- `SNOWFLAKE_ACCOUNT`: `ORCHARD`
- `SNOWFLAKE_USER`: you Snowflake user
- `SNOWFLAKE_DATABASE`: `ROYALTY_ACCOUNTING`
- `SNOWFLAKE_SCHEMA`: `QA`
- `SNOWFLAKE_CORTEX_SEARCH_SERVICE_NAME`: `PAYMENT_DATA_SEARCH`
- `SNOWFLAKE_PRIVATE_KEY`: optional private key string
- `SNOWFLAKE_PRIVATE_KEY_PATH`: optional the path to your private key file (e.g., `~/.ssh/snowflake/rsa_key.p8`)
- `SNOWFLAKE_KEY_PASSPHRASE`: optional passphrase for your private key if encrypted
- `SNOWFLAKE_LOGIN_TIMEOUT`: optional login timeout in seconds
- `SNOWFLAKE_NETWORK_TIMEOUT`: optional network timeout in seconds

Refer to the following [documentation](https://www.notion.so/Snowflake-7c88cc17b0034e7db669a88fd2962bab) on keys creation and adding to Snowflake.

### Testing

To run the tests, all you have to do is to run:

```bash
make test
```

To run integration tests:

Make sure that You have the integration stak running:

```bash
make local_integration_stack
```

then run the tests

```bash
make test_integration
```

To format the code:
```bash
make format
```

To lint:
```bash
make lint
```

To generate OpenAPI documentation run the following command from the root of the project:
```bash
make openapi
```
*execute the command locally and include the generated file in the pull request*


## Dependency Management

### Some of the libraries we're using

- [`flask-sqlalchemy`](https://flask-sqlalchemy.palletsprojects.com/en/2.x/) for integrating with our ORM framework, [SQLAlchemy](https://www.sqlalchemy.org/).
- [`flask-marshmallow`](https://flask-marshmallow.readthedocs.io/en/latest/) for integrating with [Marshmallow](https://marshmallow.readthedocs.io/en/3.0/),
our object serialization/deserialization tool.

### Adding new packages

  - Regular packages: ```uv add <pkg>```

  - Dev packages: ```uv add <pkg> --dev```

  - Integration packages: ```uv add <pkg> --group integration```

### Upgrading packages

  - All packages: ```uv sync --upgrade```
  
  - A specific package: ```uv sync --upgrade-package <pkg>```

### Notes

Windows users will not be able to use the `make` commands as Make is a Unix util.
Windows users can attempt to install [GNUWin](http://gnuwin32.sourceforge.net/packages/make.htm) to get this functionality.

## Features of the Boilerplate

### Linting

Ruff with a custom config is being used for formatting and linting the code. 

### Third-Party Integrations for Reporting

This boilerplate comes with support for Loggly, Sentry, and Datadog.
