dapi 2.25.3 copy "dapi: ^2.25.3" to clipboard
dapi: ^2.25.3 copied to clipboard

Financial APIs to connect users' bank accounts.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:dapi/dapi.dart';

DapiConnection? connection;
String jsonConnectionParams = "{\n" +
    "    \"bankId\": \"DAPIBANK_AE_ADCB\",\n" +
    "    \"clientUserID\": \"CLIENT_USER_ID\",\n" +
    "    \"color\": {\n" +
    "      \"primaryColor\": \"#BD0000\",\n" +
    "      \"secondaryColor\": \"#2A2B38\"\n" +
    "    },\n" +
    "    \"fullLogoPng\": \"https://cdn.dapi.com/banks-full-logo/ADCB.png\",\n" +
    "    \"fullName\": \"Abu Dhabi Commercial Bank Sandbox\",\n" +
    "    \"halfLogoPng\": \"https://cdn.dapi.com/banks-horizontal-logo/ADCB.png\",\n" +
    "    \"miniLogoPng\": \"https://cdn.dapi.com/banks-mini-logo/ADCB.png\",\n" +
    "    \"name\": \"ADCB+Sandbox\",\n" +
    "    \"tokenID\": \"1ceedd1c-c800-45c1-90d2-d8b9597be8d5\",\n" +
    "    \"userID\": \"7x4orrsRTbIDXLcW2rgHbv1wVSsOOxHdRPg3v0SuSjH57LfPp5/rFayQDnvnWnVg8C8XqaGaenWhN1gjMg6dzw==\",\n" +
    "    \"userSecret\": \"eEBCWu5/7NFFM3otkd4UmckEIasotzcPbHCww3jWn2JZaazYgmMUP38h7tT9wNao9I8KS1Ns2oj+mT+2p/21ZyczFigFS28mn791MlclFe6RykqxmbLmnLp+d61fiR7O6vsewcbjgosR0dqHwkQkcth18bcHzaA8dlsdMOFTAY622zvGAWdikKfPggj8MOmBce8VpV817sv+WvCPtSJ8QAHIZ1obYZ0TZIwv6os9Ifc/8V5G+Mo0DAqjAolDzR8542VYYqjJOaG8BDwRN5S2x81CFSwxU8RBAbQEZsJ0G/5RG6TdhVd1UkEqYt3/FRs/ommYOacn8Nf3VKQtEk+gWue2mSAJInxaK2Tfa+POZcEJUN1/756iLq0r5k2bglknYFTxfYab6Xz8X+f00oDlY/z4qhaR5L1ne01oq+Y+AJBQf1Xyf5aRzyQzTZKblJLzH1Y6z8/YWKOKoabwxgldFghPA1RbZtt0YRRa5pykaJFbIPo9dDA+YaeMDdy+5Nkkz4XDwZowUdw5ejR0mEAL1lXMvPoq5WqmABwRg0Y/dAbD0zgBn0vKQy5VE+FER/QtlEgQpf83jfoBSfwEHCHPPs0gjvw6aiFQqmykNIeuMCeYovEd1OMep3eQ0xX8A7I6yFnJnVNT3kx0KS+kLeLik5Wxh2YpCmqehYUugt5EKzw=\"\n" +
    "  }";

void main() {
  runApp(MyApp());
}

class Button extends StatelessWidget {
  final void Function() onPressed;
  final String text;
  final bool visible;

  const Button(
      {required this.onPressed, required this.text, this.visible = true});

