Send from Master Account balance to Customer Funding Source NETStandard C#

Hi there,
I’m using NETStandard Dwolla.Client Nuget v. 5.1.1 (the last at this point). What I try to do is transferring from Master Account balance to a verified funding source of receive-only Customer. I use “send” link of the Account entity and failed to perform transfer successfully on my own or find a solution. Here’s what I have right now:

var root = await GetRootAsync();
//Account inherits BaseResponse and has Id and Name properties
var accountResponse = await GetAsync<Account>(root.Links[DwollaConsts.Account].Href);
ValidateResponse(accountResponse, nameof(ChargeAsync));
var account = accountResponse.Content;

var fundingSourcesResponse = await GetAsync<GetFundingSourcesResponse>(new Uri(
    $@"{new Uri($"{root.Links[DwollaConsts.Customers].Href}/{input.PaymentGatewayCustomerIdentifier}")
        .AbsoluteUri}/{DwollaConsts.FundingSources}"));

ValidateResponse(fundingSourcesResponse, nameof(ChargeAsync));

var destinationFundingSource = fundingSourcesResponse.Content.Embedded.FundingSources.FirstOrDefault(fs =>
    fs.Id == input.SourceIdentifier);

Check.NotNull(destinationFundingSource, nameof(destinationFundingSource));
Debug.Assert(destinationFundingSource != null, "destinationFundingSource != null");

var createTransferRequest = new CreateTransferRequest
{
    Amount = new Money {Currency = input.Currency, Value = input.Amount},
    Links = new Dictionary<string, Link>(new List<KeyValuePair<string, Link>>
    {
        //new KeyValuePair<string, Link>(DwollaConsts.Source, account.Links[DwollaConsts.Self]),
        new KeyValuePair<string, Link>(DwollaConsts.Destination, destinationFundingSource.Links[DwollaConsts.Self])
    })
};

var sendResponse = await PostAsync<CreateTransferRequest, TransferResponse>(
    account.Links[DwollaConsts.Send].Href, createTransferRequest);

//that fails with a message "A server error occurred. Error ID: 1d1a5862-2110-45d1-82bc-8c247e9610ff."
ValidateResponse(sendResponse, nameof(ChargeAsync));
var sendTransfer = sendResponse.Content;

Hi @Neuren, I pulled your request body from our logs and here is what we are receiving:

{
    "_links": {
        "destination": {
            "href": "https://api-sandbox.dwolla.com/funding-sources/280509b3-a13d-4bf1-afce-15054f0a9402",
            "type": "application/vnd.dwolla.v1.hal+json",
            "resource-type": "funding-source"
        }
    },
    "amount": {
        "value": 1.0,
        "currency": "USD"
    }
}
}

It appears that you are missing the source JSON object which indicates what the source funding source is in the Transfer request. Try updating your request body to add that in and let us know if it works! Here’s an example of a valid request body:

{
"_links": {
    "source": {
        "href": "https://api-sandbox.dwolla.com/funding-sources/{{BalanceFundingSourceId}}"
    },
    "destination": {
        "href": "https://api-sandbox.dwolla.com/funding-sources/{{BankFundingSourceId}}"
    }
},
"amount": {
    "currency": "USD",
    "value": "42.00"
}
}
1 Like

Hi, @spencer, ok got it, thanks. I thought “send” link used from Account doesn’t require source and uses its balance. Trying…

Ah, gotcha! That sounds like a valid assumption. If we allowed you to set a default funding source (since there are multiple types), then I think this would be an interesting approach.

It worked. I didn’t realize balance is a funding source with a type “balance” and “send” still has to have Source provided. I’ve added

var accountFundingSourcesResponse =
                await GetAsync<GetFundingSourcesResponse>(account.Links[DwollaConsts.FundingSources].Href);

            ValidateResponse(accountFundingSourcesResponse, nameof(ChargeAsync));
            var accountFundingSources = accountFundingSourcesResponse.Content.Embedded.FundingSources;

            var balanceAccountFs =
                accountFundingSources.FirstOrDefault(fs => fs.Type == DwollaConsts.BalanceFundingSourceType);

and

var createTransferRequest = new CreateTransferRequest
{
    Amount = new Money {Currency = input.Currency, Value = input.Amount},
    Links = new Dictionary<string, Link>(new List<KeyValuePair<string, Link>>
    {
        new KeyValuePair<string, Link>(DwollaConsts.Source, balanceAccountFs.Links[DwollaConsts.Self]),
        new KeyValuePair<string, Link>(DwollaConsts.Destination, destinationFundingSource.Links[DwollaConsts.Self])
    })
};

@spencer thank you once again.

1 Like