# Record Order Payment

POST https://services.leadconnectorhq.com/payments/orders/{orderId}/record-payment

The "Record Order Payment" API allows to record a payment for an order. Use this endpoint to record payment for an order and update the order status to "Paid".

## Authentication

Send `Authorization: Bearer <token>` using:

- **Sub-Account token: OAuth access token or Private Integration Token.** Scopes: `payments/orders.collectPayment`

## Parameters

### Header Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `Version` | string | Yes | API Version |

### Path Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `orderId` | string | Yes | Order ID |

## OpenAPI Specification

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "LeadConnector API",
    "version": "v3"
  },
  "servers": [
    {
      "url": "https://services.leadconnectorhq.com"
    }
  ],
  "paths": {
    "/payments/orders/{orderId}/record-payment": {
      "post": {
        "summary": "Record Order Payment",
        "operationId": "recordOrderPayment",
        "description": "The \"Record Order Payment\" API allows to record a payment for an order. Use this endpoint to record payment for an order and update the order status to \"Paid\".",
        "parameters": [
          {
            "name": "Version",
            "in": "header",
            "description": "API Version",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "v3"
              ]
            }
          },
          {
            "name": "orderId",
            "required": true,
            "in": "path",
            "description": "Order ID",
            "schema": {
              "example": "5e2d4c8e0e8b4e001c1c4f5d",
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PostRecordOrderPaymentBody"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PostRecordOrderPaymentResponse"
                }
              }
            }
          },
          "400": {
            "description": "Order not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BadRequestDTO"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnauthorizedDTO"
                }
              }
            }
          },
          "422": {
            "description": "Unprocessable Entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnprocessableDTO"
                }
              }
            }
          }
        },
        "security": [
          {
            "Location-Access": [
              "payments/orders.collectPayment"
            ]
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account (OR) Private Integration Token of Sub-Account.",
        "type": "http"
      },
      "Location-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Sub-Account.",
        "type": "http"
      },
      "Agency-Access": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency (OR) Private Integration Token of Agency.",
        "type": "http"
      },
      "Agency-Access-Only": {
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "name": "Authorization",
        "in": "header",
        "description": "Use the Access Token generated with user type as Agency.",
        "type": "http"
      }
    },
    "schemas": {
      "PostRecordOrderPaymentBody": {
        "type": "object",
        "properties": {
          "altId": {
            "type": "string",
            "description": "location Id / company Id based on altType",
            "example": "6578278e879ad2646715ba9c"
          },
          "altType": {
            "type": "string",
            "description": "Alt Type",
            "enum": [
              "location"
            ],
            "example": "location"
          },
          "mode": {
            "type": "string",
            "description": "manual payment method",
            "enum": [
              "cash",
              "card",
              "cheque",
              "bank_transfer",
              "other"
            ],
            "example": "card"
          },
          "card": {
            "description": "Details of Card if used for payment",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "visa",
                      "mastercard",
                      "other"
                    ],
                    "example": "mastercard"
                  },
                  "last4": {
                    "type": "string",
                    "description": "Last 4 digit of the card",
                    "example": "1234"
                  }
                },
                "required": [
                  "type",
                  "last4"
                ],
                "title": "CardDto"
              }
            ]
          },
          "cheque": {
            "description": "Details of the Cheque if used for payment",
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "number": {
                    "type": "string",
                    "description": "check number",
                    "example": "129-129-129-912"
                  }
                },
                "required": [
                  "number"
                ],
                "title": "ChequeDto"
              }
            ]
          },
          "notes": {
            "type": "string",
            "description": "Any note to be recorded with the transaction",
            "example": "This was a direct payment"
          },
          "amount": {
            "type": "number",
            "description": "Amount to be paid against the invoice.",
            "example": 100
          },
          "meta": {
            "type": "object",
            "description": "Meta data to be recorded with the transaction"
          },
          "isPartialPayment": {
            "type": "boolean",
            "description": "Indicates if the order is intended to be a partial payment."
          }
        },
        "required": [
          "altId",
          "altType",
          "mode"
        ],
        "title": "PostRecordOrderPaymentBody"
      },
      "PostRecordOrderPaymentResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean",
            "description": "Success status of the request",
            "example": true
          }
        },
        "required": [
          "success"
        ],
        "title": "PostRecordOrderPaymentResponse"
      },
      "BadRequestDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 400
          },
          "message": {
            "type": "string",
            "example": "Bad Request"
          }
        },
        "title": "BadRequestDTO"
      },
      "UnauthorizedDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 401
          },
          "message": {
            "type": "string",
            "example": "Invalid token: access token is invalid"
          },
          "error": {
            "type": "string",
            "example": "Unauthorized"
          }
        },
        "title": "UnauthorizedDTO"
      },
      "UnprocessableDTO": {
        "type": "object",
        "properties": {
          "statusCode": {
            "type": "number",
            "example": 422
          },
          "message": {
            "example": [
              "Unprocessable Entity"
            ],
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "error": {
            "type": "string",
            "example": "Unprocessable Entity"
          }
        },
        "title": "UnprocessableDTO"
      }
    }
  }
}
```

## Code Examples

**cURL**

```bash
curl -L -X POST 'https://services.leadconnectorhq.com/payments/orders/<orderId>/record-payment' \
  -H 'Authorization: Bearer <TOKEN>' \
  -H 'Version: v3' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location",
  "mode": "card",
  "card": {
    "type": "mastercard",
    "last4": "1234"
  },
  "cheque": {
    "number": "129-129-129-912"
  },
  "notes": "This was a direct payment",
  "amount": 100
}'
```

**Node.js**

```javascript
const options = {
  method: 'POST',
  headers: {
    Authorization: 'Bearer <TOKEN>',
    Version: 'v3',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
      "altId": "6578278e879ad2646715ba9c",
      "altType": "location",
      "mode": "card",
      "card": {
        "type": "mastercard",
        "last4": "1234"
      },
      "cheque": {
        "number": "129-129-129-912"
      },
      "notes": "This was a direct payment",
      "amount": 100
  })
};