  @override
  Widget build(BuildContext context) {
    Widget button = ElevatedButton(onPressed: onPressed, child: Text(text));
    return Visibility(child: button, visible: visible);
  }
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Dapi Connect'),
        ),
        body: ListView(
          padding: EdgeInsets.all(20),
          children: [
            Button(onPressed: () => startDapi(), text: "Start"),
            Button(
                onPressed: () => setConfigurations(new DapiConfigurations(
                    environment: DapiEnvironment.SANDBOX,
                    countries: List.from({"AE"}),
                    showAddButton: true,
                    postSuccessfulConnectionLoadingText: "TestTest")),
                text: "Set Configurations"),
            Button(
                onPressed: () => configurations(), text: "Get Configurations"),
            Button(onPressed: () => isStarted(), text: "Is Started"),
            Button(
                onPressed: () => setClientUserID("newID"),
                text: "Set Client User ID"),
            Button(onPressed: () => clientUserID(), text: "Get Client User ID"),
            Button(onPressed: () => presentConnect(), text: "Present Connect"),
            Button(onPressed: () => getConnections(), text: "Get Connections"),
            Button(
                onPressed: () => createConnection(jsonConnectionParams),
                text: "Create Connection"),
            Button(
                onPressed: () => getParameters(connection!),
                text: "Get Parameters"),
            Button(
                onPressed: () => getIdentity(connection!),
                text: "Get Identity"),
            Button(
                onPressed: () => getAccounts(connection!),
                text: "Get Accounts"),
            Button(onPressed: () => getCards(connection!), text: "Get Cards"),
            Button(
                onPressed: () => getTransactionsForAccount(connection!,
                    DateTime.parse("2023-01-13"), DateTime.parse("2023-03-25")),
                text: "Get Transactions For Account"),
            Button(
                onPressed: () => getTransactionsForCard(connection!,
                    DateTime.parse("2022-04-25"), DateTime.parse("2022-10-13")),
                text: "Get Transactions For Card"),
            Button(
                onPressed: () => getAccountsMetadata(connection!),
                text: "Get Accounts Metadata"),
            Button(
                onPressed: () => getBeneficiaries(connection!),
                text: "Get Beneficiaries"),
            Button(
                onPressed: () => createBeneficiary(connection!),
                text: "Create Beneficiary"),
            Button(
                onPressed: () {
                  createTransfer(connection!);
                  // Future.delayed(Duration(milliseconds: 3000), () {
                  //   dismissTransfer();
                  // });

                  // Future.delayed(Duration(milliseconds: 10000), () {
                  //   dismissMFA();
                  // });
                },
                text: "Create Transfer"),
            Button(
                onPressed: () => createTransferToExistingBeneficiary(connection!),
                text: "Create Transfer To Existing Beneficiary"),
            Button(
                onPressed: () => getWireBeneficiaries(connection!),
                text: "Get Wire Beneficiaries"),
            Button(
                onPressed: () => createWireBeneficiary(connection!),
                text: "Create Wire Beneficiary"),
            Button(
                onPressed: () => createWireTransfer(connection!),
                text: "Create Wire Transfer"),
            Button(
                onPressed: () =>
                    createWireTransferToExistingBeneficiary(connection!),
                text: "Create Wire Transfer To Existing Beneficiary"),
            Button(
                onPressed: () => createACHPullTransfer(connection!),
                text: "Create ACH Pull Transfer"),
            Button(onPressed: () => delete(connection!), text: "Delete"),
            Button(
                onPressed: () => nymcardLoadFunds(connection!),
                text: "NymCard Load Funds"),
            Button(
                onPressed: () => presentAccountSelection(connection!),
                text: "Present Account Selection")
          ],
        ),
      ),
    );
  }
}

