Skip to main content

Documentation

Cancel Payment

Cancel a payment where the status of the payment is ACT.

Relevant to payment methods where is_cancelable = true in the response to List Payment Methods by Country.

This method triggers the Payment Canceled Webhook. This webhook contains the same information as the response.

Note

If the status is CLO, use Create Refund.

Note

    • payment

    • ID of the payment. String starting with payment_.

Code Samples
    • .NET

      • using System;
        
        namespace RapydApiRequestSample
        {
            class Program
            {
                static void Main(string[] args)
                {
                    try
                    {
                        string payment = "payment_84e75b8d03f7875463cb58d5a55db843";
        
                        string result = RapydApiRequestSample.Utilities.MakeRequest("DELETE", $"/v1/payments/{payment}");
        
                        Console.WriteLine(result);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error completing request: " + e.Message);
                    }
                }
            }
        }
        
    • JavaScript

      • const makeRequest = require('<path-to-your-utility-file>/utilities').makeRequest;
        
        async function main() {
          try {
            const result = await makeRequest(
              'DELETE',
              '/v1/payments/payment_84e75b8d03f7875463cb58d5a55db843'
            );
        
            console.log(result);
          } catch (error) {
            console.error('Error completing request', error);
          }
        }
        
    • PHP

      • <?php
        $path = $_SERVER['DOCUMENT_ROOT'];
        $path .= "/<path-to-your-utility-file>/utilities.php";
        include($path);
        
        try {
            $object = make_request('delete', '/v1/payments/payment_84e75b8d03f7875463cb58d5a55db843');
            var_dump($object);
        } catch(Exception $e) {
            echo "Error: $e";
        }
        ?>
    • Python

      • from pprint import pprint
        
        from utilities import make_request
        
        payment = "payment_84e75b8d03f7875463cb58d5a55db843"
        response = make_request(method='delete',
                                path=f'/v1/payments/{payment}')
        
        pprint(response)
  • /v1/payments/:payment

  • Cancel Payment

  • curl -X delete
    https://sandboxapi.rapyd.net/v1/payments/payment_00778be57b9087180596678817973e61
    -H 'access_key: your-access-key-here'
    -H 'Content-Type: application/json'
    -H 'salt: your-random-string-here'
    -H 'signature: your-calculated-signature-here'
    -H 'timestamp: your-unix-timestamp-here'
    
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "11fc3c4a-d938-48aa-b8fd-c00b8f180b7f"
        },
        "data": {
            "id": "payment_00778be57b9087180596678817973e61",
            "amount": 0,
            "original_amount": 101,
            "is_partial": false,
            "currency_code": "PHP",
            "country_code": "PH",
            "status": "CAN",
            "description": "Cancelable payment",
            "merchant_reference_id": "",
            "customer_token": "cus_907dc0e443fde54d2bbbdde8915a3417",
            "payment_method": "other_cb92f8c4370e36cb1b9f75a30b5ebe61",
            "payment_method_data": {},
            "expiration": 1623073515,
            "captured": true,
            "refunded": false,
            "refunded_amount": 0,
            "receipt_email": "",
            "redirect_url": "",
            "complete_payment_url": "",
            "error_payment_url": "",
            "receipt_number": "",
            "flow_type": "",
            "address": null,
            "statement_descriptor": "Rapyd",
            "transaction_id": "",
            "created_at": 1621863915,
            "metadata": {
                "merchant_defined": true
            },
            "failure_code": "",
            "failure_message": "",
            "paid": false,
            "paid_at": 0,
            "dispute": null,
            "refunds": null,
            "order": null,
            "outcome": null,
            "visual_codes": {},
            "textual_codes": {
                "code": "8765433177018479"
            },
            "instructions": [],
            "ewallet_id": "ewallet_c67c44ec60d5c2e62480aa7c76b3f8b4",
            "ewallets": [
                {
                    "ewallet_id": "ewallet_c67c44ec60d5c2e62480aa7c76b3f8b4",
                    "amount": 101,
                    "percent": 100,
                    "refunded_amount": 0
                }
            ],
            "payment_method_options": {},
            "payment_method_type": "ph_bankatmotc_cash",
            "payment_method_type_category": "cash",
            "fx_rate": 1,
            "merchant_requested_currency": null,
            "merchant_requested_amount": null,
            "fixed_side": "",
            "payment_fees": null,
            "invoice": "",
            "escrow": null,
            "group_payment": "",
            "cancel_reason": null,
            "initiation_type": "customer_present",
            "mid": "",
            "next_action": "not_applicable",		
            "merchant_advice_code": null,
            "merchant_advice_message": null,
            "merchant_ewallet": null,
            "transaction_link_id": null
        }
    }
  • Bad Request - Closed Payment

  • curl -X delete
    https://sandboxapi.rapyd.net/v1/payments/payment_eac0d2f27b85af17a018ec8b7ac2f504 \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here'
  • {
        "status": {
            "error_code": "ERROR_PAYMENT_CAN_NOT_BE_CANCELED",
            "status": "ERROR",
            "message": "The request tried to cancel a payment, but the payment was already closed. The request was rejected. Corrective action: None. Determine why an attempt was made to cancel a closed payment.",
            "response_code": "ERROR_PAYMENT_CAN_NOT_BE_CANCELED",
            "operation_id": "06d87f28-957c-462b-891e-c3a45ca464d5"
        }
    }
  • Bad Request - Payment Not Found

  • curl -X delete
    https://sandboxapi.rapyd.net/v1/payments/payment_84e75b8d03f7875463cb58d5a55db843 \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here'
  • {
        "status": {
            "error_code": "ERROR_GET_PAYMENT",
            "status": "ERROR",
            "message": "The request tried to retrieve a payment, but the payment was not found. The request was rejected. Corrective action: Use a valid payment ID.",
            "response_code": "ERROR_GET_PAYMENT",
            "operation_id": "74bf0a50-4925-403f-8164-b545dcedbd30"
        }
    }
  • Unauthorized

  • curl -X delete
    https://sandboxapi.rapyd.net/v1/payments/payment_84e75b8d03f7875463cb58d5a55db843 \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here'
  • {
        "status": {
            "error_code": "UNAUTHENTICATED_API_CALL",
            "status": "ERROR",
            "message": "The request was rejected due to an authentication issue. Corrective action: Check the status of your account in the 'Account Details' page of the Client Portal.",
            "response_code": "UNAUTHENTICATED_API_CALL",
            "operation_id": "cb3a1627-a931-4285-a88d-c67259bf9bb1"
        }
    }