---
title: Cancel - API Checkout
slug: en/nicepay-api-cancel-api-checkout
description: Information about API Checkout - Cancel for all payment methods provided by NICEPAY
image: https://archbee-image-uploads.s3.amazonaws.com/ZHvSjR5ZrsoxwKbJa3xmo/og8vEmp7qeqcuj0sTdn_A_microsoftteams-image.png
icon: {"faIcon":"fa-solid fa-book"}
docTags: 
createdAt: 2022-09-21T02:56:12.000Z
---

# About Cancel - API Checkout

***

This API uses to cancel the transaction that will ongoing. Specific to VA, the transaction can only cancel before makes payment. After the transaction is cancelled, Customer must register again from the beginning through [Registration - API Checkout](docId\:pjBflBNCehkuuuqQSAiug).



# API Cancel - API Checkout

***

| **API URL**         | `/nicepay/direct/v2/cancel`                                |
| ------------------- | ---------------------------------------------------------- |
| **Request Method**  | `POST`                                                     |
| **Header**          | `Content-Type: application/json`****                       |
| **Merchant Token**  | SHA256 (`timestamp`+ `iMid`+ `tXid`+ `amt`+ `merchantKey`) |



## Request Parameter for Cancel - API Checkout

***

| **Parameter**                                                   | **Type** | **Size** | **Description**                                        | **Remark**                                                       |
| --------------------------------------------------------------- | -------- | -------- | ------------------------------------------------------ | ---------------------------------------------------------------- |
| `timeStamp`<br /><font color="#2166ae">Required</font>          | N        | 14       | API Request Timestamp                                  | 20221219111294                                                   |
| `tXid`<br /><font color="#2166ae">Required</font>               | AN       | 30       | Transaction ID<br />                                   | NORMALTEST00202212191104443483                                   |
| `iMid`<br /><font color="#2166ae">Required</font>               | AN       | 10       | Merchant ID<br />                                      | NORMALTEST                                                       |
| `payMethod`<br /><font color="#2166ae">Required</font>          | N        | 2        | [Payment Method Code](docId\:NQ1y7vMa25ZtvQHN5He6W)    | 02                                                               |
| `cancelType`<br /><font color="#2166ae">Required</font>         | N        | 2        | [Cancel Type Code](docId\:VNHGJOXcH1WJMHnlKYVOC)<br /> | 1                                                                |
| `merchantToken`<br /><font color="#2166ae">Required</font>      | AN       | 255      | Merchant Token<br />                                   | 63d44f80942cc915f6d736995797470ac2918a9f88b6fb762608541145e65bd8 |
| `amt`<br /><font color="#2166ae">Required</font>                | N        | 12       | Payment Amount<br />                                   | 10000                                                            |
| `cancelMsg`<br /><font color="#2166ae">Required</font>          | AN       | 255      | Cancel Message                                         | Request Cancel                                                   |
| `preauthToken`                                                  | AN       | 100      | Pre-Auth Token                                         | d4ef98b26f917a697691807cf…                                       |
| `referenceNo`<br /><font color="#2166ae">Optional For CC</font> | ANS      | 40       | Merchant Cancel Number                                 | CancelNo20160525000-52104                                        |
| `cancelServerIp`                                                | AN       | 15       | Server IP                                              | 127.0.0.1                                                        |
| `cancelUserId`                                                  | AN       | 30       | User ID                                                | Admin                                                            |
| `cancelUserIp`                                                  | AN       | 15       | User IP                                                | 127.0.0.1                                                        |
| `cancelUserInfo`                                                | AN       | 100      | User Information                                       | Test Cancel                                                      |
| `cancelRetryCnt`                                                | N        | 2        | Retry Count                                            | 5                                                                |
| `worker`                                                        | AN       | 10       | Worker                                                 | Worker                                                           |



## Response Parameter for Cancel - API Checkout

***

| **Parameter**                                                         | **Type** | **Size** | **Description**                                             | **Remark**                                             |
| --------------------------------------------------------------------- | -------- | -------- | ----------------------------------------------------------- | ------------------------------------------------------ |
| `resultCd`                                                            | N        | 4        |  [Result Code](docId:9eC3yH9CQqpb6cRWauWWO)                 | 0000                                                   |
| `resultMsg`                                                           | AN       | 255      | Result Message: [Error Code](docId\:FsX1GESJKxOp0T9rvUHp_)  | SUCCESS                                                |
| `tXid`                                                                | AN       | 30       | Transaction ID                                              | NORMALTEST00202212191104443483<br /><br />When Success |
| `referenceNo`                                                         | ANS      | 40       | Merchant Order Number                                       | ORDER20221012080918<br /><br />When Success            |
| `transDt`                                                             | N        | 8        | Transaction Date                                            | 20221219<br /><br />When Success                       |
| `transTm`                                                             | N        | 6        | Transaction Time                                            | 110444<br /><br />When Success                         |
| `amt`                                                                 | N        | 12       | Amount                                                      | 10000<br /><br />When Success                          |
| `description`                                                         | AN       | 255      | Description                                                 |                                                        |
| `canceltXid`                                                          | AN       | 30       | Cancel Transaction ID                                       |                                                        |
| `cancelTrxSn`                                                         | AN       | 32       | Cancel Transaction Number                                   |                                                        |
| `cancelReferenceNo`<br /><font color="#2166ae">Optional For CC</font> | AN       | 40       | Merchant Cancel Number                                      |                                                        |



