# 5. Provision Close

## Provision Close

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

You just need to make a request to the address provided above. You can use the 'Base Address' as you like for both the Test environment and the Production environment.

{% hint style="info" %}
**Important**: To use the Provision Close service, you need to send the '**apikeypublic**' and '**apiclientpublic**' parameters in the 'Header' field.

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

<table><thead><tr><th width="162">Parameter</th><th width="112">Type</th><th width="166">Compulsory</th><th width="403">Description</th></tr></thead><tbody><tr><td>apikeypublic</td><td>string</td><td>Yes</td><td>The Public Key you obtained from the merchant panel.</td></tr><tr><td>apiclientpublic</td><td>string</td><td>Yes</td><td>The Public Client you 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="226">Parameter</th><th width="114">Type</th><th width="166">Compulsory</th><th>Description</th></tr></thead><tbody><tr><td>MerchantUniqueCode</td><td>string</td><td>Yes</td><td>It must be the same value as the MerchantUniqueCode sent in the request to initiate the payment. This code is the unique value provided by you for the transaction. It is used to uniquely identify and track a payment for all Cancel/Refund/Payment Inquiry operations.</td></tr><tr><td>Date</td><td>date</td><td>Yes</td><td>The date information when the payment was made</td></tr><tr><td>ProvisionAmount</td><td>decimal?</td><td>No</td><td>The final amount at which the payment authorization will be closed. It is a nullable value; if left empty or sent as 0, the authorization will be closed with the main amount.</td></tr></tbody></table>

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

```json5
{
    "Date": "2024-06-13",
    "MerchantUniqueCode": "aaa"
}
```

{% 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(string[] args)
    {
        var data = new
        {
            MerchantUniqueCode = "aaa"
        };

        client.DefaultRequestHeaders.Add("apikeypublic", "%PUBLICKEY%");
        client.DefaultRequestHeaders.Add("apiclientpublic", "%PUBLICCLIENT%");

        var content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
        var response = await client.PostAsync("{{Base Adres}}/api/paywall/payment/end3d", content);

        var responseString = await response.Content.ReadAsStringAsync();
        var responseObject = JsonConvert.DeserializeObject<Response>(responseString);

        Console.WriteLine("ErrorCode: " + responseObject.ErrorCode);
        Console.WriteLine("Result: " + responseObject.Result);
        Console.WriteLine("Message: " + responseObject.Message);
    }

    public class Response
    {
        public int ErrorCode { get; set; }
        public bool Result { get; set; }
        public string Message { get; set; }
        public string Body { get; set; }
    }
}
```

{% endtab %}

{% tab title="GO" %}

```go
package main

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

type Response struct {
	ErrorCode int
	Result    bool
	Message   string
	Body      string
}

type Request struct {
	MerchantUniqueCode string `json:"MerchantUniqueCode"`
}

func main() {
	url := "{{Base Adres}}/api/paywall/payment/end3d"
	reqBody := &Request{
		MerchantUniqueCode: "aaa",
	}

	reqBodyBytes := new(bytes.Buffer)
	json.NewEncoder(reqBodyBytes).Encode(reqBody)

	req, _ := http.NewRequest("POST", url, reqBodyBytes)

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("apikeypublic", "%PUBLICKEY%")
	req.Header.Set("apiclientpublic", "%PUBLICCLIENT%")

	client := &http.Client{}
	resp, err := client.Do(req)

	if err != nil {
		panic(err)
	}

	defer resp.Body.Close()

	body, _ := ioutil.ReadAll(resp.Body)

	var responseObj Response
	json.Unmarshal(body, &responseObj)

	fmt.Println("ErrorCode:", responseObj.ErrorCode)
	fmt.Println("Result:", responseObj.Result)
	fmt.Println("Message:", responseObj.Message)
}
```

{% endtab %}

{% tab title="Java" %}

```java
import okhttp3.*;
import org.json.*;

