# SACCO YETU — Automatic Payment SMS Workflow

## Purpose
SACCO YETU can accept an incoming M-Pesa or bank transaction SMS from an approved SMS gateway, Android SMS bridge, or bank integration. The message is parsed into payment details and kept pending until an authorized organization administrator approves it.

## Endpoint
`POST /api/sms/incoming-payment`

Required fields:
- `organizationId`
- `message`

Optional:
- `channel`: `mpesa` or `bank`
- `sender`
- `receivedAt`

The parser attempts to extract:
- Transaction/reference code
- Amount
- Account number
- Mobile number
- Transaction date

## Member matching
The organization transaction is matched to a member using the configured member account number first. If the account number is not present or does not match, the member phone number is used when available.

## Approval
Imported payments are never posted directly to a member balance. They are created as **Pending admin approval**. The administrator can approve or reject them from the organization's Contributions/Transactions area.

## Duplicate protection
The platform's existing normalized transaction-reference check prevents the same transaction reference from being recorded more than once in the browser ledger. The database inbox also uses a unique organization/reference constraint.

## Important limitation
A normal web browser cannot silently read SMS messages from a phone. For true automatic operation, connect an approved SMS provider, Android SMS bridge, or bank notification service to the endpoint. Without that integration, members can still record payments manually and administrators can import/verify incoming payments through the supported workflow.
