Skip to content

Instantly share code, notes, and snippets.

@georgehemmings
Last active September 1, 2016 15:24
Show Gist options
  • Save georgehemmings/da83ccdec265e6ba1edafa877a9108b4 to your computer and use it in GitHub Desktop.
Save georgehemmings/da83ccdec265e6ba1edafa877a9108b4 to your computer and use it in GitHub Desktop.
PostDirectToClientPayment
using System;
using System.Collections.Generic;
using System.Linq;
using Orca.ServiceModel;
using Orca.ServiceModel.Types;
using ServiceStack;
using ServiceStack.Text;
namespace PostDirectToClientPayment
{
class Program
{
static void Main(string[] args)
{
JsConfig.DateHandler = DateHandler.ISO8601;
JsConfig.SkipDateTimeConversion = true;
var client = new JsonServiceClient("http://local.orca/api")
{
AlwaysSendBasicAuthHeader = true,
UserName = "adtec",
Password = "PASSWORD1234"
};
var debtCodeFromSource = "INI0000001";
var paymentAmountFromSource = 10m;
var debt = client.Send(new GetDebt
{
Code = debtCodeFromSource
}).Debt;
Transaction outstandingPlc;
if (debt.ConsolidationDebtCode == null)
{
var transactions = client.Send(new GetTransactions
{
DebtCode = debt.Code
}).Results;
outstandingPlc = transactions.First(t =>
t.TransactionTypeCode == "PLC" &&
t.Outstanding > 0);
}
else
{
var consolidatedDebt = debt;
debt = client.Send(new GetDebt
{
Code = debt.ConsolidationDebtCode
}).Debt;
var transactions = client.Send(new GetTransactions
{
DebtCode = debt.Code
}).Results;
outstandingPlc = transactions.First(t =>
t.TransactionTypeCode == "PLC" &&
t.Outstanding > 0 &&
t.Reference == consolidatedDebt.ClientReference);
}
var createdTransaction = client.Send(new CreateTransaction
{
DebtCode = debt.Code,
DebtorId = debt.Debtors.First().Id,
TransactionDate = DateTime.Today,
TransactionTypeCode = "DC",
Amount = paymentAmountFromSource,
Allocations = new List<CreateTransaction.Allocation>
{
new CreateTransaction.Allocation
{
TransactionId = outstandingPlc.Id,
AllocationAmount = Math.Min(paymentAmountFromSource, outstandingPlc.Outstanding.Value)
}
}
}).Result;
createdTransaction.PrintDump();
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment