# POST /invoice/failedpayment/{{invoice_id}} — Record Failed Payment Invoice

> Product: **Pabbly Subscription Billing** (v1)
> Base URL: `https://payments.pabbly.com/api/v1`
> Auth: Basic via `Authorization` header
> Canonical: `/subscription-billing/invoice/record-failed-payment-invoice`

POST request API . can be used the record the transaction of Payment Invoice. You need to add invoice Id in the link. In response you will get the ‘Failed’ status and the status of invoice will be updated.

**Path parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| invoice_id | string | Yes |  |

**Body parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| error_message | string | Yes | Error message received by the payment processor on your server. |
| transaction | string | No | Add transaction details if any. |

**Example request body:**

```json
{
	"error_message":"Unable to process the purchase transaction",
	"transaction":"Transaction data if any"
}
```

**Response (200)** — Record Failed Payment Invoice:

```json
{
    "status": "failed",
    "message": "Your payment is failed.",
    "data": {
        "customer": {
            "company_name": "Trip Band",
            "phone": "654665487",
            "website": "www.triptoes.com",
            "billing_address": {
                "street1": "103 Brice Town Road",
                "city": "Michigan",
                "state": "California",
                "state_code": "CA",
                "zip_code": "462003",
                "country": "US"
            },
            "shipping_address": {},
            "createdAt": "2020-03-04T06:06:04.541Z",
            "updatedAt": "2020-03-04T06:06:04.541Z",
            "id": "5e5f454c3b2518365c7923f0",
            "first_name": "Stella",
            "last_name": "Rocks",
            "email_id": "rockersstella@gmail.com"
        },
        "product": {
            "createdAt": "2020-02-05T10:12:36.805Z",
            "updatedAt": "2020-02-05T10:12:36.805Z",
            "id": "5e3a95143c92e44b424b6d47",
            "product_name": "Product 1",
            "description": null,
            "notification_email": null,
            "redirect_url": "#"
        },
        "subscription": {
            "plan": {
                "plan_active": "true",
                "bump_offer": {},
                "createdAt": "2020-02-06T11:30:00.807Z",
                "updatedAt": "2020-02-06T11:30:00.807Z",
                "id": "5e3bf8b8db85462760295d2f",
                "product_id": "5e3a95143c92e44b424b6d47",
                "user_id": "5b961bc55dfff7797d9cd897",
                "plan_name": "New recurring plan",
                "plan_code": "new-recurring-plan",
                "price": 200,
                "billing_period": "m",
                "billing_period_num": "1",
                "billing_cycle": "lifetime",
                "billing_cycle_num": null,
                "trial_period": 0,
                "setup_fee": 0,
                "plan_description": "<p>zdf</p>"
            },
            "setup_fee": 0,
            "payment_terms": "",
            "currency_symbol": "$",
            "payment_method": "test",
            "taxable": true,
            "gateway_type": "test",
            "gateway_id": "5e3a950824b63d4b28410c8d",
            "custom_fields": [],
            "cron_process": "done",
            "createdAt": "2020-03-04T06:06:04.553Z",
            "updatedAt": "2020-03-04T06:06:04.553Z",
            "id": "5e5f454c3b2518365c7923f1",
            "customer_id": "5e5f454c3b2518365c7923f0",
            "product_id": "5e3a95143c92e44b424b6d47",
            "plan_id": "5e3bf8b8db85462760295d2f",
            "amount": 200,
            "email_id": "rockersstella@gmail.com",
            "status": "dunning",
            "quantity": 1,
            "starts_at": "2020-03-04T06:06:04.044Z",
            "activation_date": "",
            "expiry_date": "2120-03-04T06:06:04.044Z",
            "trial_days": 0,
            "trial_expiry_date": "",
            "next_billing_date": "",
            "last_billing_date": "",
            "canceled_date": null
        },
        "invoice": {
            "invoice_id": "INV-56",
            "quantity": 1,
            "product_id": "5e3a95143c92e44b424b6d47",
            "setup_fee": 0,
            "currency_symbol": "$",
            "credit_note": {
                "total_tax": "0.00",
                "status": "success",
                "new_plan_total": 200,
                "credit_applied": []
            },
            "tax_apply": "not_exist",
            "cron_process": "done",
            "retry": true,
            "retry_count": 2,
            "createdAt": "2020-03-04T06:06:04.571Z",
            "updatedAt": "2020-03-04T06:06:04.575Z",
            "id": "5e5f454c3b2518365c7923f2",
            "customer_id": "5e5f454c3b2518365c7923f0",
            "subscription_id": "5e5f454c3b2518365c7923f1",
            "status": "overdue",
            "payment_term": "",
            "amount": 200,
            "due_amount": 200,
            "due_date": "2020-03-04T06:06:04.044Z",
            "plan_id": [
                "5e3bf8b8db85462760295d2f"
            ]
        }
    }
}
```

