# How to use PayOn Library

## Initialize PAYON's Library&#x20;

{% tabs %}
{% tab title="JAVA" %}

```java
import com.payon.pg.aggregator.ecommerce.gateway.client.CheckoutURIBuilder;
import com.payon.pg.aggregator.ecommerce.gateway.client.CheckoutURIBuilder.Environment;

public class OrderController {

    public static void main(String[] args) throws IOException, InterruptedException {

	CheckoutURIBuilder checkoutURIBuilder = CheckoutURIBuilder.builder()
						.env(Environment.UAT)// UAT:for TEST,PRODUCTION: production
						.apiKey(YOUR API KEY)
						.merchantId(YOUR MERCHANT ID)
						.termId(YOUR TERMINAL ID)
						.txId(YOUR TRANSACTION ID)
						.amount(YOUR CHECK OUT AMOUNT)
						.currency(YOUR CURRENCY)
						.build();
    }
}
```

{% endtab %}

{% tab title="PHP" %}

```php
<?php
	require_once('CheckoutURIBuilder.php');
	$lang        = "en";
	$merchantId  = "YOUR MERCHANT ID";
	$termId      = "YOUR TERM ID";
	$amount      = "YOUR CHECK OUT AMOUNT";
	$txId        = "YOUR TRANSACTION ID";
	$currency    = "YOUR CURRENCY";
	$apiKey        = "YOUR API KEY";
	$checkoutURIBuilder = new CheckoutURIBuilder($lang, $merchantId, $termId, $txId, $amount, $currency, $redirectUri, $apiKey);
	$env = new Environment();
	// get test url function $env::getTestUrl() and get real url function $env::getRealUrl()
	$url = $checkoutURIBuilder::toCheckoutUrlString($env::getTestUrl());
	echo "<a href='".$url."'>Click to Pay</a><br/>";
	
?>
	
```

{% endtab %}
{% endtabs %}

### Get Checkout Link

{% tabs %}
{% tab title="JAVA" %}

```
String checkoutURI = checkoutURIBuilder.toCheckoutUrlString()
```

{% endtab %}

{% tab title="PHP" %}

```php
 <?php
     $checkoutURI = $checkoutURIBuilder::toCheckoutUrlString();
 ?>
```

{% endtab %}
{% endtabs %}

### Get API's Signature

{% tabs %}
{% tab title="JAVA" %}

```java
String sign = checkoutURIBuilder.getSign()
```

{% endtab %}

{% tab title="PHP" %}

```php
 <?php
     $checkoutURI = $checkoutURIBuilder::getSign();
 ?>
```

{% endtab %}
{% endtabs %}

### Arguments

| env        | environment mode(TEST,PRODUCTION)                              |
| ---------- | -------------------------------------------------------------- |
| apiKey     | Merchant's API key, will provided after merchant registration. |
| termId     | Merchant's terminal identification                             |
| merchantId | Merchant's identification                                      |
| amount     | Total amount                                                   |
| Currency   | Currency code (KHR, USD)                                       |


---

# 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.payon.com.kh/payons-library/how-to-use-payon-library.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.
