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

outdated

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;

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({"SA", "EG"}), showAddButton: true)),
                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: () => 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("2021-05-01"), DateTime.parse("2021-09-10")),
                text: "Get Transactions For Account"),
            Button(
                onPressed: () => getTransactionsForCard(connection!,
                    DateTime.parse("2021-05-01"), DateTime.parse("2021-09-10")),
                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!),
                text: "Create Transfer"),
            Button(
                onPressed: () =>
                    createTransferToExistingBeneficiary(connection!),
                text: "Create Transfer To Existing Beneficiary"),
            Button(onPressed: () => delete(connection!), text: "Delete"),
          ],
        ),
      ),
    );
  }
}

Future<String?> startDapi() async {
  try {
    return await Dapi.start(
        "1d4592c4a8dd6ff75261e57eb3f80c518d7857d6617769af3f8f04b0590baceb",
        "1234ID",
        configurations: new DapiConfigurations(
            environment: DapiEnvironment.SANDBOX,
            countries: List.from({"AE"})));
  } on DapiSdkException catch (e) {
    print('Error logged in Example Flutter app $e.');
  }
}

Future<bool> isStarted() async {
  bool isStarted = await Dapi.isStarted();
  print(isStarted);
  return isStarted;
}

void presentConnect() async {
  Dapi.onConnectionSuccessful
      .listen((m) => print("CONNECTION_SUCCESSFUl userID: ${m.userID}"));

  Dapi.onConnectionFailure.listen((m) => dismissConnect());
  Dapi.presentConnect();
}

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

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 {
  List<DapiConnection> connections = await Dapi.getConnections();
  if (connections.isNotEmpty) {
    connection = connections.first;
  }
  print(connections.toString());
  return connections;
}

Future<DapiIdentityResponse> getIdentity(DapiConnection connection) async {
  DapiIdentityResponse identityResponse = await connection.getIdentity();
  print(identityResponse.identity!.emailAddress);
  return identityResponse;
}

Future<DapiAccountsResponse> getAccounts(DapiConnection connection) async {
  DapiAccountsResponse accountsResponse = await connection.getAccounts();
  print(accountsResponse.accounts![1].id);
  return accountsResponse;
}

Future<DapiCardsResponse> getCards(DapiConnection connection) async {
  DapiCardsResponse cardsResponse = await connection.getCards();
  print(cardsResponse.cards!.first.id);
  return cardsResponse;
}

Future<DapiTransactionsResponse> getTransactionsForAccount(
    DapiConnection connection, DateTime fromDate, DateTime toDate) async {
  DapiTransactionsResponse transactionsResponse = await connection
      .getTransactionsForAccount(connection.accounts.first, fromDate, toDate);
  print(transactionsResponse.transactions!.first.amount);
  return transactionsResponse;
}

Future<DapiTransactionsResponse> getTransactionsForCard(
    DapiConnection connection, DateTime fromDate, DateTime toDate) async {
  DapiTransactionsResponse transactionsResponse = await connection
      .getTransactionsForCard(connection.cards.first, fromDate, toDate);
  print(transactionsResponse.transactions!.first.amount);
  return transactionsResponse;
}

Future<DapiAccountsMetadataResponse> getAccountsMetadata(
    DapiConnection connection) async {
  DapiAccountsMetadataResponse accountsMetadataResponse =
      await connection.getAccountsMetadata();
  print(accountsMetadataResponse.metadata?.swiftCode);
  return accountsMetadataResponse;
}

Future<DapiResult> delete(DapiConnection connection) async {
  DapiResult result = await connection.delete();
  print(result);
  return result;
}

Future<DapiBeneficiariesResponse> getBeneficiaries(
    DapiConnection connection) async {
  DapiBeneficiariesResponse beneficiariesResponse =
      await connection.getBeneficiaries();
  print(beneficiariesResponse.beneficiaries!.first.id);
  return beneficiariesResponse;
}

Future<DapiResult> createBeneficiary(DapiConnection connection) async {
  DapiResult result =
      await connection.createBeneficiary(getSandboxBeneficiary());
  print(result.operationID);
  return result;
}

Future<CreateTransferResponse> createTransfer(DapiConnection connection) async {
  CreateTransferResponse result =
      await connection.createTransfer(null, getSandboxBeneficiary(), 2.0, null);
  print(result.accountID);
  return result;
}

Future<CreateTransferResponse> createTransferToExistingBeneficiary(
    DapiConnection connection) async {
  DapiBeneficiariesResponse beneficiariesResponse =
      await getBeneficiaries(connection);
  CreateTransferResponse result =
      await connection.createTransferToExistingBeneficiary(
          connection.accounts.first,
          beneficiariesResponse.beneficiaries!.first.id!,
          2.0,
          null);
  print(result.accountID);
  return result;
}

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

  return DapiBeneficiary(
      address: lineAddress,
      accountNumber: "1623404370879825504324",
      name: "name",
      bankName: "bankName",
      swiftCode: "DAPIBANK",
      iban: "DAPIBANKAEENBD1623404370879825504324",
      country: "UNITED ARAB EMIRATES",
      branchAddress: "branchAddress",
      branchName: "branchName",
      phoneNumber: "xxxxxxxxxxx");
}
1
likes
0
points
25
downloads

Publisher

verified publisherdapi.com

Weekly Downloads

Financial APIs to connect users' bank accounts.

Homepage

License

unknown (license)

Dependencies

flutter, intl

More

Packages that depend on dapi

Packages that implement dapi