Future startDapi() async {
  try {
    await Dapi.start(
        "APP_KEY",
        "CLIENT_USER_ID",
        configurations: new DapiConfigurations(
            environment: DapiEnvironment.SANDBOX,
            countries: List.from({"US", "AE"}),
            showTransferErrorResult: true,
            showTransferSuccessfulResult: true,
            extraBody: {"key1": "value1", "key2": "value2"},
            extraHeaderFields: {"key1": "value1", "key2": "value2"},
            postSuccessfulConnectionLoadingText: "Test..",
            language: DapiLanguage.EN));
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<bool?> isStarted() async {
  try {
    bool isStarted = await Dapi.isStarted();
    print(isStarted);
    return isStarted;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

void presentConnect() async {
  Dapi.onConnectionSuccessful.listen((m) => print(m));

  Dapi.onConnectionFailure.listen((m) => print(m.error));

  Dapi.onBankRequest.listen((m) => print(m));

  Dapi.onConnectDismissed.listen((m) => print(m));

  Dapi.presentConnect();
}

void dismissConnect() {
  Dapi.dismissConnect();
}

void dismissTransfer() {
  Dapi.dismissTransfer();
}

void dismissMFA() {
  Dapi.dismissMFA();
}

void setConfigurations(DapiConfigurations configurations) {
  Dapi.setConfigurations(configurations);
}

Future<DapiConfigurations> configurations() async {
  DapiConfigurations config = await Dapi.configurations();
  print(config);
  return config;
}

void setClientUserID(String clientUserID) {
  Dapi.setClientUserID(clientUserID);
}

Future<String?> clientUserID() async {
  String? id = await Dapi.clientUserID();
  print(id);
  return id;
}

Future<List<DapiConnection>?> getConnections() async {
  try {
    List<DapiConnection> connections = await Dapi.getConnections();
    if (connections.isNotEmpty) {
      connection = connections.last;
    }
    print(connections.toString());
    return connections;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiIdentityResponse?> getIdentity(DapiConnection connection) async {
  try {
    DapiIdentityResponse identityResponse = await connection.getIdentity();
    return identityResponse;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiAccountsResponse?> getAccounts(DapiConnection connection) async {
  try {
    DapiAccountsResponse accountsResponse = await connection.getAccounts();
    print(accountsResponse.accounts![0].id);
    return accountsResponse;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiCardsResponse?> getCards(DapiConnection connection) async {
  try {
    DapiCardsResponse cardsResponse = await connection.getCards();
    print(cardsResponse.cards!.first.id);
    return cardsResponse;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiTransactionsResponse?> getTransactionsForAccount(
    DapiConnection connection, DateTime fromDate, DateTime toDate) async {
  try {
    DapiAccountsResponse? accountsResponse = await getAccounts(connection);
    DapiTransactionsResponse transactionsResponse =
        await connection.getTransactionsForAccount(
            accountsResponse!.accounts!.first, fromDate, toDate,
            type: DapiTransactionsType.DEFAULT);
    print(transactionsResponse.transactions?.first.amount);
    return transactionsResponse;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiTransactionsResponse?> getTransactionsForCard(
    DapiConnection connection, DateTime fromDate, DateTime toDate) async {
  try {
    DapiCardsResponse? cardsResponse = await getCards(connection);
    DapiTransactionsResponse transactionsResponse = await connection
        .getTransactionsForCard(cardsResponse!.cards!.first, fromDate, toDate,
            type: DapiTransactionsType.CATEGORIZED);
    print(transactionsResponse.transactions!.first.amount);
    return transactionsResponse;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiAccountsMetadataResponse?> getAccountsMetadata(
    DapiConnection connection) async {
  try {
    DapiAccountsMetadataResponse accountsMetadataResponse =
        await connection.getAccountsMetadata();
    print(accountsMetadataResponse.metadata?.address?.line1.toString());
    print(accountsMetadataResponse.metadata?.address?.line2.toString());
    print(accountsMetadataResponse.metadata?.address?.line3.toString());
    return accountsMetadataResponse;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiResult?> delete(DapiConnection connection) async {
  try {
    DapiResult result = await connection.delete();
    print(result);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiBeneficiariesResponse?> getBeneficiaries(
    DapiConnection connection) async {
  try {
    DapiBeneficiariesResponse beneficiariesResponse =
        await connection.getBeneficiaries();
    print(beneficiariesResponse.beneficiaries!.first.id);
    return beneficiariesResponse;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiResult?> createBeneficiary(DapiConnection connection) async {
  try {
    DapiResult result =
        await connection.createBeneficiary(getSandboxBeneficiary());
    print(result.operationID);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<CreateTransferResponse?> createTransfer(
    DapiConnection connection) async {
  try {
    DapiAccountsResponse? accountsResponse = await getAccounts(connection);
Dapi.setOnTransferSuccessResult((result) {
  return "Test Success Message";
});

Dapi.setOnTransferErrorResult((error) {
  return "Test Error Message";
});
    Dapi.onTransferUiDismissed.listen((m) => print("TRANSFER_UI_DISMISSED"));
    Dapi.onTransferUiWillSend.listen((m) => print("TRANSFER_UI_WILL_SEND"));
    CreateTransferResponse? result = await connection.createTransfer(
        null, getSandboxBeneficiary(), 100, "test remark");
    print(result.accountID);
    print(result.remark);
    print(result.reference);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
    print(
        'Error logged in Example Flutter app ${e.beneficiaryCoolDownPeriod?.unit}.');
    print(
        'Error logged in Example Flutter app ${e.beneficiaryCoolDownPeriod?.value}.');
  }
}

Future<CreateTransferResponse?> createTransferToExistingBeneficiary(
    DapiConnection connection) async {
  try {
    DapiAccountsResponse? accountsResponse = await getAccounts(connection);
    DapiBeneficiariesResponse? beneficiariesResponse =
        await getBeneficiaries(connection);
    CreateTransferResponse result =
        await connection.createTransferToExistingBeneficiary(
            accountsResponse!.accounts!.first,
            beneficiariesResponse!.beneficiaries!.first.id!,
            2.0,
            null);
    print(result.accountID);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiWireBeneficiariesResponse?> getWireBeneficiaries(
    DapiConnection connection) async {
  try {
    DapiWireBeneficiariesResponse beneficiariesResponse =
        await connection.getWireBeneficiaries();
    print(beneficiariesResponse.beneficiaries!.first.routingNumber);
    return beneficiariesResponse;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiResult?> createWireBeneficiary(DapiConnection connection) async {
  try {
    DapiResult result =
        await connection.createWireBeneficiary(getSandboxWireBeneficiary());
    print(result.operationID);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<CreateTransferResponse?> createWireTransfer(
    DapiConnection connection) async {
  try {
    Dapi.onTransferUiDismissed.listen((m) => print("TRANSFER_UI_DISMISSED"));
    Dapi.onTransferUiWillSend.listen((m) => print("TRANSFER_UI_WILL_SEND"));
    DapiAccountsResponse? accountsResponse = await getAccounts(connection);

    CreateTransferResponse result = await connection.createWireTransfer(
        accountsResponse!.accounts!.first,
        getSandboxWireBeneficiary(),
        0,
        "remark");
    print(result.accountID);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<CreateTransferResponse?> createWireTransferToExistingBeneficiary(
    DapiConnection connection) async {
  try {
    DapiAccountsResponse? accountsResponse = await getAccounts(connection);
    DapiWireBeneficiariesResponse? beneficiariesResponse =
        await getWireBeneficiaries(connection);
    CreateTransferResponse result =
        await connection.createWireTransferToExistingBeneficiary(
            accountsResponse!.accounts!.first,
            beneficiariesResponse!.beneficiaries!.first.id!,
            99.0,
            "remark");
    print(result.accountID);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<CreateTransferResponse?> createACHPullTransfer(
    DapiConnection connection) async {
  try {
    Dapi.onTransferUiDismissed.listen((m) => print("TRANSFER_UI_DISMISSED"));
    Dapi.onTransferUiWillSend.listen((m) => print("TRANSFER_UI_WILL_SEND"));
    DapiAccountsResponse? accountsResponse = await getAccounts(connection);

    CreateTransferResponse result =
        await connection.createACHPullTransfer("description", null, 0);
    print(result.accountID);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<CreateTransferResponse?> nymcardLoadFunds(
    DapiConnection connection) async {
  try {
    Dapi.onTransferUiDismissed.listen((m) => print("TRANSFER_UI_DISMISSED"));
    Dapi.onTransferUiWillSend.listen((m) => print("TRANSFER_UI_WILL_SEND"));

    DapiAccountsResponse? accountsResponse = await getAccounts(connection);

    CreateTransferResponse result =
    await connection.nymcardLoadFunds("token", null, 0);
    print(result.remark);
    return result;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

DapiBeneficiary getSandboxBeneficiary() {
  DapiLineAddress lineAddress = DapiLineAddress(
      line1: "baniyas road", line2: "dubai", line3: "united arab emirates");

  return DapiBeneficiary(
      address: lineAddress,
      accountNumber: "1166666666666666",
      name: "name",
      bankName: "bankName",
      swiftCode: "DAPIBANK",
      iban: "DAPIBANKAE1166666666666666",
      country: "AE",
      branchAddress: "branchAddress",
      branchName: "branchName",
      phoneNumber: "xxxxxxxxxxx",
      nickname: "nickname12");
}

DapiWireBeneficiary getSandboxWireBeneficiary() {
  DapiLineAddress lineAddress = DapiLineAddress(
      line1: "2400 bruce street UCA stadium park bld 6", line2: "", line3: "");

  DapiWireBeneficiary beneficiary = new DapiWireBeneficiary(
      address: lineAddress,
      accountNumber: "1234567654321",
      name: "TestAccount",
      country: "US",
      receiverType: "retail",
      routingNumber: "953349354",
      nickname: "OmarChase",
      receiverAccountType: "checking",
      firstName: "Omar",
      lastName: "Agoor",
      zipCode: "72305",
      state: "Arkansas",
      city: "Conway");

  return beneficiary;
}

Future<DapiConnection?> createConnection(String jsonConnectionParams) async {
  try {
    DapiConnection connection =
        await DapiConnection.create(jsonConnectionParams);
    print(connection.bankID);
    return connection;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<String?> getParameters(DapiConnection connection) async {
  try {
    String params = await connection.getParameters();
    print(params);
    jsonConnectionParams = params;
    return params;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<DapiAccount?> presentAccountSelection(DapiConnection connection) async {
  try {
    DapiAccount account = await connection.presentAccountSelection();
    print(account);
    print(account.id);
    print(account.iban);
    return account;
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}
1
likes
100
pub points
53%
popularity

Publisher

verified publisherdapi.com

Financial APIs to connect users' bank accounts.

Homepage

Documentation

API reference

License

BSD-3-Clause (LICENSE)

Dependencies

collection, flutter, intl

More

Packages that depend on dapi