Skip to main content

Documentation

Pay Invoice

Make a payment against an invoice.

This method triggers the following webhooks:

The following asynchronous webhooks provide information about later changes to the Invoice object:

Depending on the request values, some of these webhooks are triggered synchronously.

Note

    • invoice

    • ID of the invoice you want to pay. String starting with invoice_.

    • payment_method

    • ID of the payment method for paying the invoice. If not included in the body, then the customer's default payment method is used.

Code Samples
    • .NET

      • using System;
        
        namespace RapydApiRequestSample
        {
            class Program
            {
                static void Main(string[] args)
                {
                    try
                    {
                        string invoice = "invoice_f387777eaa23ff864e2a8fced2455ef6";
        
                        string result = RapydApiRequestSample.Utilities.MakeRequest("POST", $"/v1/invoices/{invoice}/pay");
        
                        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(
              'POST',
              '/v1/invoices/invoice_f387777eaa23ff864e2a8fced2455ef6/pay'
            );
        
            console.log(result);
          } catch (error) {
            console.error('Error completing request', error);
          }
        }
    • PHP

      • <?php
        $path .= "/<path-to-your-utility-file>/utilities.php";
        include($path);
        
        try {
            $object = make_request('post', "/v1/invoices/invoice_f387777eaa23ff864e2a8fced2455ef6/pay");
            var_dump($object);
        } catch(Exception $e) {
            echo "Error => $e";
        }
        ?>
    • Python

      • from pprint import pprint
        
        from utilities import make_request
        
        result = make_request(method='post', path='/v1/invoices/invoice_f387777eaa23ff864e2a8fced2455ef6/pay')
        pprint(result)
  • /v1/invoices/:invoice/pay

  • Pay Invoice

  • curl -X post  'https://sandboxapi.rapyd.net/v1/invoices/invoice_3c69b5228f548953a4da8cb5f80d79b8/pay' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw ''
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "4a9ddcbf-0ed4-4441-8af3-eeaaeb7bfdbd"
        },
        "data": {
            "id": "invoice_3c69b5228f548953a4da8cb5f80d79b8",
            "attempt_count": 0,
            "billing": "pay_automatically",
            "billing_reason": "manual",
            "created_at": 1764745257,
            "currency": "USD",
            "customer": "cus_4e25112ac20e144ad073a614dc46934b",
            "description": "",
            "discount": null,
            "due_date": 1767337257,
            "days_until_due": 30,
            "metadata": {},
            "payment_method": "card_b9548d9b53a565b2315fecdc6c87f158",
            "payment": null,
            "payout": null,
            "payment_fields": null,
            "period_end": 0,
            "period_start": 0,
            "lines": [],
            "statement_descriptor": "",
            "subscription": "",
            "discount_amount": 0,
            "subtotal": 0,
            "tax": 0,
            "tax_percent": 0,
            "total": 0,
            "status": "paid",
            "payout_fields": null,
            "type": "payment"
        }
    }
  • Bad Request - Status Not Draft

  • curl -X post  'https://sandboxapi.rapyd.net/v1/invoices/invoice_90be94b2416dfb41b7458ad551e62e0/pay' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw ''
  • {
        "status": {
            "error_code": "ERROR_UPDATE_NOT_DRAFT_INVOICE",
            "status": "ERROR",
            "message": "The request tried to a update an invoice but the invoice is not draft. Can only update draft invoice. The request was rejected.",
            "response_code": "ERROR_UPDATE_NOT_DRAFT_INVOICE",
            "operation_id": "0cf27984-c881-4b23-a97d-55eaec3f46c3"
        }
    }
  • Bad Request - Invoice Not Found

  • curl -X post  'https://sandboxapi.rapyd.net/v1/invoices/invoice_90be94b2416dfb41b7458ad551e62e0/pay' \
    -H 'access_key: your-access-key-here' \
    -H 'Content-Type: application/json' \
    -H 'idempotency: your-idempotency-parameter-here' \
    -H 'salt: your-random-string-here' \
    -H 'signature: your-calculated-signature-here' \
    -H 'timestamp: your-unix-timestamp-here' \
    --data-raw ''
  • {
        "status": {
            "error_code": "ERROR_GET_INVOICE",
            "status": "ERROR",
            "message": "The request tried to retrieve an invoice, but the invoice was not found. The request was rejected. Corrective action: Use a valid invoice ID.",
            "response_code": "ERROR_GET_INVOICE",
            "operation_id": "a201da53-3a4f-4ff2-8545-101d18c1e970"
        }
    }