Deferred Transactions

Visit the Deferred Transactions reference area for background details.

The deferred transaction API client allows you to create, validate, group and retrieve deferred transactions. Below are code samples on how this client can be used.

Configure a new deferred transaction API client

var config = new Configuration("{api-token}", Environment.Staging);
var dtxClient = new DeferredTransactionApiClient(config);

Validate or create a deferred transaction

A forex rate group is required when creating or validating a deferred transaction, details can be found in section 6.

A TransactionRequest object needs to be defined to set the payment details, more details can be found. It is also possible to create a transaction and grouping it with one call.

// create forex group
ForexInfo forexRateGroup = await forexClient.CreateAsync(1);

// define transaction request
var rq = new TransactionRequest
{
  SendValue = 10,
  SendCurrency = "GBP",
  Recipient = new Recipient
  {
    Name = "SDK TESTING",
    Country = "GB",
    Currency = "GBP",
    RecipientReference = "REF",
    Account = new AccountDescriptor
    {
      AccountNumber = "11111111",
      SortCode = "111111"
    }
  },
  RateGroupId = forexRateGroup.Resource.RateGroupId
};

// validate deferred transaction
Response<TransactionResponse> validateDtx = await dtxClient.ValidateAsync(rq);

// create deferred transaction
Response<TransactionResponse> createDtx = await dtxClient.CreateAsync(rq);

// create deferred transaction with group
Response<DeferredTransactionAndGroup> createDtxWithGroup = 
  await dtxClient.CreateWithGroupAsync(rq);

Retrieve deferred transactions and groups

The deferred transactions can be used to retrieve a deferred transaction, ungrouped transactions, a specific group and all groups.

var dtxWithGroup = 
  await dtxClient.CreateWithGroupAsync(rq);

var txId = dtxWithGroup.Resource.Transaction.TransactionId;
var groupId = dtxWithGroup.Resource.Group.DeferredTransactionGroupId;

// retrieve deferred transaction (by Guid or string)
TransactionResponse dtx = await dtxClient.RetrieveAsync(txId);

// retrieve ungrouped deferred transactions
List<TransactionSummary> ungroupedDtx = await dtxClient.RetrieveUngroupedAsync();

// retrieve group (by string or int)
DeferredTransactionGroup group = await dtxClient.RetrieveGroupAsync(groupId);

// retrieve all groups
List<DeferredTransactionGroup> allGroups = await dtxClient.RetrieveGroupsAsync();

Group deferred transactions

A group can be created for ungrouped deferred transactions, however they must be of the same source currency.

var ungroupedDtx = await dtxClient.RetrieveUngroupedAsync();

List<Guid> ungroupedTxIds = ungrouped
  .Where(y=>y.SourceCurrency == "GBP" && y.ExpiresOn > DateTime.UtcNow)
  .Select(x => x.TransactionRequestId).ToList();

// create a group for ungrouped deferred transactions 
// List<Guid> required as the parameter
Response<DeferredTransactionGroup> createdGroup = 
  await dtxClient.CreateGroupAsync(ungroupedTxIds);