Pay Invoice
Make a payment against an invoice.
This method triggers the following webhooks:
Invoice Payment Created Webhook - This webhook contains the same information as the response.
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
Before you pay an invoice with a token for a payment method, verify that the value of
is_tokenizableis true.If the payment method category is card, certain operations require 3DS authentication. To simulate this authentication in the sandbox, use the URL from the
redirect_urlfield that appears in the response and in Invoice Payment Created Webhook and Payment Succeeded Webhook. See Simulating 3DS Authentication.A card payment that requires 3DS authentication must be authenticated within 15 minutes.
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.
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" } }