# Return URL with IPN (Instant Payment Notification)

For normal payment flow, the buyer browser is being redirected to a hosted payment page, financial institution or channel page(if any), and then returned to the merchant website or system. Users might close the browser any time throughout the payment process, even if the payment is completed, successfully or failed. Another possible reason that rarely happens is the network connectivity issue. As a result, the payment gateway is unable to update the merchant system on the payment status. Therefore, merchants are recommended to implement IPN to acknowledge(ACK) upon the receiving of status from gateway. Otherwise the callback worker will resend the payment status within a time interval.

## Implementation:

**Step 1:** Logon to merchant admin, choose “Yes” to “Enable Return URL with IPN”, as shown:-

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXdavmROOVzLnwnKarRdZBNHeQ-fJF1fNyKSVIubdePJHu5HzePbalJJBUcGgexeq8M7dIu1RyRiv33jNq4ijkAoN20h6cM0eH1Ip7rDtFyg4018VWUlwv6vOfBW9ghRnVTyVpLHkb34oPpxFezJJHBjE-laASAypetH63h5O5ZcxlGgJzAM5A?key=YOQU3AbjLOhXrKaT0sW92g" alt=""><figcaption></figcaption></figure>

**Step 2:** There are 2 approaches to ack on receiving payment status.&#x20;

1. Simple front-end snippet: copy the Javascript (JS) code from merchant admin and paste it on the merchant receipt page (which shows payment success/failed), preferable in the HTML header, before \</head> tag.
2. Advanced back-end scripting: merchant is to echo back all the POST variables with one additional variable, i.e. “treq” with value 1. PHP sample code is provided below.

**URL:** [https://pg.e2pay.co.id/RMS/API/chkstat/returnipn.php](https://pay.merchant.razer.com/RMS/API/chkstat/returnipn.php)

**Step 3:** Merchant to prepare a Notify URL and Callback URL script, which is similar to return URL script but serves at the backend, in order to receive consequent payment notification in case the merchant system misses the first notification attempt from the payment gateway.

### Example of back-end IPN script for PHP (combined with return URL script)

```php
<?php

$sec_key ="xxxxxxxxxx"; //Replace xxxxxxxxxx with Secret_Key

$_POST[treq]    =	1; // Additional parameter for IPN

// Value always 1. Do not change this value.
$tranID 	=	$_POST['tranID'];
$orderid 	=	$_POST['orderid'];
$status 	=	$_POST['status'];
$domain 	=	$_POST['domain'];
$amount 	=	$_POST['amount'];
$currency 	=	$_POST['currency'];
$appcode 	=	$_POST['appcode'];
$paydate 	=	$_POST['paydate'];
$skey 	        =	$_POST['skey'];

/***********************************************************
* Snippet code in purple color is the enhancement required
* by merchant to add into their return script in order to
* implement backend acknowledge method for IPN
************************************************************/
while ( list($k,$v) = each($_POST) ) {
  $postData[]= $k."=".$v;
}
$postdata	= implode("&",$postData);
$url 		= "https://pg.e2pay.co.id/RMS/API/chkstat/returnipn.php";
$ch 		= curl_init();
curl_setopt($ch, CURLOPT_POST			, 1 	    );
curl_setopt($ch, CURLOPT_POSTFIELDS		, $postdata );
curl_setopt($ch, CURLOPT_URL			, $url      );
curl_setopt($ch, CURLOPT_HEADER		        , 1	    );
curl_setopt($ch, CURLINFO_HEADER_OUT	        , TRUE	    );
curl_setopt($ch, CURLOPT_RETURNTRANSFER 	, 1 	    );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER 	, FALSE     );
curl_setopt($ch, CURLOPT_SSLVERSION             , 6         );  // use only TLSv1.2
$result = curl_exec( $ch );
curl_close( $ch );

/***********************************************************
* To verify the data integrity sending by PG
************************************************************/
$key0 = md5( $tranID.$orderid.$status.$domain.$amount.$currency );
$key1 = md5( $paydate.$domain.$key0.$appcode.$sec_key );
if( $skey != $key1 ) $status= -1; // Invalid transaction
if ( $status == "00" ) {
  if ( check_cart_amt($orderid, $amount) ) {
    // write your script here .....
  }
} else {
  // failure action
}

?>

```


---

# 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://e2payprod.gitbook.io/payment-gateway/api-documentation/technical-doc-of-fiuu-id/payment-response-parameter/payment-status-notification-merchant-webhook-or-the-3-endpoints/return-url-with-ipn-instant-payment-notification.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.
