Skip to content

Instantly share code, notes, and snippets.

@RobertWaiteREPAY
Last active November 18, 2020 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobertWaiteREPAY/307e0a6d309e6622355abf553ae80d54 to your computer and use it in GitHub Desktop.
Save RobertWaiteREPAY/307e0a6d309e6622355abf553ae80d54 to your computer and use it in GitHub Desktop.
PSBlog010
Function Pay-Invoice
{
param(
[Parameter(Mandatory=$true)]
[Microsoft.PowerShell.Commands.WebRequestSession]$WebSession,
$EndPoint = $env:AcumaticaTestEndPoint,
[Parameter(Mandatory=$true)]
[string]$ReferenceNbr,
[Parameter(Mandatory=$true)]
[string]$PaymentMethod)
"Getting Invoice Detail in preparation for payment"
$InvoiceAsPSObject = Get-Invoice -WebSession $WebSession -ReferenceNbr $ReferenceNbr
$PaymentAmount = $InvoiceAsPSObject.Balance.Value.ToString()
$CustomerNbr = $InvoiceAsPSObject.CustomerNbr.Value
"Create A payment for invoice $ReferenceNbr"
$body = @"
{
`"Type`": {`"value`": `"Payment`"},
`"CustomerID`": {`"value`": `"$CustomerNbr`"},
`"PaymentMethod`": {`"value`": `"$PaymentMethod`"},
`"PaymentAmount`": {`"value`": $PaymentAmount},
`"DocumentsToApply`": [{`"ReferenceNbr`": {`"value`": `"$ReferenceNbr`"}}]
}
"@
$HashArguments = @{
Uri = "$AcumaticaEndPoint/entity/default/18.200.001/Payment"
Method = 'PUT'
Headers = $headers
Body = $body
WebSession = $WebSession}
$response = Invoke-RestMethod @HashArguments
$PaymentAsPSObject = $response | ConvertTo-Json | ConvertFrom-Json
$PaymentEntityID = $PaymentAsPSObject.id
"Capturing CC Payment for Invoice $ReferenceNbr on EntityID $PaymentEntityID"
$body = @"
{
`"entity`":
{
`"id`": `"$PaymentEntityID`"
}
}
"@
$HashArguments = @{
Uri = "$AcumaticaEndPoint/entity/default/18.200.001/Payment/CaptureCreditCardPayment"
Method = 'POST'
Headers = $headers
Body = $body
WebSession = $WebSession}
$response = Invoke-RestMethod -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json
sleep 2
$HashArguments = @{
Uri = "$EndPoint/entity/default/18.200.001/Payment?`$Filter=ReferenceNbr eq `'$($PaymentAsPSObject.ReferenceNbr.value)`'"
Method = 'GET'
Headers = $headers
WebSession = $WebSession}
$response = Invoke-RestMethod @HashArguments
$PaymentAsPSObject = $response | ConvertTo-Json | ConvertFrom-Json
return $PaymentAsPSObject
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment