Skip to main content

Documentation

Create Invoice

Create an invoice to add a one-time charge to a subscription.

After you create the invoice with this method, create invoice items and assign them to the invoice with Create Invoice Item

This method triggers the Invoice Created Webhook. This webhook contains the same information as the response.

The following asynchronous webhook provides information about later changes to the Invoice object:

Note

Clients who have PCI clearance can use card payment methods for an invoice.

Code Samples
    • .NET

      • using System;
        using System.Text.Json;
        
        namespace RapydApiRequestSample
        {
            class Program
            {
                static void Main(string[] args)
                {
                    try
                    {
                        var requestObj = new
                        {
                            customer = "cus_efd877ff7df0b0259f021792d0780185",
                            billing = "pay_automatically",
                            days_until_due = "",
                            description = "",
                            due_date = 0,
                            metadata = new
                            {
                                merchant_defined = true
        
                            },
                            statement_descriptor = "",
                            subscription = "",
                            tax_percent = "",
                            currency = "USD"
                        };
        
                        string request = JsonSerializer.Serialize(requestObj);
        
                        string result = RapydApiRequestSample.Utilities.MakeRequest("POST", "/v1/invoices", request);
        
                        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 body = {
              customer: 'cus_efd877ff7df0b0259f021792d0780185',
              billing: 'pay_automatically',
              days_until_due: null,
              description: '',
              due_date: 0,
              metadata: {
                merchant_defined: true
              },
              statement_descriptor: '',
              subscription: '',
              tax_percent: '',
              currency: 'USD'
            };
            const result = await makeRequest('POST', '/v1/invoices', body);
        
            console.log(result);
          } catch (error) {
            console.error('Error completing request', error);
          }
        }
    • PHP

      • <?php
        $path .= "/<path-to-your-utility-file>/utilities.php";
        include($path);
        
        $body = [
            "customer" => "cus_efd877ff7df0b0259f021792d0780185",
            "billing" => "pay_automatically",
            "days_until_due" => null,
            "description" => "",
            "due_date" => 0,
            "statement_descriptor" => "",
            "subscription" => "",
            "tax_percent" => "",
            "currency" => "USD"
        ];
        
        try {
            $object = make_request('post', '/v1/invoices', $body);
            var_dump($object);
        } catch(Exception $e) {
            echo "Error => $e";
        }
        ?>
    • Python

      • from pprint import pprint
        
        from utilities import make_request
        
        invoice = {
            "customer": "cus_efd877ff7df0b0259f021792d0780185",
            "billing": "pay_automatically",
            "description": "",
            "due_date": 0,
            "metadata": {
                "merchant_defined": True
            },
            "statement_descriptor": "",
            "subscription": "",
            "tax_percent": "",
            "currency": "USD"
        }
        result = make_request(method='post', path='/v1/invoices', body=invoice)
        pprint(result)
        
  • /v1/invoices

  • Create Invoice

  • curl -X post
    https://sandboxapi.rapyd.net/v1/invoices
    -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'
    -d '{
        "customer": "cus_893a041b7dd251ec894556564298dc13",
        "payment_method": "card_4bd5b06ff2ba990676e3b9e8695d790e",
        "currency": "USD"
    }
    '
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "f829e227-7286-40ad-9114-322841788445"
        },
        "data": {
            "id": "invoice_3c767d675d41e03968d74a63f6353d8e",
            "attempt_count": 0,
            "billing": "pay_automatically",
            "billing_reason": "manual",
            "created_at": 1702307231,
            "currency": "USD",
            "customer": "cus_893a041b7dd251ec894556564298dc13",
            "description": "",
            "discount": null,
            "due_date": 1704899231,
            "days_until_due": 30,
            "metadata": {},
            "number": 0,
            "payment_method": "card_4bd5b06ff2ba990676e3b9e8695d790e",
            "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": "draft",
            "payout_fields": null,
            "type": "payment",
            "next_payment_attempt": 1702310831,
            "automatic_attempt_count": 0
        }
    }