# Payments Generate

## Overview
This lambda generates a payment set by
1. Using the `target_id` of the received `abacus_event` to get a `payment_group`'s `group_criteria` from `ows-payment`
2. Using the `group_criteria` to grab eligible payees from `ows-payee`.
3. Getting the `last_payment` amount for each eligible payee from `ows_payment`.
4. Bulk inserting into `payment_group_payment_payee` through `ows-payment`.

This lambda is executed as a part of the payment workflow.

It expects an `abacus_event` JSON object as an argument where the target is a `payment_group_payment`.

## Getting Started

### Requirements

- Python 3.11
- Docker

### OWS Dependencies

- [ows-payee](https://github.com/theorchard/ows-payee)
- [ows-payment](https://github.com/theorchard/ows-payment)

### Installation

Create a `.env` file based on the `.env.shadow` and fill in the values:

```bash
$ cp .env.shadow .env
```

Create a virtual env and install the requirements:

```bash
$ make dev_env
```

### Running

You can run the function locally with: `make run`

Or you can run the function inside Docker with: `make docker_local_up` and trigger an event with `make local_event`

### Testing

You can run the linter and the unit tests locally with: `make lint` and `make test`

Or you can run the linter and the unit tests inside Docker with: `make docker_test`

The integration tests can only be run inside Docker with: `make docker_test_integration`

**Note:**
You might need to login to Docker with the shared AWS account in order to run the integration tests:

```bash
$ awsume <shared_profile>
$ make docker_login
```

### Adding new packages

- For dev packages, add them normally to `requirements-dev.txt`
- For regular packages, add the new top level package name
  and optionally version constraints to `requirements-to-freeze.txt`
- Run `make pip_lock_versions`

### Upgrading packages

Regularly running `make pip_lock_versions` will update and freeze all non-dev dependencies in `requirements.txt`
