Integration

To integrate plugin to your app you have to add a dependency for plugin itself and a dependency for PCSDK.

1. Adding flutter plugin

In order to include a flutter plugin in your app, you are supposed to add the following lines to pubspec.yaml:

For PCSDK:

dependencies:
    pcsdk:
        git: https://repo.payconfirm.org/git/flutter/pcsdk-flutter.git

For PCSDKGost:

dependencies:
    pcsdk_gost: 
        git: https://repo.payconfirm.org/git/flutter/pcsdkgost-flutter.git

2. Adding PCSDK

To make the plugin work, you have to embed PCSDK for each platform separately.

iOS

In iOS project (usually in <your_project>/ios folder) add the new dependency to a Podfile:

For PCSDK:

target 'Runner' do

    ...

    pod 'PCSDKModule', :git => 'https://repo.payconfirm.org/git/ios/pcsdk.git'

    ...

end

For PCSDKGost:

target 'Runner' do
    use_frameworks! :linkage => :static
    ...

    pod 'PCSDKModule', :git => 'https://repo.payconfirm.org/git/ios/pcsdk-gost.git'

    ...

end

Android

In Android project (<your_project>/android folder) add the following maven repository to a root build.gradle:

For PCSDK:

allprojects {
    repositories {
        ...
        maven { url "https://repo.payconfirm.org/android/maven" }
    }
}

For PCSDKGost:

allprojects {
    repositories {
    ...
    // PC Libs
    maven { url "https://repo.paycontrol.org/android/maven" }
    // CryptoPro libs
    maven { url "https://repo.paycontrol.org/mydss/android/maven" }
   }

}

Then, add the dependency with the last PCSDK version into a module-level build.gradle:

For PCSDK:

// Dependency in your module-level build.gradle
implementation 'tech.paycon.sdk.v5:pcsdk:5.4.<LATEST_VERSION>'

For PCSDKGost:

dependencies {
implementation 'tech.paycon.sdk.v5:pcsdk-gost:6.0.414'
// CryptoPro libs
implementation 'ru.cryptopro.sdk:cspbase:5.0.49010-3'
implementation 'ru.cryptopro.sdk:jinitcsp:5.0.49010-3'
implementation 'ru.cryptopro.sdk:sharedlibrary:5.0.49010-3'
implementation 'ru.cryptopro.sdk:cspgui:5.0.49010-3'
implementation 'org.ini4j:ini4j:0.5.4'
} 

Initialization

PCSDK must be initialized before using. To initialize PC SDK library you just call PCSDK.initialize() method. Also, you may turn on SDK's logger providing the required log level.

// Импорт зависимостей
import 'package:pcsdk/pcsdk.dart';
import 'package:pcsdk/models/pcloggingoptions.dart';

...

// Выставление уровня логирования
await PCSDK.setLogLevel(PCLoggingOptions.debug + PCLoggingOptions.sensitive);
// Инициализация
await PCSDK.initialize();

User registration

User registration process contains followings steps:

  1. Getting personalization data from the PC Server (via QR, QR + activation code, JSON-value)
  2. Registering PC User on PC Server
  3. Store user's keys in internal storage for further using

The activation code could be delivered by other channel (SMS, Push Notifications)


import 'package:pcsdk/models/pcuser.dart';
import 'package:pcsdk/pcusersmanager.dart';

String userJSON = ... ; // String with user's data in JSON format

// Importing JSON info
PCUser user = await PCUsersManager.importUser(userJSON);

// Activating the user
if (await user.isActivated() == false) {
    await PCUsersManager.activate(user, activationCode);
}

// Registering
await PCUsersManager.register(user, deviceToken);

// Storing
await PCUsersManager.store(user, userName, passwordToStore);

After successfull registration you can use this user to confirm and decline transactions.


List<PCUser> users = await PCUsersManager.listUsers();
PCUser firstUser = users.first;

Transactions

Online Methods


// Getting the appropriate user.
// We are using the first stored user in this example
PCUser user = await PCUsersManager.listUsers().first;

// Getting the available transactions list for this user
List<String> transactionsIDs = await PCTransactionsManager.getTransactionsList(user);

// Getting transactions's data
// We are using the first transaction in the list in this example
PCTransaction transaction = await PCTransactionsManager.getTransaction(transactionsIDs.first, user);

