# Payoneer Payments Payout

## Overview

This lambda creates batches of payments and sends to payee service by:

1. Using the `target_id` of the received `abacus_event` to determine which `payment-group-payment`'s accounts payments are to be send.
2. Requesting ows-payment service to get accounts by payment_group_payment_id.
3. Create batches of payment-group-payment accounts by program_id.
4. Process the account's payment information.
5. Create separate entries for each batch in the payment_group_payment_batch table, and batches accounts in the payment_group_payment_batch_account table.
6. Create an abacus_state for each payment_group_payment_batch.
7. Create an abacus_event for each payment_group_payment_batch to trigger the committing to subledger process.
8. Send payments to payoneer.

## Requirements

- Python 3.11
- Docker

## OWS Dependencies

- [ows-royalties](https://github.com/theorchard/ows-royalties)
- [ows-abacus-state](https://github.com/theorchard/ows-abacus-state)
- [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`
