Sending payments

Overview

Sending payments is achieved through the use of payouts. In order to support a variety of business processes sending payments is a two step process:

  1. A payout record is created
  2. A payout record is authorized for payment.

The steps above allow developers to cater for a variety of situations. From the creation and submission of a single payout to the batch approval of multiple payouts.

Creating a payout

When creating a payout the following data needs to be specified:

  • Source account ID
  • Payment currency
  • Payment amount
  • Sender's reference
  • Destination IBAN (some useful information on IBANs for testing can be found here)
  • Destination account name
  • Recipient's reference

The following code snippets provide examples of payout creation:

using System.Net.Http.Json;

//Remember to keep the JWT token safe and secure.
var jwtToken = Environment.GetEnvironmentVariable("NOFRIXION_USER_TOKEN");

string baseUrl = "<<SANDBOX_URL>>payouts";

var client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/json");
client.DefaultRequestHeaders.Add("Authorization", $"Bearer {jwtToken}");

var data = new Dictionary<string, string>();
data.Add("AccountID", "A120P0JR");
data.Add("Currency", "EUR");
data.Add("Amount", "19.99");
data.Add("YourReference", "My Ref");
data.Add("DestinationIBAN", "GB94BARC10201530093459");
data.Add("DestinationAccountName", "Dest Name");
data.Add("TheirReference", "Their Ref");

HttpContent postData = new FormUrlEncodedContent(data);

HttpResponseMessage response = await client.PostAsync(baseUrl, postData);
if (response.IsSuccessStatusCode)
{
    // "Created" on success
    Console.WriteLine(response.StatusCode);

    // The newly created payout object will be returned in the response body
    Console.WriteLine(await response.Content.ReadFromJsonAsync<Payout>());
}
else
{
    // HTTP error codes will return a MoneyMoov API problem object
    Console.WriteLine(await response.Content.ReadFromJsonAsync<ApiProblem>());
}

// Type definitions for returned data
record Payout(string currentUserID, string currentUserRole, string approvePayoutUrl, string id,
                string accountID, string userID, string type, string description, string currency,
                decimal amount, string yourReference, string destinationAccountID, string destinationIBAN,
                string destinationAccountName, string theirReference);

record ApiProblem(string type, string title, int status, string detail);
// These modules allow the code to run on Node.js, they aren't required if running in a browser.
const fetch = require('cross-fetch');
const FormData = require('form-data');

// Remember, the JWT access token must be securely store - this example uses an environment variable
const jwtToken = process.env.NOFRIXION_USER_TOKEN;

const url = '<<SANDBOX_URL>>payouts';

// Example form data
const form = new FormData();
form.append('AccountID', 'A120P0JR');
form.append('Currency', 'EUR');
form.append('Amount', '12.34');
form.append('YourReference', 'Sender ref');
form.append('DestinationIBAN', 'GB33BUKB20201555555555');
form.append('DestinationAccountName', 'Test Account');
form.append('TheirReference', 'Recipient ref');

const options = {
    method: 'POST',
    headers: {
        Accept: 'application/json',
        Authorization: 'Bearer ' + jwtToken
    }
};

options.body = form;

fetch(url, options)
    .then(response => response.json())
    // Response object containsd details of the newly created payout.
    .then(responseJson => console.log(responseJson))
    .catch(err => console.error(err));
# The 'requests' library for Python can be used to make calls to the MoneyMoov API in
# popular python frameworks such as Django and Flask.
import requests
import os

# Remember, the JWT access token must be securely stored ('os' module above allows storage in environment variable)
jwtToken = os.environ['NOFRIXION_USER_TOKEN']

baseUrl = "<<SANDBOX_URL>>/payouts"

headers = {
    "Accept": "application/json",
    "Authorization": f"Bearer {jwtToken}"
}

paymentData = {
    "AccountID": "A120P0JR",
    "Currency": "EUR",
    "Amount": "0.99",
    "YourReference": "My reference",
    "DestinationIBAN": "GB33BUKB20201555555555",
    "DestinationAccountName": "Destination Name",
    "TheirReference": "Their reference"
}

response = requests.request("POST", baseUrl, headers=headers, data=paymentData)

if response.ok:
    # On successful payout creation, the API returns the payout object
    print(response.json())
else:
    # If not OK, response contains MoneyMoov problem (https://docs.nofrixion.com/reference/error-messages)
    print(response.json())

Remember, the payment is not sent when the payment is created, it still needs to be authorized to complete the process.