**Code examples:**

_cURL_

```curl
curl -X POST https://payments.pabbly.com/api/v1/invoice/failedpayment/{{invoice_id}} \
  -u {{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}} \
  -H "Content-Type: application/json" \
  -d '{
    "error_message": "Unable to process the purchase transaction",
    "transaction": "Transaction data if any"
  }'
```

_Ruby_

```ruby
require 'net/http'
require 'json'

uri = URI('https://payments.pabbly.com/api/v1/invoice/failedpayment/{{invoice_id}}')
request = Net::HTTP::Post.new(uri)
request.basic_auth '{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'
request['Content-Type'] = 'application/json'
request.body = "{\"error_message\":\"Unable to process the purchase transaction\",\"transaction\":\"Transaction data if any\"}"

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end

data = JSON.parse(response.body)
```

_Python_

```python
import requests
from requests.auth import HTTPBasicAuth

response = requests.post(
    'https://payments.pabbly.com/api/v1/invoice/failedpayment/{{invoice_id}}',
    auth=HTTPBasicAuth('{{YOUR_API_KEY}}', '{{YOUR_SECRET_KEY}}'),
    json={
    'error_message': 'Unable to process the purchase transaction',
    'transaction': 'Transaction data if any'
},
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://payments.pabbly.com/api/v1/invoice/failedpayment/{{invoice_id}}');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_USERPWD, '{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"error_message":"Unable to process the purchase transaction","transaction":"Transaction data if any"}');

$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
```

_Java_

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Base64;

String credentials = Base64.getEncoder().encodeToString("{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}".getBytes());

HttpClient client = HttpClient.newHttpClient();
HttpRequest.Builder builder = HttpRequest.newBuilder()
    .uri(URI.create("https://payments.pabbly.com/api/v1/invoice/failedpayment/{{invoice_id}}"))
    .header("Authorization", "Basic " + credentials)
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\"error_message\":\"Unable to process the purchase transaction\",\"transaction\":\"Transaction data if any\"}"));

HttpRequest request = builder.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

_Node.js_

```node
const credentials = Buffer.from('{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}').toString('base64');

const response = await fetch('https://payments.pabbly.com/api/v1/invoice/failedpayment/{{invoice_id}}', {
  method: 'POST',
  headers: {
    'Authorization': `Basic ${credentials}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "error_message": "Unable to process the purchase transaction",
    "transaction": "Transaction data if any"
  }),
});

const data = await response.json();
```

_Go_

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    payload := strings.NewReader("{\"error_message\":\"Unable to process the purchase transaction\",\"transaction\":\"Transaction data if any\"}")
    req, _ := http.NewRequest("POST", "https://payments.pabbly.com/api/v1/invoice/failedpayment/{{invoice_id}}", payload)
    req.Header.Set("Content-Type", "application/json")
    req.SetBasicAuth("{{YOUR_API_KEY}}", "{{YOUR_SECRET_KEY}}")

    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)
    fmt.Println(string(body))
}
```

_.NET_

```dotnet
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;

var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes("{{YOUR_API_KEY}}:{{YOUR_SECRET_KEY}}"));

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://payments.pabbly.com/api/v1/invoice/failedpayment/{{invoice_id}}");
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {credentials}");
request.Content = new StringContent("{\"error_message\":\"Unable to process the purchase transaction\",\"transaction\":\"Transaction data if any\"}");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

var response = await client.SendAsync(request);
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
```

---

**Other endpoints in Invoice:**

- [GET /invoice/{{invoice_id}} — Get Single Invoice](/subscription-billing/invoice/get-single-invoice)
- [GET /invoices/transactions/{{invoice_id}} — List All Transactions By Invoice Id](/subscription-billing/invoice/list-all-transactions-by-invoice-id)
- [GET /invoices/{{customer_id}} — List All Invoices By Customer Id](/subscription-billing/invoice/list-all-invoices-by-customer-id)
- [GET /invoices — List All Invoices](/subscription-billing/invoice/list-all-invoices)
- [POST /invoice/recordpayment/{{invoice_id}} — Record Payment Invoice](/subscription-billing/invoice/record-payment-invoice)
- [DELETE /invoices/{{invoice_id}} — Delete Invoice](/subscription-billing/invoice/delete-invoice)
- [POST /invoices/create-metered/{{subscription_id}} — Create Metered Invoice](/subscription-billing/invoice/create-metered-invoice)