public class Main {
    public static void main(String[] args) {
        OkHttpClient client = new OkHttpClient();

        MediaType mediaType = MediaType.parse("application/json");
        JSONObject json = new JSONObject();
        json.put("MerchantUniqueCode", "aaa");
        
        RequestBody body = RequestBody.create(mediaType, json.toString());
        Request request = new Request.Builder()
        .url("{{Base Adres}}/api/paywall/payment/end3d")
        .post(body)
        .addHeader("Content-Type", "application/json")
        .addHeader("apikeypublic", "%PUBLICKEY%")
        .addHeader("apiclientpublic", "%PUBLICCLIENT%")
        .build();

        try {
            Response response = client.newCall(request).execute();
            String responseString = response.body().string();

            // Parse the response
            JSONObject jsonResponse = new JSONObject(responseString);
            System.out.println("ErrorCode: " + jsonResponse.getInt("ErrorCode"));
            System.out.println("Result: " + jsonResponse.getBoolean("Result"));
            System.out.println("Message: " + jsonResponse.getString("Message"));
            
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
$url = '{{Base Adres}}/api/paywall/payment/end3d';
$data = array(
    "MerchantUniqueCode" => "aaa"
);
$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\n" .
                     "apikeypublic: %PUBLICKEY%\r\n" . 
                     "apiclientpublic: %PUBLICCLIENT%\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 */ }

// Decode
$response = json_decode($result);

// ErrorCode-Result-Message
echo "ErrorCode: " . $response->ErrorCode . "\n";
echo "Result: " . ($response->Result ? "true" : "false") . "\n";
echo "Message: " . $response->Message . "\n";
?>
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = '{{Base Adres}}/api/paywall/payment/end3d'
headers = {
    'Content-Type': 'application/json',
    'apikeypublic': '%PUBLICKEY%',
    'apiclientpublic': '%PUBLICCLIENT%'
}
data = {
    "MerchantUniqueCode": "aaa"
}
response = requests.post(url, headers=headers, data=json.dumps(data))

# Parsing the response
response_json = response.json()

print('ErrorCode:', response_json['ErrorCode'])
print('Result:', response_json['Result'])
print('Message:', response_json['Message'])
```

{% endtab %}

{% tab title="Ruby" %}

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

uri = URI.parse("{{Base Adres}}/api/paywall/payment/end3d")
request = Net::HTTP::Post.new(uri)
request.content_type = "application/json"
request["Apikeypublic"] = "%PUBLICKEY%"
request["Apiclientpublic"] = "%PUBLICCLIENT%"
request.body = JSON.dump({
  "MerchantUniqueCode" => "aaa"
})

req_options = {
  use_ssl: uri.scheme == "https",
}

response = Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
  http.request(request)
end

response = JSON.parse(response.body)

puts "ErrorCode: #{response['ErrorCode']}"
puts "Result: #{response['Result']}"
puts "Message: #{response['Message']}"
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
import * as https from 'https';

const data = JSON.stringify({
  "MerchantUniqueCode": "aaa"
});

const options = {
  hostname: '{{Base Adres}}',
  port: 443,
  path: '/api/paywall/payment/end3d',
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'apikeypublic': '%PUBLICKEY%',
    'apiclientpublic': '%PUBLICCLIENT%'
  }
};

const req = https.request(options, (res) => {
  res.on('data', (d) => {
    // Parse the response
    const response = JSON.parse(d.toString());

    console.log(`ErrorCode: ${response.ErrorCode}`);
    console.log(`Result: ${response.Result}`);
    console.log(`Message: ${response.Message}`);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();
```

{% endtab %}

{% tab title="Curl" %}

```sh
curl --location --request POST '{{Base Adres}}/api/paywall/payment/end3d' \
--header 'Content-Type: application/json' \
--header 'apikeypublic: %PUBLICKEY%' \
--header 'apiclientpublic: %PUBLICCLIENT%' \
--data-raw '{
    "MerchantUniqueCode": "aaa"
}'
```

{% endtab %}
{% endtabs %}

**The response returned from the service:**

<table><thead><tr><th width="185.33333333333331">Parameter</th><th width="96">Type</th><th>Description</th></tr></thead><tbody><tr><td>ErrorCode</td><td>int</td><td>This indicates the result of the operation. It returns '0' if successful, otherwise '1'.</td></tr><tr><td>Result</td><td>string</td><td>It returns 'true' if the operation is successful, otherwise 'false'.</td></tr><tr><td>Message</td><td>string</td><td>It reports the result message of the operation.</td></tr></tbody></table>

**Sample Code:**

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

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

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