Source Code

Here's the full source code for the Sample Application. Alternatively, it can be downloaded from here.

package com.ixaris.example;

import io.swagger.client.ApiClient;
import io.swagger.client.ApiException;
import io.swagger.client.api.AuthApi;
import io.swagger.client.api.CardIssuingSimulatorApi;
import io.swagger.client.api.DepositsApi;
import io.swagger.client.api.ExternalAccountsApi;
import io.swagger.client.api.ManagedAccountsApi;
import io.swagger.client.api.ManagedCardsApi;
import io.swagger.client.api.PayinSimulatorApi;
import io.swagger.client.api.TransfersApi;
import io.swagger.client.model.CreateExternalAccountDepositParams;
import io.swagger.client.model.CreateExternalAccountParams;
import io.swagger.client.model.CreateManagedAccountParams;
import io.swagger.client.model.CreateManagedCardParams;
import io.swagger.client.model.CreatePayinSimulationParams;
import io.swagger.client.model.CreateTransferParams;
import io.swagger.client.model.CurrencyAmountMessage;
import io.swagger.client.model.ExternalAccount;
import io.swagger.client.model.ExternalAccountInfo;
import io.swagger.client.model.Fee;
import io.swagger.client.model.FeeDefinition;
import io.swagger.client.model.FeeDefinition.FeeTypeEnum;
import io.swagger.client.model.LoginParams;
import io.swagger.client.model.LoginResult;
import io.swagger.client.model.ManagedAccount;
import io.swagger.client.model.ManagedCard;
import io.swagger.client.model.PayinSimulation;
import io.swagger.client.model.PurchaseSimulationParams;
import io.swagger.client.model.TypedId;

/**
 * An example client making use of the OPE APIs to create a card and transfer some funds on it.
 */
public class ExampleClient {

    // Instrument types required for performing transactions
    private static final String MANAGED_CARD_TYPE = "managed_cards";
    private static final String MANAGED_ACCOUNT_TYPE = "managed_accounts";
    private static final String EXTERNAL_ACCOUNT_TYPE = "external_accounts";

    // Configuration settings - replace the following values with your own
    private static final String API_BASE_PATH = "http://localhost:8324/api";
    private static final String USERNAME = "user";
    private static final String PASSWORD = "Password";
    private static final String TENANT_ID = "team-01";
    private static final long PROGRAMME_ID = 123L;
    private static final long MANAGED_ACCOUNT_PROFILE_ID = 1L;
    private static final long EXTERNAL_ACCOUNT_PROFILE_ID = 1L;
    private static final long MANAGED_CARD_PROFILE_ID = 1L;
    private static final long CORPORATE_IDENTITY_ID = 1L;
    private static final long TRANSFER_PROFILE_ID = 1L;
    private static final long DEPOSIT_PROFILE_ID = 1L;

    // The format of the programme key is as follows: '%tenant_id%|%programme_id%'
    private static final String PROGRAMME_KEY = String.format("%s|%s", TENANT_ID, PROGRAMME_ID);

    public static void main(final String[] args) {
        try {
            helloWorld();
        } catch (final ApiException e) {
            // Something went wrong
            e.printStackTrace();
        }
    }

