Public/PartialPayments/New-AspirePartialPayment.ps1

<#
.SYNOPSIS
    Creates a new partial payment in the Aspire API.
.DESCRIPTION
    Uses Invoke-AspireRequest to perform a POST request to the /PartialPayments endpoint.
.PARAMETER Amount
    The payment amount (required, minimum 0.01).
.PARAMETER PaymentDate
    The payment date (required, date-time format).
.PARAMETER PaymentMethod
    The payment method (required, max 20 characters).
.PARAMETER PaymentReference
    The payment reference (required, max 50 characters).
.PARAMETER BillingCompany
    Optional billing company name (max 100 characters).
.PARAMETER BillingContact
    Optional billing contact name (max 250 characters).
.PARAMETER BranchName
    Optional branch name (max 50 characters).
.PARAMETER InvoiceNumber
    Optional invoice number.
.PARAMETER PaymentNote
    Optional payment note.
.OUTPUTS
    The response from the API containing the partial payment details.
.EXAMPLE
    New-AspirePartialPayment -Amount 100.00 -PaymentDate "2023-01-01T00:00:00Z" -PaymentMethod "Credit Card" -PaymentReference "REF123"
#>

function New-AspirePartialPayment {
    [CmdletBinding()]
    param(
        [Parameter(Mandatory = $true)]
        [double]$Amount,
        [Parameter(Mandatory = $true)]
        [string]$PaymentDate,
        [Parameter(Mandatory = $true)]
        [string]$PaymentMethod,
        [Parameter(Mandatory = $true)]
        [string]$PaymentReference,
        [string]$BillingCompany = $null,
        [string]$BillingContact = $null,
        [string]$BranchName = $null,
        [int]$InvoiceNumber = $null,
        [string]$PaymentNote = $null
    )

    $body = @{
        Amount = $Amount
        PaymentDate = $PaymentDate
        PaymentMethod = $PaymentMethod
        PaymentReference = $PaymentReference
    }

    if ($BillingCompany) {
        $body.BillingCompany = $BillingCompany
    }
    if ($BillingContact) {
        $body.BillingContact = $BillingContact
    }
    if ($BranchName) {
        $body.BranchName = $BranchName
    }
    if ($InvoiceNumber) {
        $body.InvoiceNumber = $InvoiceNumber
    }
    if ($PaymentNote) {
        $body.PaymentNote = $PaymentNote
    }

    return Invoke-AspireRequest -Method POST -Path "/PartialPayments" -Body $body -ApiVersion $null
}