> For the complete documentation index, see [llms.txt](https://mogami.gitbook.io/mogami/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mogami.gitbook.io/mogami/java-server-sdk/price-provider.md).

# Price provider

By default, the `@X402PayUSDC` annotation uses a fixed price, defined directly in the amount field:

```java
@X402PayUSDC(amount = "5.00")
@GetMapping("/data")
public ResponseEntity<String> getData() {
    return ResponseEntity.ok("Here is your protected data");
}
```

In some cases, however, the required payment amount depends on **runtime conditions.** For example, query parameters, user tiers, or data size.\
To handle this, you can use a **dynamic pricing provider** via the `amountProvider` field.

**🧩 Step 1 — Implement an AmountProvider.**

An `AmountProvider` is a simple Java interface:

```java
public interface AmountProvider {
    BigDecimal getAmount(HttpServletRequest request);
}
```

It receives the current HTTP request and returns the amount.

**Example : Simple fixed provider**

```java
public final class SimpleAmountProvider implements AmountProvider {
    @Override
    public BigDecimal getAmount(HttpServletRequest request) {
        return new BigDecimal("0.10"); // always 10 cents
    }
}
```

**Example : Provider based on query parameters**

```java
public final class TypeBasedProvider implements AmountProvider {
    @Override
    public BigDecimal getAmount(HttpServletRequest request) {
        String type = request.getParameter("type");
        return switch (type) {
            case "image" -> new BigDecimal("0.20");
            case "text" -> new BigDecimal("0.05");
            default -> new BigDecimal("0.01");
        };
    }
}
```

**🧩 Step 2 — Reference your provider in the annotation**

Simply reference the class in the annotation:

```java
@X402PayUSDC(amount = "5.00", amountProvider = TypeBasedProvider.class)
@GetMapping("/generate")
public ResponseEntity<String> generate() {
    return ResponseEntity.ok("Generated content");
}
```

At runtime, Mogami’s resolver automatically:

1. Checks if the provider class is a Spring Bean (`@Component`, `@Service`, etc.).
2. Falls back to manual instantiation if it’s a plain Java class.
3. The `amount` field is ignored if `amountProvider` is set
