Customer Journey
CustomerJourney has seen changes that will increase its customisability by introducing the ability to inject custom Fragments into the flow of the journey. Fragments can now be displayed before a RequiredAction and during an uploading task. This carries the intention of allowing custom information and loading screens to be displayed before each step of the journey and during each upload task. Making CustomerJourney become an option for customers that previously had to implement DocumentScanner and Liveness themselves..
Components
To display custom Fragments in CustomerJourney you must be aware of the following items:
- CustomerJourneyNavigator – An interface that must be implemented. Alerts you to when a Fragment before a specified RequiredAction will be displayed.
- CustomerJourneyFragment – A Fragment that must be extended. Fragments extending this Fragment should be returned by the CustomJourneyNavigator.actionBefore() method
- CustomerJourneyLoadingFragment – A Fragment that must be extended. Fragments extending this Fragment should be returned by the CustomJourneyNavigator.onUploadStarted() method
Building a Custom Fragment
Building a custom Fragment for CustomerJourney is simple. The only differences from building a normal fragment are that:
- You must extend CustomerJourneyFragment
- You are responsible for notifying CustomerJourney when to remove the Fragment by calling finish().
- You must override the TAG variable and set a unique String
Kotlin
class
CustomerJourneyFragmentSample : CustomerJourneyFragment() {
//set a unique tag here
override var TAG = "CustomerJourneyFragmentSample"
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return
inflater.inflate(R.layout.fragment_customer_journey_sample, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
//button that calls finish
button.setOnClickListener { finish() }
}
}
Java
public
class
CustomerJourneyFragmentSample extends
CustomerJourneyFragment {
private
Button button;
@Nullable
@Override
public
View onCreateView(@NonNull
LayoutInflater
inflater, @Nullable
ViewGroup container, @Nullable
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_customer_journey_sample, container, false);
view.findViewById(R.id.button);
return
view;
}
@Override
public
void
onActivityCreated(@Nullable
Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
button.setOnClickListener(new
View.OnClickListener() {
@Override
public
void
onClick(View v) {
finish();
}
});
}
@NotNull
@Override
public
String getTAG() { //set a unique tag here
return
"CustomerJourneyFragmentSample";
}
@Override
public
void
setTAG(@NotNull
String TAG) {
//no operation
}
}
Building a Custom Loading Fragment
To build a custom Loading Fragment for CustomerJourney you must be aware of the following:
- You must extend CustomerJourneyLoadingFragment
- You are notified when the Fragment is ready to be removed. You can either let the fragment be removed automatically or decide when to remove it yourself and call finish().
- You must override the TAG variable and set a unique String
- You are responsible for handling errors by either retrying the failed action or cancelling the journey. This can be done by either calling retry() or cancel()
Kotlin
class CustomerJourneyLoadingFragmentSample : CustomerJourneyLoadingFragment() {
override var TAG = "CustomerJourneyLoadingFragmentSample"
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_customer_journey_loading_sample, container, false)
}
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
textViewCustomerJourneyLoadingFragmentSampleTitle.setText(R.string.customer_journey_sample_uploading_fragment)
buttonCustomerJourneyFragmentSampleRetry.setOnClickListener { retry(); setButtonVisibility(View.GONE) } // retry the previous action
buttonCustomerJourneyFragmentSampleCancel.setOnClickListener { cancel(); setButtonVisibility(View.GONE) } // cancel the journey
}
override fun onError(code: Int, message: String) {
//display the error message to the user and make retry and cancel buttons visible
setButtonVisibility(View.VISIBLE)
progressBarCustomerJourneyLoadingFragmentSample?.visibility = View.GONE
textViewCustomerJourneyLoadingFragmentSampleTitle?.text = "Error Code: $code\nMessage: $message"
}
override fun onUploadFinished(): Boolean {
super.onUploadFinished()
//... anything you want to do after the upload has finished
return false // if you do not want the fragment to be removed immediately after this method then return true. finish() must be called to remove the fragment
}
private fun setButtonVisibility(visibility : Int) {
buttonCustomerJourneyFragmentSampleRetry?.visibility = visibility
buttonCustomerJourneyFragmentSampleCancel?.visibility = visibility
}
}
Building the Navigator
To build a navigator you must create a class then implement the CustomerJourneyNavigator interface. This will add the following methods to your class:
- actionBefore(action : Action) – This method is called by CustomerJourney and returns a CustomerJourneyFragment. It passes the next RequiredAction as an argument. This will tell you which fragment to return so it can be displayed.
- onUploadStarted() – This method is called by CustomerJourney when an uploading task has started and returns CustomerJourneyLoadingFragment. You can return your custom loading Fragment here.
kotlin
class Navigator : CustomerJourneyNavigator {
override fun actionBefore(action: Action): CustomerJourneyFragment? {
return when (action) { //return the correct fragment depending on the action
is FrontSide -> CustomerJourneyFragmentSample("BEFORE FRONT SIDE")
is BackSide -> ...
is Selfie -> ...
is Liveness -> ...
is AddressDocument -> ...
is NfcScan -> ...
else -> return null // CustomerJourney continues as normal when null is returned
}
}
override fun onUploadStarted(): CustomerJourneyLoadingFragment? {
return CustomerJourneyLoadingFragmentSample() //return loading fragment... CustomerJourney continues as normal when null is returned
}
}
Starting CustomerJourney
After all the individual components have been built. The CustomerJourneyNavigator can be passed into the CustomerJourneyActivity.
Kotlin
CustomerJourneyActivity.startActivity(this, config, Navigator())
Java
CustomerJourneyActivity.startActivity(this,config,new
Navigator())
Customer Journey Config
Creating a CustomerJourneyConfig
Kotlin
val config = CustomerJourneyConfig.Builder(baseUrl,
Credentials(username, password)).setCertificates(emptyList())
.setJourneyDefinitionId(journeyDefinitionGUID)
.setCropConfig(cropType)
.setQualityCheckConfig(qualityCheckConfig)
.build()
Java
CustomerJourney.Builder config = new CustomerJourneyConfig.Builder(baseUrl,
Credentials(username, password)).setCertificates(emptyList())
.setJourneyDefinitionId(journeyDefinitionGUID)
.setCropConfig(cropType)
.setQualityCheckConfig(qualityCheckConfig)
.build()
Quality Checks
Previously disabling quality checks in CustomerJourney was not possible in this version we have added QualityCheckConfig that can be set on the CustomerJourneyConfig.Builder.
Kotlin
val qualityCheckConfig = QualityCheckConfig(false,false,false,false)
Java
QualityCheckConfig qualityCheckConfig = new
QualityCheckConfig(false,false,false,false);
The qualityCheckConfig can then be set in the CustomerJourneyConfig.Builder as shown in the example above.