SDK Configurations
This guide explains the configuration methods for Dapi Android SDK and how to set environment, send data to your backend server and customize Dapi UI.
Dapi Configurations
You can use DapiConfigurations
to configure the SDK as follows.
val configurations = DapiConfigurations(
environment = DapiEnvironment.SANDBOX,
countries = arrayOf("US", "AE", "SA"),
extraHeaderFields = hashMapOf(Pair("key1", "value1"), Pair("key2", "value2")),
extraBody = hashMapOf(Pair("key1", "value1"), Pair("key2", "value2")),
postSuccessfulConnectionLoadingText = "Loading..",
showCloseButton = true,
showAddButton = false,
showTransferSuccessfulResult = true,
showTransferErrorResult = true,
language = DapiLanguage.EN,
theme = DapiThemeConfigurations(
enforceTheme = DapiTheme.DARK,
primaryColor = DapiColor(lightMode = "#610903", darkMode = "#cf1002")
)
)
HashMap<String, Object> extraBody = new HashMap<>();
extraBody.put("key1", "value1");
extraBody.put("key2", "value2");
HashMap<String, Object> extraQueryParameters = new HashMap<>();
extraQueryParameters.put("key1", "value1");
extraQueryParameters.put("key2", "value2");
HashMap<String, Object> extraHeaderFields = new HashMap<>();
extraHeaderFields.put("key1", "value1");
extraHeaderFields.put("key2", "value2");
DapiEnvironment environment = DapiEnvironment.SANDBOX;
String[] countries = new String[]{"US", "AE", "SA"};
boolean showLogos = true;
boolean showExperimentalBanks = false;
boolean showCloseButton = true;
boolean showAddButton = false;
String postSuccessfulConnectionLoadingText = "Loading..";
boolean showTransferSuccessfulResult = true;
boolean showTransferErrorResult = true;
DapiThemeConfigurations theme = new DapiThemeConfigurations(DapiTheme.DARK, new DapiColor("#610903", "#cf1002"));
DapiLanguage language = DapiLanguage.EN;
DapiConfigurations configurations = new DapiConfigurations(
extraBody,
extraQueryParameters,
extraHeaderFields,
environment,
countries,
showLogos,
showExperimentalBanks,
showCloseButton,
showAddButton,
postSuccessfulConnectionLoadingText,
showTransferSuccessfulResult,
showTransferErrorResult,
theme,
language
);
Configuration Parameters
Parameter | Description |
---|---|
environment | The running environment for Dapi. Set to DapiEnvironment.PRODUCTION for production release and DapiEnvironment.SANDBOX for testing. |
countries | Array of countries that you support, use the Alpha-2 country codes from COUNTRY CODES LIST |
extraHeaderFields | HashMap of header fields to send to any endpoint. |
extraQueryParameters | HashMap of query parameters to send to any endpoint. |
extraBody | HashMap of entries to include in any request under the key UserExtraBody .The extraBody will look like UserExtraBody:{Key1:"Value1", "Key2": "Value2"} included in the original request body. |
showCloseButton | Boolean that controls X button visibility on Connect. Set true to show X button, false otherwise. |
showAddButton | Boolean that controls Add button visibility on Accounts Screen. Set true to enable your users to open Connect from the Accounts Screen, false otherwise. |
postSuccessfulConnectionLoadingText | The text to show in the loader screen after a successful credentials input on Connect. |
showTransferSuccessfulResult | Boolean that controls the Result Screen visibility after a successful payment attempt using Dapi UI. Set true to show Result Screen, false otherwise. |
showTransferErrorResult | Boolean that controls the Result Screen visibility after a failed payment attempt using Dapi UI. Set true to show Result Screen, false otherwise. |
theme | DapiThemeConfiguration to configure the SDK UI theme.enforceTheme -> enforce a specific theme DapiTheme.LIGHT DapiTheme.DARK or device theme DapiTheme.DYNAMIC primaryColor -> your primary color for Light and Dark Modes in Hex format. |
language | The language of the SDK Supported languages: English DapiLanguage.EN , Arabic DapiLanguage.AR Default language: DapiLanguage.EN |
Start the SDK with your configurations
Open your Application class and add this code to your onCreate
method
val configurations = DapiConfigurations(
environment = DapiEnvironment.SANDBOX,
countries = arrayOf("US", "AE", "SA"),
extraHeaderFields = hashMapOf(Pair("key1", "value1"), Pair("key2", "value2")),
extraBody = hashMapOf(Pair("key1", "value1"), Pair("key2", "value2")),
postSuccessfulConnectionLoadingText = "Loading..",
showCloseButton = true,
showAddButton = false,
showTransferSuccessfulResult = true,
showTransferErrorResult = true,
language = DapiLanguage.EN,
theme = DapiThemeConfigurations(
enforceTheme = DapiTheme.DARK,
primaryColor = DapiColor(lightMode = "#610903", darkMode = "#cf1002")
)
)
Dapi.start(
application = this,
appKey = "<#app_key#>",
clientUserID ="<#client_user_id#>",
configurations = configurations,
onSuccess = {
},
onFailure = { error ->
}
)
HashMap<String, Object> extraBody = new HashMap<>();
extraBody.put("key1", "value1");
extraBody.put("key2", "value2");
HashMap<String, Object> extraQueryParameters = new HashMap<>();
extraQueryParameters.put("key1", "value1");
extraQueryParameters.put("key2", "value2");
HashMap<String, Object> extraHeaderFields = new HashMap<>();
extraHeaderFields.put("key1", "value1");
extraHeaderFields.put("key2", "value2");
DapiEnvironment environment = DapiEnvironment.SANDBOX;
String[] countries = new String[]{"US", "AE", "SA"};
boolean showLogos = true;
boolean showExperimentalBanks = false;
boolean showCloseButton = true;
boolean showAddButton = false;
String postSuccessfulConnectionLoadingText = "Loading..";
boolean showTransferSuccessfulResult = true;
boolean showTransferErrorResult = true;
DapiThemeConfigurations theme = new DapiThemeConfigurations(DapiTheme.DARK, new DapiColor("#610903", "#cf1002"));
DapiLanguage language = DapiLanguage.EN;
DapiConfigurations configurations = new DapiConfigurations(
extraBody,
extraQueryParameters,
extraHeaderFields,
environment,
countries,
showLogos,
showExperimentalBanks,
showCloseButton,
showAddButton,
postSuccessfulConnectionLoadingText,
showTransferSuccessfulResult,
showTransferErrorResult,
theme,
language
);
Dapi.start(
this,
"<#app_key#>",
"<#client_user_id#>",
configurations,
() -> {
//Success
return Unit.INSTANCE;
},
(error) -> {
//Error
return Unit.INSTANCE;
}
);
Note
ClientUserID
is used to distinguish between different users on the same device. The value for ClientUserID needs to be set by you. We recommend setting clientUserID to your actual user ID that you use to distinguish between users. You should update the clientUserID once the user logs out and another user logs in.
Modify the SDK configurations
You can modify the configurations after you've started the SDK successfully by accessing Dapi.configurations
to set your modifications
Dapi.configurations.environment = DapiEnvironment.PRODUCTION
Dapi.configurations.countries = arrayOf("EG", "JO")
Dapi.configurations.extraBody = hashMapOf(Pair("newKey1", "newValue1"), Pair("newKey2", "newValue2"))
Dapi.configurations.... = ...
Dapi.getConfigurations().setEnvironment(DapiEnvironment.PRODUCTION);
String[] countries = new String[]{"EG", "JO"};
Dapi.getConfigurations().setCountries(countries);
HashMap<String, Object> extraBody = new HashMap<>();
extraBody.put("newKey1", "newValue1");
extraBody.put("newKey2", "newValue2");
Dapi.getConfigurations().setExtraBody(extraBody);
//...
Enable Network Logging
Enable network logging to get full information on the requests happening inside the SDK.
- Open
AndroidManifest.xml
. - Add the following code.
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
.
.
.>
<!--enable logger-->
<meta-data
android:name="co.dapi.networkLoggingEnabled"
android:value="true" />
</application>
Updated 9 months ago