# Kyc Flutter Guide

Kyc Plugin


# Install
## IOS

infor.plist

```
<key>NSCameraUsageDescription</key>
<string>Camera permission</string>
<key>NFCReaderUsageDescription</key>
<string>NFC permission</string>
<key>com.apple.developer.nfc.readersession.iso7816.select-identifiers</key>
<array>
  <string>00000000000000</string>
  <string>A0000002471001</string>
  <string>A0000002472001</string>
</array>
```

podfile

```
post_install do |installer|
  installer.pods_project.targets.each do |target|
    if ["Alamofire", "CryptoSwift", "SnapKit", "lottie-ios", "KeychainSwift", "ObjectMapper"].include? "#{target}"
      target.build_configurations.each do |config|
        config.build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES"
      end
    end
    if ["Alamofire", "KeychainSwift", "ObjectMapper"].include? "#{target}"
      target.build_configurations.each do |config|
        deployment_target = config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"]
        if !deployment_target.nil? || !deployment_target.empty? || deployment_target.to_f < 12.0
          config.build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = "12.0" 
        end
      end
    end
  end
end
```

## ANDROID

add permission in AndroidManifest.xml:
```
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.NFC" />

    <uses-feature
        android:name="android.hardware.camera"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.nfc"
        android:required="false" />

```
<aside>
⚠️ *`minSdkVersion` = 24

</aside>

Trong build.gradle (project) thêm các cấu hình như sau

```groovy
allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://maven.google.com" }
        maven { url "https://jitpack.io" }
        maven {
            url = uri("https://maven.pkg.github.com/pvcbdigibank/SDK-KYC-v2-ANDROID")
            credentials {
                username = ""
                password = "<Access Key>"
            }
        }
    }
}
```
### Init
```dart
  final kyc = Kyc();

void _setupEventListener() {
  kyc.eventStream.listen(
            (event) {

    },
    onError: (error) {

    },
  );
}

```
### Open a bank account
Open an account instantly with just your phone number and email
```dart
Future<void> _startEKyc(email, phone, editable, requireEmail) async {
  setState(
        () {
      kycStatus = "Starting KYC...";
    },
  );
  try {
    KycConfig config = KycConfig(
        env: Environment.PROD,
        debug: true,
        appCode: "ONBOARD",
        appId: "ONBOARD",
        partnerUserId: "partner.user.id",
        email: email,
        phone: phone,
        requireEmail: requireEmail);
    await pvcomBankKyc.eKyc(config);
  } catch (e) {
    setState(() {
      kycStatus = "Error starting KYC: $e";
    });
  }
}
```
### trustData
Share data into create all services
```dart
Future<void> _trustData() async {
  setState(() {
    kycStatus = "Starting KYC Liveness...";
  });
  try {
    KycConfig config = KycConfig(
        env: Environment.UAT,
        debug: true,
        appCode: "ONBOARD",
        appId: "ONBOARD",
        partnerUserId: "partner.user.id",
        email: email,
        phone: phone,
        trustDataConfirm: urlConfirm);
    await pvcomBankKyc.eKycTrustData(config);
  } catch (e) {
    setState(() {
      kycStatus = "Error starting KYC Liveness: $e";
    });
  }
}
```
### trustDataV2
Share data but do not create pvconnect
```dart
Future<void> _trustDataV2() async {
  setState(() {
    kycStatus = "Starting KYC by Data...";
  });
  try {
    KycConfig config = KycConfig(
      env: Environment.PROD,
      debug: true,
      appCode: "ONBOARD",
      appId: "ONBOARD",
      partnerUserId: "partner.user.id",
      email: email,
      phone: phone,
    );
    await pvcomBankKyc.eKycTrustDataV2(config);
  } catch (e) {
    setState(() {
      kycStatus = "Error starting KYC by Data: $e";
    });
  }
}
```

### Callback
```dart
void _setupEventListener() {
  pvcomBankKyc.eventStream.listen(
        (event) {
      print('Kyc received event: $event');
      if (event is Map<String, dynamic>) {
        //TODO: Your code here
      }
    },
    onError: (error) {
      print('Kyc error: $error');
      setState(() {
        kycStatus = "Error: $error";
      });
    },
  );
}
```