// Transaction may contain the binary data
// It is necessary to download it before confirming or declining
if (transaction.hasBinaryData) {
    String? binaryDataURL = await transaction.getBinaryDataUrl();
    if (binaryDataURL == null) {
        await PCTransactionsManager.getTransactionBinaryData(transaction, user);
    }
}

// Providing password before processing
bool isReadyToSign = await user.isReadyToSign();
if (!isReadyToSign) {
     await PCUsersManager.submit(user, password);
}

// Confirming transaction
await PCTransactionsManager.sign([transaction], user);

// ... or declining transaction
await PCTransactionsManager.decline([transaction], user);

Offline Methods


// Getting the appropriate user.
// We are using the first stored user in this example
PCUser user = await PCUsersManager.listUsers().first;

String transactionJSON = ... ; // String with transaction's data in JSON format

// Importing a transaction from JSON
PCTransaction transaction = await PCTransactionsManager.importTransaction(transactionJSON);

// Providing password before processing
bool isReadyToSign = await user.isReadyToSign();
if (!isReadyToSign) {
     await PCUsersManager.submit(user, password);
}

// Confirming transaction
PCConfirmation confirmation = await PCTransactionsManager.signOffline(transaction, user);
// PCConfirmation contains a confirmationCode to complete confirmation process on the server

// ... or declining transaction
PCDeclination declination = await PCTransactionsManager.declineOffline(transaction, user);
// PCDeclination contains a declineCode to complete decline process on the server

Errors

There are two types of errors in SDK:

  • PC_ERROR: returning by SDK
  • PC_SERVER_ERROR: returning by PC server

PC_ERROR codes

Code Description
PC_ERROR_INTERNAL_ERROR Internal error
PC_ERROR_STORAGE_NOT_INITIALIZED Storage is not initialized
PC_ERROR_EMPTY_KEYS_CONTENT The user's source does not contain the key content
PC_ERROR_EMPTY_DEVICE_TOKEN The device token is not set
PC_ERROR_MISSING_INTERACTION_URL Interaction url is missing
PC_ERROR_MISSING_TRANSACTION_DATA Transaction's data is missing
PC_ERROR_MISSING_KAUTH Authorization data is missing
PC_ERROR_MISSING_REQUESTED_DATA Requested data is missing
PC_ERROR_EMPTY_PASSWORD Password is not set
PC_ERROR_EMPTY_NAME Name is not set
PC_ERROR_INVALID_ACTIVATION_CODE Activation code is invalid
PC_ERROR_INVALID_PASSWORD The password is invalid
PC_ERROR_PASSWORD_DOES_NOT_MATCH_CONDITIONS Provided password does not match the policy conditions
PC_ERROR_USER_IS_NOT_ACTIVATED The user is not activated
PC_ERROR_USER_IS_NOT_REGISTERED User is not registered
PC_ERROR_USER_IS_EXPIRED User is expired
PC_ERROR_USER_NOT_FOUND User is not found in the storage
PC_ERROR_BINARY_UNAVAILABLE This transaction does not contain a binary data
PC_ERROR_BINARY_REQUIRED Downloading transaction's binary data is required before confirmation or declining
PC_ERROR_UNABLE_TO_STORE_BINARY_DATA Unable to store the transaction's binary data
PC_ERROR_BINARY_DATA_IS_CORRUPTED Binary data is corrupted
PC_ERROR_API_IS_NOT_SUPPORTED This version of the SDK does not support the API version of the server
PC_ERROR_API_IS_UNDEFINED Interaction server api is undefined
PC_ERROR_UNSUPPORTED_KEY_VERSION This version of the key is unsupported
PC_ERROR_ENDPOINT_UNAVAILABLE Endpoint unavailable
PC_ERROR_SIGNING_ERROR An error occured during signing operation
PC_ERROR_INVALID_HANDLE Entering password is required
PC_ERROR_SCORING_UNAVAILABLE Scoring is unavailable for this user
PC_ERROR_AUTOSIGN_UNAVAILABLE Auto-signing is unavailable
PC_ERROR_INVALID_JSON JSON data is invalid
PC_ERROR_INVALID_QR QR code is invalid
PC_ERROR_EXT_AUTH_NOT_FOUND The extended authentication type is not registered for the user
PC_ERROR_REMOTE_UPDATE_DISABLED The remote update is not available for this user
PC_ERROR_LOGIN_SESSION_IS_EXPIRED Login session is expired
PC_ERROR_PROCESSING_ERROR Failed to process one or more transactions
PC_ERROR_EXTERNAL_KEYS_PROCESSOR_IS_REQUIRED External keys processor is required

