# Payment Service

Payment service interfaces with Stripe and is backed by a database (payment\_service) containing two tables:

* subscriptions - which houses the users/organisations Stripe subscriptions, this contains information about the subscription type, i.e free, basic, pro.
* quota - tracks the amount of resources used
* payments - not yet used, but will track each subscription payment made

## Stripe

The stripe details can be provided on request.

## Database Migrations

This service uses Postgres as it's core database. You can run migrations using:

### Create a migration

```bash
$ make migrate.create name="my_new_migration"
```

### Migrate up

```bash
$ make migrate.local.up
```

### Migrate production/staging database

```bash
$ make migrate.proxy.up password=<database-password>
```

## Protobuf definition

This service exposes a gRPC + Protobuf server, for certain endpoints/functions. You

The protobuf definition can be found in `./proto`, you can re-build the protobuf definitions `$ make build.proto`.

## gRPC endpoints

```
ListSubscriptions(ListSubscriptionsRequest) ListSubscriptionsResponse // Lists subscriptions by user or organisation
ListUsage(ListUsageRequest) ListUsageResponse // Lists usage records (months)
IncrementUsage(IncrementUsageRequest) IncrementUsageResponse // Updates current usage 
CheckQuota(CheckQuotaRequest) CheckQuotaResponse // Returns current usage 
```

## REST endpoint

A couple of public facing Stripe webhooks are exposed via the Ingress controller for this service, which deal with the Stripe payment process.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mediamagic.dev/product-docs/services/payment-service.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