## Sample Parameter for Cancel - API Checkout

***

### Request Parameter

:::CodeblockTabs
cURL

```curl
curl --location 'https://dev.nicepay.co.id/nicepay/direct/v2/cancel' \
--header 'Content-Type: application/json' \
--data '{
    "timeStamp" : "20251111011147",
    "iMid" : "IONPAYTEST",
    "tXid" : "IONPAYTEST02202511110137007677",
    "payMethod" : "02",
    "merchantToken" : "0eeb02a32bffdc6309a672b3ef7ea35f8fb2b20c1fda11e4cbdb76313d9f2085",
    "amt" : "10000",
    "cancelType" : "1",
    "cancelMsg" : "Cancel Testing Transaction",
    "cancelUserId" : "",
    "cancelUserIp" : "127.0.0.1",
    "cancelServerIp" : "127.0.0.1",
    "cancelUserInfo" : "",
    "cancelRetryCnt" : "",
    "worker" : ""
}'
```

Node.js

```nodejs
const SecondApiVersion = require("../lib/secondApiVersion.js");
const cons = require("./sharedConfig.js");

const config = {
  isProduction: false,
  isCloudServer: false,
  merchantKey: cons.merchantKey,
};

let parameterCancel = {
  "timeStamp": "20251111011147",
  "iMid": "IONPAYTEST",
  "tXid": "IONPAYTEST02202511110137007677",
  "payMethod": "02",
  "amt": "10000",
  "cancelType": "1",
  "cancelMsg": "Cancel Testing Transaction",
  "cancelUserId": "",
  "cancelUserIp": "127.0.0.1",
  "cancelServerIp": "127.0.0.1",
  "cancelUserInfo": "",
  "cancelRetryCnt": "",
  "worker": ""
};

let secondVersion = new SecondApiVersion(config);

response = secondVersion
  .requestAPI(parameterCancel, "/direct/v2/cancel");
```

```java
config = NICEPay.builder()
        .isProduction(false)
        .build();

String timestamp = "20251111011147";
String txId = "IONPAYTEST02202511110137007677";
String iMid = "IONPAYTEST";
String amount = "10000";

Cancel requestCancel = Cancel.builder()
        .timeStamp(timestamp)
        .tXid(txId)
        .iMid(iMid)
        .merchantToken(timestamp, iMid, txId, amount, YOUR_MERCHANT_KEY) 
        .payMethod("02")
        .cancelType("1")
        .amt(amount)
        .cancelMsg("Cancel Testing Transaction") 
        .cancelUserId("") 
        .cancelUserIp("127.0.0.1") 
        .cancelServerIp("127.0.0.1") 
        .cancelUserInfo("") 
        .cancelRetryCnt("") 
        .worker("")
        .build();

NICEPayResponseV2 response = V2CancelService.callV2CancelTransaction(requestCancel, config);
```

```python
bodyCancel = (
    builderCancel.BuildCancel()
    .setPayMethod("02")
    .setTxid("IONPAYTEST02202511110137007677")
    .setCancelUserId("")
    .setCancelType("1")
    .setCancelMsg("Cancel Testing Transaction")
    .setAmt("10000")
    .setCancelUserIp("127.0.0.1")
    .setCancelServerIp("127.0.0.1")
    .setCancelUserInfo("")
    .setCancelRetryCnt("")
    .setWorker("")
    .build()
)

environment = (builderEnvironment.BuildEnvironment()
               .isCloud(False)
               .isProduction(False)
               .build())

response = ServiceNicepay.serviceCancel(DataGenerator.getCancelBody(bodyCancel.jsonCancel()), environment)
```

C#

```csharp
TestingConstantService config = new TestingConstantService(); // Sample Constants 
string merchantKey = config.MerKey;
string clientId = "IONPAYTEST";
string timestamp = "20251111011147";
string amount = "10000";
string txid = "IONPAYTEST02202511110137007677";
bool isProduction = false;
bool isCloudServer = false;

var builder = new MerchantTokenBuilder()
  .SetTimeStamp(timestamp)
  .SetIMid(clientId)
  .SetTXid(txid)
  .SetAmount(amount)
  .SetMerchantKey(merchantKey);

// Act: Menghasilkan merchantToken
string merchantToken = builder.BuildCancelMerchantToken();

var Bodybuilder = new NicepayRequestBuilder()
.SetCancel(
iMid : clientId,
timeStamp : timestamp,
tXid : txid,
amt : amount,
merchantToken : merchantToken,
payMethod : "02",
cancelType : "1",
cancelMsg : "Cancel Testing Transaction",
cancelUserId : "",
cancelRetryCnt : "",
);

ApiEndpoints apiEndpoints = new ApiEndpoints();
Dictionary<string, object> payload = Bodybuilder.Build();
string jsonPayload = Newtonsoft.Json.JsonConvert.SerializeObject(payload);

var registrationService = new NicepayRegistrationService(apiEndpoints,isProduction, isCloudServer);
var result = await registrationService.SendPostAsync(apiEndpoints.CancelV2,payload);
```