PC_SERVER_ERROR codes

Code Description
PC_SERVER_ERROR_UNDEFINED Undefined error
PC_SERVER_ERROR_ATTEMPT_ID_IS_NULL Attempt ID not set
PC_SERVER_ERROR_AUTH_CODE_IS_NULL Authentication code is null
PC_SERVER_ERROR_AUTOSIGN_FAILED Transaction autoconfirm failed
PC_SERVER_ERROR_AUTOSIGN_NOT_ALLOWED Autoconfirm is not allowed
PC_SERVER_ERROR_AUTOSING_SIGNATURE_IS_INVALID Signature for autoconfirm is invalid
PC_SERVER_ERROR_BILL_DATE_CORRUPTED Billing date is corrupted
PC_SERVER_ERROR_BILL_REQUEST_ALREADY_PROCESSED Billing is closed for this date
PC_SERVER_ERROR_BILLING_TYPE_CORRUPTED Billing type corrupted in database
PC_SERVER_ERROR_CALLBACK_URL_IS_NULL Callback url is NULL
PC_SERVER_ERROR_COLLECTION_IS_EMPTY Collection is empty
PC_SERVER_ERROR_CONFIRM_CODE_IS_NULL Confrimation code is null
PC_SERVER_ERROR_CONFIRM_CODE_LENGTH_IS_WRONG Confirmation code length is not valid
PC_SERVER_ERROR_CONFIRM_TYPE_IS_NULL Confirm type is null
PC_SERVER_ERROR_CREATE_OPERATION_ERROR Create operation error
PC_SERVER_ERROR_DATA_TYPE_IS_WRONG Data type is wrong
PC_SERVER_ERROR_DECLINE_REASON_IS_NULL Decline reason is null
PC_SERVER_ERROR_DEVICE_ID_IS_NULL Device ID is null
PC_SERVER_ERROR_DEVICE_TYPE_IS_INCORRECT Device type is incorrect
PC_SERVER_ERROR_DEVICE_TYPE_IS_NULL Device type is null
PC_SERVER_ERROR_DS_STRUCT_ERROR Digital signature is corrupted
PC_SERVER_ERROR_DS_VERIFY_ERROR Digital signature is not valid
PC_SERVER_ERROR_ERROR_PARSE_REGISTER_SYSTEM_INFO Request is corrupted
PC_SERVER_ERROR_EXT_AUTH_FAILED Extended authentication failed
PC_SERVER_ERROR_EXT_AUTH_NEEDED Extended authentication needed
PC_SERVER_ERROR_EXT_AUTH_TEMPLATE_NOT_FOUND Extended authentication template not found
PC_SERVER_ERROR_EXT_AUTH_TYPE_NOT_SUPPORTED Extended authentication type not supported
PC_SERVER_ERROR_FLEXIBLE_LICENSE_ERROR Flexible license error
PC_SERVER_ERROR_FPRINT_IS_EMPTY Fingerprint is empty
PC_SERVER_ERROR_FPRINT_IS_NOT_EMPTY Fingerprint has not been set
PC_SERVER_ERROR_HIGH_SCORING_RISK_LEVEL Scoring risk level is very high
PC_SERVER_ERROR_HTTP_AUTH_CODE_INVALID HTTP Authorization failed
PC_SERVER_ERROR_INCORRECT_USER_TYPE User type is incorrect
PC_SERVER_ERROR_INVALID_HMAC HMAC is not valid
PC_SERVER_ERROR_INVALID_KDF Export param format is not valid
PC_SERVER_ERROR_INVALID_OTP OTP is not valid
PC_SERVER_ERROR_JAVA_INTERNAL_ERROR Internal Error
PC_SERVER_ERROR_JSON_REQUEST_INCORRECT JSON request is incorrect
PC_SERVER_ERROR_JSON_SCHEME_NOT_SUPPORTED JSON scheme not supported
PC_SERVER_ERROR_KEY_CONTAINER_ALIAS_IS_NULL Key alias is null
PC_SERVER_ERROR_KEY_CONTAINER_NOT_EXISTS Key container does not exist
PC_SERVER_ERROR_KEY_EXPIRED The key has been expired, to continue you should update the key
PC_SERVER_ERROR_KEY_INFO_NOT_FOUND User key not found
PC_SERVER_ERROR_LICENSE_ERROR License error
PC_SERVER_ERROR_LICENSE_EXPIRED License expired
PC_SERVER_ERROR_LICENSE_NOT_FOUND License not found
PC_SERVER_ERROR_LICENSE_UPDATE_ERROR License update error
PC_SERVER_ERROR_LICENSE_USER_COUNT_EXCEEDED Licensed users count exceeded
PC_SERVER_ERROR_NO_RESULT Empty result
PC_SERVER_ERROR_NOT_SUPPORTED Operation not supported
PC_SERVER_ERROR_OPERATION_EXPIRED Operation has been expired
PC_SERVER_ERROR_OPERATION_NOT_EXISTS Operation not exists
PC_SERVER_ERROR_OPERATION_STATUS_INVALID Operation status invalid
PC_SERVER_ERROR_OTP_IS_NOT_VALID OTP is not valid
PC_SERVER_ERROR_PIN_IS_EMPTY PIN is empty
PC_SERVER_ERROR_PIN_LENGTH_IS_WRONG PIN length is invalid
PC_SERVER_ERROR_PUBKEY_IS_EMPTY Public key is empty
PC_SERVER_ERROR_PUBKEY_IS_NOT_EMPTY Public key was already set
PC_SERVER_ERROR_PUSH_ID_IS_NULL PUSH ID is null
PC_SERVER_ERROR_PUSH_NOT_FOUND Device ID not found
PC_SERVER_ERROR_REMOTE_UPDATE_DISABLED Remote update disabled
PC_SERVER_ERROR_REMOTE_UPDATE_ERROR_BLOCK Remote update error, user was blocked
PC_SERVER_ERROR_REMOTE_UPDATE_ERROR Remote update error
PC_SERVER_ERROR_REPORT_TPL_IS_NULL Report template is null
PC_SERVER_ERROR_REQUEST_ERROR Request error
PC_SERVER_ERROR_REQUEST_SIGNATURE_NOT_VALID Requset digital signature invalid
PC_SERVER_ERROR_SCORING_FAILED Scoring failed
PC_SERVER_ERROR_SCORING_SETTINGS_IS_NULL Scoring settings not set
PC_SERVER_ERROR_SERVER_SCORING_SETTINGS_INCORRECT Scoring settings are invalid on the server
PC_SERVER_ERROR_SIGNATURE_AND_CONFIRM_CODE_ARE_NULL Signature or confirm code must be specified
PC_SERVER_ERROR_SIGNATURE_IS_INVALID Signature is invalid
PC_SERVER_ERROR_SIGNATURE_IS_NULL Signature is null
PC_SERVER_ERROR_SPART_LENGTH_IS_WRONG Second key part length is not valid
PC_SERVER_ERROR_STATUS_LIST_IS_EMPTY Transaction status list is empty
PC_SERVER_ERROR_STATUS_LIST_IS_INCORRECT Status list is incorrect
PC_SERVER_ERROR_STORE_TYPE_IS_NULL Key store type is null
PC_SERVER_ERROR_STORE_TYPE_IS_WRONG Key storage type is unsupported
PC_SERVER_ERROR_SYSTEM_ID_IS_NULL System ID is null
PC_SERVER_ERROR_SYSTEM_ID_IS_WRONG System ID is wrong
PC_SERVER_ERROR_SYSTEM_ID_NOT_UNIQUE System ID is not unique
PC_SERVER_ERROR_SYSTEM_IS_DELETED System has been deleted
PC_SERVER_ERROR_SYSTEM_NAME_IS_NULL System name is null
PC_SERVER_ERROR_SYSTEM_NOT_FOUND System not found
PC_SERVER_ERROR_SYSTEM_NOT_VALID System is not valid
PC_SERVER_ERROR_SYSTEM_PROPERTY_ERROR System property error
PC_SERVER_ERROR_SYSTEM_TYPE_IS_WRONG System type is not valid
PC_SERVER_ERROR_TRANSACTION_CHECKED Transaction is confirmed
PC_SERVER_ERROR_TRANSACTION_DATA_ERROR Transaction data error
PC_SERVER_ERROR_TRANSACTION_DATA_IS_NULL Transaction data is null
PC_SERVER_ERROR_TRANSACTION_DATA_TYPE_IS_NULL Transaction data type is null
PC_SERVER_ERROR_TRANSACTION_DATA_UID_ERROR Transaction data is corrupted (User ID does not match)
PC_SERVER_ERROR_TRANSACTION_EXPIRED Transaction expired
PC_SERVER_ERROR_TRANSACTION_ID_IS_NULL Transaction ID is null
PC_SERVER_ERROR_TRANSACTION_IS_DELETE Transaction is marked as deleted
PC_SERVER_ERROR_TRANSACTION_IS_NOT_IN_OPERATION Transaction is not in operation
PC_SERVER_ERROR_TRANSACTION_IS_NOT_UNIQUE Transaction is not unique
PC_SERVER_ERROR_TRANSACTION_IS_NULL Transaction is NULL
PC_SERVER_ERROR_TRANSACTION_STATUS_INVALID Invalid transaction status
PC_SERVER_ERROR_TRANSFER_STORAGE Unable to transfer data from old storage
PC_SERVER_ERROR_UNSUPPORTED_BILLING_TYPE Unsupported billing type
PC_SERVER_ERROR_USER_BILL_DATE_CORRUPTED User billing date is corrupted
PC_SERVER_ERROR_USER_ID_IS_NULL User ID is null
PC_SERVER_ERROR_USER_ID_PREF_IS_NULL User ID prefix is null
PC_SERVER_ERROR_USER_ID_PREF_TOO_LONG User ID Prefix is too long
PC_SERVER_ERROR_USER_IS_BLOCKED User is blocked
PC_SERVER_ERROR_USER_IS_DELETED User has been deleted
PC_SERVER_ERROR_USER_NOT_FOUND User not found
PC_SERVER_ERROR_VALID_DATE_EXPIRED Key has expired
PC_SERVER_ERROR_WRONG_AUTH_CODE Authentication code is invalid
PC_SERVER_ERROR_WRONG_SYSTEM_TYPE System type is not valid
PC_SERVER_ERROR_DN_IS_NULL Distinguished Name not set
PC_SERVER_ERROR_CERT_REQUEST_PARAMS_IS_NULL Certificate request params not set
PC_SERVER_ERROR_CERT_ISSUE_ERROR Certificate issuing error
PC_SERVER_ERROR_NO_CERT_REQUEST Certificate Request or Certificate is absent
PC_SERVER_ERROR_NO_CERT No certificate for this operation
PC_SERVER_ERROR_NO_PKI_SETTINGS_DEFINED No PKI settings defined in service configuration
PC_SERVER_ERROR_CAN_NOT_USE_CERTIFICATE_CHAIN Can not use one or more certificates in provided chain
PC_SERVER_ERROR_CERT_STATUS_INVALID Certificate status invalid for this operation
PC_SERVER_ERROR_CERT_REVOKE_ERROR Certificate revoking error
PC_SERVER_ERROR_KEY_INDEX_OBSOLETED This key is not longer relevant. It was re-emitted
PC_SERVER_ERROR_KEY_INDEX_WRONG Key index is wrong
PC_SERVER_ERROR_DEVICE_FINGERPRINT_MISMATCH The fingerprint of the device does not match the saved one
PC_SERVER_ERROR_KEY_NOT_ACTIVATED Key is not activated
PC_SERVER_ERROR_ACTIVATION_ATTEMPTS_EXCEEDED The number of activation attempts exceeded
PC_SERVER_ERROR_ACTIVATION_CODE_INCORRECT Activation code is incorrect
PC_SERVER_ERROR_PASSWORD_ATTEMPTS_EXCEEDED Password attempts exceeded
PC_SERVER_ERROR_PASSWORD_INCORRECT Password incorrect
PC_SERVER_ERROR_PASSWORD_NOT_SET Password not set
PC_SERVER_ERROR_CREDENTIALS_NOT_INITIALIZED Credentials not initialized

Changelog

1.0.1

  • Supporting of offline transactions

1.0.0

  • Initial release with common functional