# 11. Cancellation

## Cancellation

<mark style="color:green;">`POST`</mark> `{{Base Address}}/api/paywall/private/cancel`

All you have to do is send a request to the address given above. You can use 'Base Address' as you wish for Test environment and Real environment.

{% hint style="info" %}
**Important**: To use the cancellation service, you need to send the '**apikeyprivate**' and '**apiclientprivate**' parameters in the 'Header' section.<br>

[<mark style="color:green;">**PaymentAPI Address**</mark>](/payment-orchestration-integration-document/environment.md)
{% endhint %}

<table><thead><tr><th width="201">Parameter</th><th width="96">Type</th><th width="145">Compulsory</th><th>Description</th></tr></thead><tbody><tr><td>apikeyprivate</td><td>string</td><td>Yes</td><td>The Private Key obtained from the merchant panel.</td></tr><tr><td>apiclientprivate</td><td>string</td><td>Yes</td><td>The Private Client obtained from the merchant panel.</td></tr></tbody></table>

**The parameters that need to be sent to the service are as follows:**

<table><thead><tr><th width="227">Parameter</th><th width="105.33333333333331">Type</th><th width="161">Compulsory</th><th>Description</th></tr></thead><tbody><tr><td>MerchantUniqueCode</td><td>string</td><td>Yes</td><td>The MerchantUniqueCode in the request sent to initiate the payment must have the same value. This code is a unique value provided by your side for each transaction. It is used to uniquely identify and track a payment in all Cancel/Refund/Payment Inquiry operations.</td></tr><tr><td>Date</td><td>date</td><td>Yes</td><td>Transaction date</td></tr><tr><td>MarketPlace:DeleteExistingRecords</td><td>bool</td><td>No</td><td>Within the scope of the marketplace, if the earnings approval for the relevant payment is granted, this parameter must be sent as <strong>true</strong>. When sent as <strong>true</strong>, existing earnings will be deleted after the cancellation request is successfully completed.</td></tr></tbody></table>

{% tabs %}
{% tab title="JSON" %}
{% code overflow="wrap" lineNumbers="true" %}

```json5
{
    "Date": "2023-01-23",
    "MerchantUniqueCode": "12222a2222a",
    "MarketPlace": { // nullable
        "DeleteExistingRecords": false
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="C#" %}

```csharp
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

public class Program
{
    private static readonly HttpClient client = new HttpClient();

    private static async Task Main()
    {
        var data = new 
        {
            Date = "2023-01-23",
            MerchantUniqueCode = "12222a2222a",
        };
        var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
        content.Headers.Add("apikeyprivate", "%PRIVATEKEY%");
        content.Headers.Add("apiclientprivate", "%PRIVATECLIENT%");

        var response = await client.PostAsync("{{Private Base Address}}/api/paywall/private/cancel", content);

        var responseString = await response.Content.ReadAsStringAsync();
        Console.WriteLine(responseString);
    }
}

```

{% endtab %}

{% tab title="Go" %}

```go
package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "net/http"
    "encoding/json"
)

func main() {
    url := "{{Private Base Address}}/api/paywall/private/cancel"
    data := map[string]interface{}{
        "Date": "2023-01-23",
        "MerchantUniqueCode": "12222a2222a",
    }
    reqBody, _ := json.Marshal(data)
    
    req, _ := http.NewRequest("POST", url, bytes.NewBuffer(reqBody))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("apikeyprivate", "%PRIVATEKEY%")
    req.Header.Set("apiclientprivate", "%PRIVATECLIENT%")
    
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
}

```

{% endtab %}

{% tab title="Java" %}

```java
import java.net.http.HttpClient;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.URI;
import java.net.http.HttpResponse.BodyHandlers;
import java.util.HashMap;
import java.util.Map;

public class Main {

    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newHttpClient();

        Map<String, Object> values = new HashMap<String, Object>() {{
            put("Date", "2023-01-23");
            put("MerchantUniqueCode", "12222a2222a");
        }};

        String requestBody = new ObjectMapper().writeValueAsString(values);