Laravel

```php
$url = HttpUtil::getNicepayDomain($this->useProd, $this->useCloud) . $this->cancel_endpoint;

//request body parameter
$timestamp = "20251111011147";
$txid = "IONPAYTEST02202511110137007677";
$amt = $this->amt;
$merchant_token = $this->generateMerchantToken($timestamp, $this->imid, $txid, $this->amt, $this->merchant_key);

$body = [
    "timeStamp" => $timestamp,
    "tXid" => $txid,
    "iMid" => $this->imid,
    "payMethod" => $this->pay_method,
    "merchantToken" => $merchant_token,
    "amt" => $amt,
    "cancelMsg" => "Cancel Testing Transaction",
    "cancelType" => "1",
    "cancelServerIp" => "127.0.0.1",
    "cancelUserId" => "",
    "cancelUserIp" => "127.0.0.1",
    "cancelUserInfo" => "",
    "cancelRetryCnt" => "",
    "worker" => ""
];
try {
    $response = HttpUtil::postJsonRequest($url, $body);
} catch (Throwable $th) {
    return HttpUtil::generateErrorResponse($th);
}
```

PHP Native

```php
$timestampv2 = "20251111011147";
$amount = "10000";
$iMid = "IONPAYTEST";
$merchantKey = TestConst::$MERCHANT_KEY;

$configV2 = Nicepay::builder()
    ->setIsProduction(false)
    ->build();

$config = $configV2;
$timestamp = $timestampv2;
$txId = "IONPAYTEST02202511110137007677";

$requestBody = Cancel::builder()
    ->setTimeStamp($timestamp)
    ->setIMid($this->iMid)
    ->setTXid($txId)
    ->setMerchantToken($timestamp, $this->iMid, $txId, $this->amount, $this->merchantKey)
    ->setPayMethod("02")
    ->setCancelType("1")
    ->setAmt($this->amount)
    ->setCancelMsg("Cancel Testing Transaction")
    ->setCancelUserId("")
    ->setCancelUserIp("127.0.0.1")
    ->setCancelServerIp("127.0.0.1")
    ->setCancelUserInfo("")
    ->setCancelRetryCnt("")
    ->setWorker("")
    ->build();

try {
    $v2VaService = new V2VAService($config);
    $response = $v2VaService->cancel($requestBody);
}
```

```kotlin
private val v2VirtualAccountService: DirectV2Service<DirectV2VirtualAccount> = DirectV2VirtualAccountServiceImpl()
private val timeStamp: String = "20251111011147"
private val txId: String = "IONPAYTEST02202511110137007677"
private val iMid: String = "IONPAYTEST"
private val amount: String = "10000"

private var config: NICEPay? = NICEPay.Builder()
    .isProduction(false)
    .build()

val request: DirectV2Cancel = DirectV2Cancel.Builder()
    .timeStamp(timeStamp)
    .tXid(txId)
    .iMid(iMid)
    .merchantKey(TestingConstants.DEFAULT_MERCHANT_KEY) 
    .amt(amount)
    .payMethod("02")
    .cancelType("1")
    .cancelMsg("Cancel Testing Transaction")
    .cancelUserId("")
    .cancelUserIp("127.0.0.1")
    .cancelServerIp("127.0.0.1")
    .cancelUserInfo("")
    .cancelRetryCnt("")
    .worker("")
    .build()

val response: NICEPayResponseV2 = v2VirtualAccountService.cancel(request, config)!!
```

CodeIgniter

```php
$config = Nicepay::builder()
    ->setIsProduction(false)
    ->setIsCloudServer(false)
    ->build();

$timestamp = "20251111011147";
$txId = "IONPAYTEST02202511110137007677";
$amount = "10000";

$requestBody = Cancel::builder()
    ->setTimeStamp($timestamp)
    ->setIMid($this->iMid)
    ->setTXid($txId)
    ->setMerchantToken($timestamp, $this->iMid, $txId, $amount, $this->merchantKey)
    ->setPayMethod("02")
    ->setCancelType("1")
    ->setAmt($this->amount)
    ->setCancelMsg("Cancel Testing Transaction")
    ->setCancelUserId("")
    ->setCancelUserIp("127.0.0.1")
    ->setCancelServerIp("127.0.0.1")
    ->setCancelUserInfo("")
    ->setCancelRetryCnt("")
    ->setWorker("")
    ->build();

try {
    $v2VaService = new V2VAService($config);
    $response = $v2VaService->cancel($requestBody);
}
```
:::

### Response Parameter

:::CodeblockTabs
Sample Response

```json
{
    "tXid": "IONPAYTEST02202511110137007677",
    "referenceNo": "ordNo20251111011183",
    "resultCd": "0000",
    "resultMsg": "SUCCESS",
    "transDt": "20251111",
    "transTm": "013700",
    "description": "TESTING TRANSACTION",
    "amt": "10000"
}
```
:::