try {
  const response = await fetch('https://services.leadconnectorhq.com/payments/orders/<orderId>/record-payment', options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

**Python**

```python
import requests

url = "https://services.leadconnectorhq.com/payments/orders/{orderId}/record-payment"

headers = {
    "Authorization": "Bearer <TOKEN>",
    "Version": "v3"
}

payload = {
    "altId": "6578278e879ad2646715ba9c",
    "altType": "location",
    "mode": "card",
    "card": {
        "type": "mastercard",
        "last4": "1234"
    },
    "cheque": {
        "number": "129-129-129-912"
    },
    "notes": "This was a direct payment",
    "amount": 100
}

response = requests.post(url, json=payload, headers=headers)
print(response.json())
```

**PHP**

```php
<?php
$curl = curl_init();

curl_setopt_array($curl, [
  CURLOPT_URL => 'https://services.leadconnectorhq.com/payments/orders/<orderId>/record-payment',
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_CUSTOMREQUEST => 'POST',
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer <TOKEN>',
    'Version: v3',
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => '{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location",
  "mode": "card",
  "card": {
    "type": "mastercard",
    "last4": "1234"
  },
  "cheque": {
    "number": "129-129-129-912"
  },
  "notes": "This was a direct payment",
  "amount": 100
}',
]);

$response = curl_exec($curl);
curl_close($curl);
echo $response;
```

**Java**

```java
HttpResponse<String> response = Unirest
  .post("https://services.leadconnectorhq.com/payments/orders/<orderId>/record-payment")
  .header("Authorization", "Bearer <TOKEN>")
  .header("Version", "v3")
  .header("Content-Type", "application/json")
  .body("{\"altId\":\"6578278e879ad2646715ba9c\",\"altType\":\"location\",\"mode\":\"card\",\"card\":{\"type\":\"mastercard\",\"last4\":\"1234\"},\"cheque\":{\"number\":\"129-129-129-912\"},\"notes\":\"This was a direct payment\",\"amount\":100}")
  .asString();
```

**Go**

```go
package main

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

func main() {
  url := "https://services.leadconnectorhq.com/payments/orders/<orderId>/record-payment"
  payload := strings.NewReader(`{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location",
  "mode": "card",
  "card": {
    "type": "mastercard",
    "last4": "1234"
  },
  "cheque": {
    "number": "129-129-129-912"
  },
  "notes": "This was a direct payment",
  "amount": 100
}`)
  req, _ := http.NewRequest("POST", url, payload)
  req.Header.Add("Authorization", "Bearer <TOKEN>")
  req.Header.Add("Version", "v3")

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

**Ruby**

```ruby
require 'uri'
require 'net/http'

url = URI("https://services.leadconnectorhq.com/payments/orders/<orderId>/record-payment")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Authorization"] = "Bearer <TOKEN>"
request["Version"] = "v3"
request["Content-Type"] = "application/json"
request.body = '{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location",
  "mode": "card",
  "card": {
    "type": "mastercard",
    "last4": "1234"
  },
  "cheque": {
    "number": "129-129-129-912"
  },
  "notes": "This was a direct payment",
  "amount": 100
}'

response = http.request(request)
puts response.read_body
```

**PowerShell**

```powershell
$headers = @{
  "Authorization" = "Bearer <TOKEN>"
  "Version" = "v3"
}

$body = '{
  "altId": "6578278e879ad2646715ba9c",
  "altType": "location",
  "mode": "card",
  "card": {
    "type": "mastercard",
    "last4": "1234"
  },
  "cheque": {
    "number": "129-129-129-912"
  },
  "notes": "This was a direct payment",
  "amount": 100
}'

$response = Invoke-RestMethod -Uri 'https://services.leadconnectorhq.com/payments/orders/<orderId>/record-payment' -Method 'POST' -Headers $headers -Body $body -ContentType 'application/json'
$response | ConvertTo-Json
```