    private static void helloWorld() throws ApiException {
        // Set the base path of the API
        final ApiClient client = new ApiClient().setBasePath(API_BASE_PATH);

        // Login with your credentials to get an Authorisation token
        final AuthApi authApi = new AuthApi(client);
        final LoginParams loginRequest = new LoginParams().credentialCode(USERNAME).password(PASSWORD).programmeId(PROGRAMME_ID);
        final LoginResult loginResult = authApi.authLogin(generateCallRef(), PROGRAMME_KEY, loginRequest);

        final String token = loginResult.getToken();

        // Create a managed account
        final ManagedAccountsApi managedAccountsApi = new ManagedAccountsApi(client);
        final CreateManagedAccountParams createManagedAccountParams = new CreateManagedAccountParams()
                .profileId(MANAGED_ACCOUNT_PROFILE_ID)
                .ownerId(CORPORATE_IDENTITY_ID)
                .friendlyName("Finance Dept. Managed Account")
                .currency("GBP")
                .issuingProvider("Issuer");
        final ManagedAccount managedAccount = managedAccountsApi.managedAccountsIdCreate(generateCallRef(), PROGRAMME_KEY, token, createManagedAccountParams);

        // Create an external account
        final ExternalAccountsApi externalAccountsApi = new ExternalAccountsApi(client);
        final CreateExternalAccountParams createExternalAccountRequest = new CreateExternalAccountParams()
                .profileId(EXTERNAL_ACCOUNT_PROFILE_ID)
                .ownerId(CORPORATE_IDENTITY_ID)
                .friendlyName("GBP Bank of Europe Account")
                .externalAccountInfo(new ExternalAccountInfo()
                    .bankAccountNumber("31926819")
                    .payee("Mr John Doe")
                    .bankName("Bank of Europe")
                    .bankCode("NWBK")
                    .branchCode("601613")
                    .accountType("Savings")
                    .checkDigits("29")
                    .ibanCode("GB29NWBK60161331926819")
                    .swiftCode("ABCDEF12")
                    .branchAddress("Bank of Europe, London, UK")
                    .country("GB")
                    .additionalInformation("Any additional information goes here")
                    .currency("GBP"));
        final ExternalAccount externalAccount = externalAccountsApi.externalAccountsIdCreate(generateCallRef(), PROGRAMME_KEY, token, createExternalAccountRequest);

        // Simulate a payin
        final CurrencyAmountMessage payinAmount = new CurrencyAmountMessage().currency("GBP").amount(10000L);
        final PayinSimulatorApi payinSimulatorApi = new PayinSimulatorApi(client);
        final CreatePayinSimulationParams payinRequest = new CreatePayinSimulationParams().amount(payinAmount)
                .externalAccountId(externalAccount.getId())
                .additionalInfo("Any additional information goes here");
        final PayinSimulation payin = payinSimulatorApi.payinSimulatorIdPayin(generateCallRef(), PROGRAMME_KEY, token, payinRequest);

        // Perform a deposit
        final DepositsApi depositsApi = new DepositsApi(client);
        final CreateExternalAccountDepositParams depositRequest = new CreateExternalAccountDepositParams()
                .profileId(DEPOSIT_PROFILE_ID)
                .amount(payinAmount)
                .sourceInstrumentId(new TypedId().type(EXTERNAL_ACCOUNT_TYPE).id(externalAccount.getId()))
                .sourcePayinId(payin.getId())
                .destinationInstrumentId(new TypedId().type("managed_accounts").id(managedAccount.getId()));
        depositsApi.depositsIdCreateFromExternalAccount(generateCallRef(), PROGRAMME_KEY, token, depositRequest);

        // Create a managed card instrument using an existing profile
        final ManagedCardsApi managedCardsApi = new ManagedCardsApi(client);
        final CreateManagedCardParams createCardRequest = new CreateManagedCardParams()
                .profileId(MANAGED_CARD_PROFILE_ID)
                .ownerId(CORPORATE_IDENTITY_ID)
                .friendlyName("John's GBP card")
                .currency("GBP")
                .issuingProvider("IssuingProvider")
                .processingProvider("ProcessingProvider")
                .nameOnCard("John Doe");
        final ManagedCard card = managedCardsApi.managedCardsIdCreate(generateCallRef(), PROGRAMME_KEY, token, createCardRequest);

        // Transfer 60 GBP from an existing managed account instrument to the newly created card
        final TransfersApi transfersApi = new TransfersApi(client);
        final TypedId sourceInstrumentId = new TypedId().type(MANAGED_ACCOUNT_TYPE).id(managedAccount.getId());
        final CreateTransferParams createTransferParams =
            new CreateTransferParams().profileId(TRANSFER_PROFILE_ID)
                  .amount(new CurrencyAmountMessage().currency("GBP").amount(6000L)) // 60.00 GBP
                  .sourceInstrumentId(sourceInstrumentId)
                  .destinationInstrumentId(new TypedId().type(MANAGED_CARD_TYPE).id(card.getId()))
                  .addFeesItem(new Fee().instrumentId(sourceInstrumentId)
                        .feeDefinition(new FeeDefinition().key("exampleFee")
                            .feeType(FeeTypeEnum.FLAT)
                            .addFlatAmountFeesItem(new CurrencyAmountMessage().currency("GBP").amount(100L))));   // 1 GBP
        transfersApi.transfersIdCreate(generateCallRef(), PROGRAMME_KEY, token, createTransferParams);

        // Simulate a purchase
        final CardIssuingSimulatorApi cardIssuingSimulatorApi = new CardIssuingSimulatorApi(client);
        final PurchaseSimulationParams purchaseRequest = new PurchaseSimulationParams()
                .cardId(card.getId())
                .purchaseAmount(new CurrencyAmountMessage().currency("GBP").amount(-4500L)) // 45.00 GBP
                .merchantName("Example Merchant");
        cardIssuingSimulatorApi.cardIssuingSimulatorPurchase(generateCallRef(), PROGRAMME_KEY, token, purchaseRequest);
    }

    private static String generateCallRef() {
        // Call reference can be generated from the current timestamp
        return Long.toString(System.currentTimeMillis());
    }
}