        HttpRequest request = HttpRequest.newBuilder()
                .uri(new URI("{{Private Base Address}}/api/paywall/private/cancel"))
                .setHeader("Content-Type", "application/json")
                .setHeader("apikeyprivate", "%PRIVATEKEY%")
                .setHeader("apiclientprivate", "%PRIVATECLIENT%")
                .POST(HttpRequest.BodyPublishers.ofString(requestBody))
                .build();

        HttpResponse<String> response = client.send(request, BodyHandlers.ofString());

        System.out.println(response.body());
    }
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php

$url = '{{Private Base Address}}/api/paywall/private/cancel';
$data = array(
    'Date' => '2023-01-23',
    'MerchantUniqueCode' => '12222a2222a',
);

$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\n" .
                     "apikeyprivate: %PRIVATEKEY%\r\n" . 
                     "apiclientprivate: %PRIVATECLIENT%\r\n",
        'method'  => 'POST',
        'content' => json_encode($data),
    ),
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) { /* Handle error */ }

var_dump($result);
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "{{Private Base Address}}/api/paywall/private/cancel"
headers = {
    'Content-Type': 'application/json',
    'apikeyprivate': '%PRIVATEKEY%',
    'apiclientprivate': '%PRIVATECLIENT%',
}
data = {
    "Date": "2023-01-23",
    "MerchantUniqueCode": "12222a2222a",
}

response = requests.post(url, headers=headers, data=json.dumps(data))

print(response.json())

```

{% endtab %}

{% tab title="Ruby" %}

```ruby
require 'net/http'
require 'uri'
require 'json'

uri = URI.parse("{{Private Base Address}}/api/paywall/private/cancel")
http = Net::HTTP.new(uri.host, uri.port)

request = Net::HTTP::Post.new(uri.request_uri, {
    'Content-Type' => 'application/json',
    'apikeyprivate' => '%PRIVATEKEY%',
    'apiclientprivate' => '%PRIVATECLIENT%',
})
request.body = {Date: "2023-01-23", MerchantUniqueCode: "12222a2222a"}.to_json

response = http.request(request)

puts response.body

```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
import axios from 'axios';

const data = {
    Date: "2023-01-23",
    MerchantUniqueCode: "12222a2222a",
};

axios.post('{{Private Base Address}}/api/paywall/private/cancel', data, {
    headers: {
        'Content-Type': 'application/json',
        'apikeyprivate': '%PRIVATEKEY%',
        'apiclientprivate': '%PRIVATECLIENT%',
    }
})
.then((response) => {
    console.log(response.data);
})
.catch((error) => {
    console.log(error);
});
```

{% endtab %}

{% tab title="Curl" %}

```sh
curl -X POST "{{Private Base Address}}/api/paywall/private/cancel" \
-H "Content-Type: application/json" \
-H "apikeyprivate: %PRIVATEKEY%" \
-H "apiclientprivate: %PRIVATECLIENT%" \
-d '{
    "Date": "2023-01-23",
    "MerchantUniqueCode": "12222a2222a"
}'
```

{% endtab %}
{% endtabs %}

**Response from the service:**

<table><thead><tr><th width="156">Parameter</th><th width="99.33333333333331">Type</th><th>Description</th></tr></thead><tbody><tr><td>ErrorCode</td><td>int</td><td>Error code. If the operation is successful, it returns a value of '0'.</td></tr><tr><td>Result</td><td>bool</td><td>It returns a true or false value. If the operation is successful, it returns 'true'.</td></tr><tr><td>Message</td><td>string</td><td>If the operation is in error, this is the specified message, providing language support based on the locale parameter.</td></tr></tbody></table>

{% tabs %}
{% tab title="JSON" %}
{% code overflow="wrap" lineNumbers="true" %}

```json5
{
    "ErrorCode": 0,
    "Result": true,
    "Message": "Success",
    "Body": null
}
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# 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.paywall.one/payment-orchestration-integration-document/payment-service/11.-cancellation.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.
