# Merchant side purchase control

{% hint style="info" %}
Implementation is **OPTIONAL**
{% endhint %}

*Purchase check rules are divided into two groups.*&#x20;

* **Product specific** rules will be sent along with product data request.&#x20;
* **Store based** rules can be configured in Smarts manager UI.&#x20;

### General Flow

* Smarts asks from merchant if the purchase check is needed by sending shopping cart information to merchant.
* Merchant will response with purchase check decision.&#x20;
  * Smarts will lock app and shows the purchase check notification to client.
* Merchant send the purchase check result to Smarts.
  * Smarts will unlock the  app
  * Purchase control supervisor is able to make changes from client shopping cart.
  * Purchase control supervisor is able to cancel the shopping process.
* After purchase check client will be directed to payment process.

{% hint style="danger" %}
App lock will **expire after 4 hours** and app will be unlocked.  This might be happen when client will not appear to purchase check or merchant will not send purchase check result back to Smarts.
{% endhint %}

### Configuration

Visit your store configuration page in Smarts manager UI. Switch merchant side purchase control to **ON** position and implement SDK required methods.

### Implementation

You only need to create a new class, implement **`PurchaseControlAdapter`** interface and fill all required methods.  API endpoints for purchase check are created automatically and secured with token.&#x20;

It is important to add `@Component` annotation on top of the class. There is no restriction for class name or location in your project. Our SDK will find your implementation based on the interface (DI).

```java
import ee.smarts.common.v1.requests.PurchaseControlCheckRequest;
import ee.smarts.common.v1.responses.PurchaseControlCheckResponse;
import ee.smarts.starter.adapter.PurchaseControlAdapter;
import org.springframework.stereotype.Component;

@Component
public class PurchaseControlAdapterImpl implements PurchaseControlAdapter {
    @Override
    public PurchaseControlCheckResponse check(PurchaseControlCheckRequest request) {
        // implement this method
        return null;
    } 
}
```

Send purchase check results back to Smarts by calling send method from`PurchaseControlResultSender`

```java
import ee.smarts.common.v1.requests.PurchaseControlCheckRequest;
import ee.smarts.common.v1.responses.PurchaseControlCheckResponse;
import ee.smarts.starter.adapter.PurchaseControlAdapter;
import org.springframework.stereotype.Component;
import lombok.RequiredArgsConstructor;

@Component
@RequiredArgsConstructor
public class PurchaseControlStoreSideSender{

    private final PurchaseControlResultSender resultSender
    
    public void sendResult(PurchaseControlResult result) {
        resultSender.send(result);
    } 
}
```


---

# 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://developer.smarts.ee/integration/spring-boot-starter/merchant-side-purchase-control.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.
