Cancel Payment

POST /v1/payments/payment/{payment_id}/cancel

To cancel a payment transaction before paid by payer

Parameter

payment_id String Mandatory

Unique Identifier of payment transaction

Request Body

reason String Mandatory

Reason for particular operation

Response

code Number

Please refer to Response Code

description String

Description of response

Sample Code


curl -X POST  https://sandbox.api.liquidpay.com/openapi/v1/payments/payment/{{payment_id}}/cancel \
  -H 'content-type: application/json' \
  -H 'Liquid-Api-Key: {{api_key}}' \
  -d '{
    "reason": "{{reason}}"
}'

$request = new HttpRequest();
$request->setUrl('https://sandbox.api.liquidpay.com/openapi/v1/payments/payment/{{payment_id}}/cancel');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'content-type' => 'application/json',
  'Liquid-Api-Key' => '{{api_key}}'
));

$request->setBody('{
  "reason": "{{reason}}",
}');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

var client = new RestClient("https://sandbox.api.liquidpay.com/openapi/v1/payments/payment/{{payment_id}}/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("Liquid-Api-Key", "{{api_key}}");
request.AddParameter("application/json", "{\n\t\"reason\": \"{{reason}}\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://sandbox.api.liquidpay.com/openapi/v1/payments/payment/{{payment_id}}/cancel",
  "method": "POST",
  "headers": {
    "Liquid-Api-Key": "{{api_key}}",
    "content-type": "application/json"
  },
  "processData": false,
  "data": "{\"reason\":\"{{reason}}\" }"
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

HttpResponse response = Unirest.post("https://sandbox.api.liquidpay.com/openapi/v1/payments/payment/{{payment_id}}/cancel")
  .header("Liquid-Api-Key", "{{api_key}}")
  .header("content-type", "application/json")
  .body("{\"\"reason\":\"{{reason}}\" }");
  .asString();

#import 

NSDictionary *headers = @{ @"Liquid-Api-Key": @"{{api_key}}",
                           @"content-type": @"application/json";
NSDictionary *parameters = @{ @"reason": @"{{reason}}"};

NSData *postData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://sandbox.api.liquidpay.com/openapi/v1/payments/payment/{{payment_id}}/cancel"]
                                                       cachePolicy:NSURLRequestUseProtocolCachePolicy
                                                   timeoutInterval:10.0];
[request setHTTPMethod:@"POST"];
[request setAllHTTPHeaderFields:headers];
[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
                                            completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                                                if (error) {
                                                    NSLog(@"%@", error);
                                                } else {
                                                    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
                                                    NSLog(@"%@", httpResponse);
                                                }
                                            }];
[dataTask resume];

import Foundation

let headers = [
  "Liquid-Api-Key": "{{api_key}}",
  "content-type": "application/json"
]
let parameters = [
  "reason": "{{reason}}"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://sandbox.api.liquidpay.com/openapi/v1/payments/payment/{{payment_id}}/cancel")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()