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.
The code samples include successful requests (200) and bad requests (400).
For error messages that appear due to bad requests (400), see:
For information about unauthorized request (401) and other authentication errors, see Troubleshooting Authentication and Authorization Errors.
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' \ --data-raw '{ "customer": "cus_4e25112ac20e144ad073a614dc46934b", "billing": "pay_automatically", "currency": "USD" }'{ "status": { "error_code": "", "status": "SUCCESS", "message": "", "response_code": "", "operation_id": "733f53d5-6081-4a1a-8f00-57379af6a48b" }, "data": { "id": "invoice_c48bd622ee2e6ad6dd3ae4dc035dd451", "attempt_count": 0, "billing": "pay_automatically", "billing_reason": "manual", "created_at": 1761645737, "currency": "USD", "customer": "cus_4e25112ac20e144ad073a614dc46934b", "description": "", "discount": null, "due_date": 1764237737, "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": "draft", "payout_fields": null, "type": "payment" } }
Bad Request - Customer Not Found
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' \ --data-raw '{ "billing": "pay_automatically", "currency": "USD" }'{ "status": { "error_code": "INVALID_CUSTOMER", "status": "ERROR", "message": "The request attempted an operation that requires a valid customer ID, but the customer was not found. The request was rejected. Corrective action: Use the correct customer, or create a new customer.", "response_code": "INVALID_CUSTOMER", "operation_id": "ec6e1765-0d74-41d4-af2e-63e60f80b74d" } }
Bad Request - Currency Not Found
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' \ --data-raw '{ "customer": "cus_4e25112ac20e144ad073a614dc46934b", "billing": "pay_automatically" }'{ "status": { "error_code": "INVALID_CUSTOMER", "status": "ERROR", "message": "The request attempted an operation that requires a valid customer ID, but the customer was not found. The request was rejected. Corrective action: Use the correct customer, or create a new customer.", "response_code": "INVALID_CUSTOMER", "operation_id": "ec6e1765-0d74-41d4-af2e-63e60f80b74d" } }