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

  • Before you pay an invoice with a token for a payment method, verify that the value of is_tokenizable is 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_url field 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.

    • 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_d021dc5aadaae5c810ed076a64065699/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'
    
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "d9b5188d-cc68-4006-ba48-46acecac2ba9"
        },
        "data": {
            "id": "invoice_d021dc5aadaae5c810ed076a64065699",
            "attempt_count": 1,
            "billing": "pay_automatically",
            "billing_reason": "subscription_create",
            "created_at": 1702305351,
            "currency": "USD",
            "customer": "cus_893a041b7dd251ec894556564298dc13",
            "description": "",
            "discount": null,
            "due_date": 1704897351,
            "days_until_due": 30,
            "metadata": {},
            "number": 0,
            "payment_method": "card_082112350b6b5347d6f626b8299587aa",
            "payment": {
                "id": "payment_2c44b8c113f37ac508ead59a8871b54e",
                "amount": 9.99,
                "original_amount": 9.99,
                "is_partial": false,
                "currency_code": "USD",
                "country_code": "AT",
                "status": "CLO",
                "description": "",
                "merchant_reference_id": "",
                "customer_token": "cus_893a041b7dd251ec894556564298dc13",
                "payment_method": "card_082112350b6b5347d6f626b8299587aa",
                "payment_method_data": {
                    "id": "card_082112350b6b5347d6f626b8299587aa",
                    "type": "at_visa_card",
                    "category": "card",
                    "metadata": {},
                    "image": "",
                    "webhook_url": "",
                    "supporting_documentation": "",
                    "next_action": "not_applicable",
                    "name": "John Doe",
                    "last4": "0093",
                    "acs_check": "unchecked",
                    "cvv_check": "pass",
                    "bin_details": {
                        "type": "CREDIT",
                        "brand": "VISA",
                        "level": "SIGNATURE",
                        "issuer": "MAYBANK SINGAPORE LIMITED",
                        "country": "SG",
                        "bin_number": "401636"
                    },
                    "expiration_year": "26",
                    "expiration_month": "01",
                    "fingerprint_token": "ocfp_3441802c25a8fb3c3249c8249da1d964"
                },
                "auth_code": "434456",
                "expiration": 1702910176,
                "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": "Subscription",
                "transaction_id": "",
                "created_at": 1702305375,
                "metadata": {},
                "failure_code": "",
                "failure_message": "",
                "paid": true,
                "paid_at": 1702305377,
                "dispute": null,
                "refunds": null,
                "order": null,
                "outcome": null,
                "visual_codes": {},
                "textual_codes": {},
                "instructions": [],
                "ewallet_id": "ewallet_8d09667ac2a0d4ba57d2765c497491fd",
                "ewallets": [
                    {
                        "ewallet_id": "ewallet_8d09667ac2a0d4ba57d2765c497491fd",
                        "amount": 9.99,
                        "percent": 100,
                        "refunded_amount": 0
                    }
                ],
                "payment_method_options": {},
                "payment_method_type": "at_visa_card",
                "payment_method_type_category": "card",
                "fx_rate": 1,
                "merchant_requested_currency": null,
                "merchant_requested_amount": null,
                "fixed_side": "",
                "payment_fees": null,
                "invoice": "invoice_d021dc5aadaae5c810ed076a64065699",
                "escrow": null,
                "group_payment": "",
                "cancel_reason": null,
                "initiation_type": "customer_present",
                "mid": "mid_f79561a67d79c6e0162bf22f3ccd1292",
                "next_action": "not_applicable",
                "error_code": "",
                "remitter_information": {}
            },
            "payout": null,
            "payment_fields": null,
            "period_end": 1704983751,
            "period_start": 1702305351,
            "lines": [],
            "statement_descriptor": "",
            "subscription": "sub_4febac6e4554b387ae7e0ee2d933abed",
            "discount_amount": 0,
            "subtotal": 9.99,
            "tax": 0,
            "tax_percent": 0,
            "total": 9.99,
            "status": "open",
            "payout_fields": null,
            "type": "payment",
            "next_payment_attempt": 1702308951,
            "automatic_attempt_count": 0
        }
    }