Create device binding
Last updated
Was this helpful?
Was this helpful?
public void createBinding(@NonNull MastercardTAFHelper mastercardTAFHelper, @NonNull String tokenID, @NonNull String correlationID) {
mastercardTAFHelper.createBinding(tokenID,
correlationID,
new TokenBindingListener() {
@Override
public void onIssuerAuthenticationReady(@NonNull IDVSession idvSession) {
}
@Override
public void onIssuerAuthenticationRequired(IDVSession idvSession) {
// Get list of idv methods
List<IDVMethod> idvMethods = idvSession.getIdvMethods();
}
@Override
public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
// Check the error or retry
}
@Override
public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
// Perform device authentication using biometric
}
@Override
public void onSuccess() {
// Handle UI of create binding success
}
@Override
public void onError(TMGClientException exception) {
// Check if there's any error
}
});
}// The singleton class to hold required properties for the Mastercard flow
class MastercardService {
static var shared = MastercardService()
var idvSession: MastercardTAFHelper.IDVSession? = nil
var completionHandler: ((MastercardTAFHelper.IDVSession?, TMGError?) -> Void)? = nil
}
let tokenID: String = ""
let correlationID: String = ""
// Start create binding
mastercardTAFHelper.createBinding(forTokenID: tokenID, correlationID: correlationID,
idvSessionHandler: { idvSession in
// hold the idv session locally
MastercardService.shared.idvSession = idvSession
// List of idv methods
let methods = idvSession.idvMethods
// Display idv methods to the user
},
deviceAuthenticationHandler: { auth in
// faceID
let customMessage = "" // Pass in the custom message. e.g: "Authenticate with Face ID"
auth.startAuthentication(withMessage: customMessage)
},
completionHandler: { session, error in
// hold the completion handler locally
MastercardService.shared.completionHandler?(session, error)
// binding successful
if error == nil {
}
// Handle error or retry idv session when there is a failure
}
)public void selectIDVMethod(@NonNull MastercardTAFHelper mastercardTAFHelper, @NonNull String tokenID, @NonNull String correlationID, @NonNull FragmentActivity activity) {
mastercardTAFHelper.createBinding(tokenID,
correlationID,
new TokenBindingListener() {
@Override
public void onIssuerAuthenticationReady(@NonNull IDVSession idvSession) {
// validate OTP
}
@Override
public void onIssuerAuthenticationRequired(IDVSession idvSession) {
// Get list of idv methods
List<IDVMethod> idvMethods = idvSession.getIdvMethods();
// Submit selected idv method
IDVMethod selectedIdvMethod = idvMethods.get(0);
idvSession.selectIDVMethod(selectedIdvMethod);
}
@Override
public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
// Check the error or retry
}
@Override
public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
// Perform device authentication using biometric
}
@Override
public void onSuccess() {
// Handle UI of create binding success
}
@Override
public void onError(TMGClientException exception) {
// Check if there's any error
}
});
}guard let idvSession = MastercardService.shared.idvSession else {
// no idv session
return
}
// 1. Display list of idv methods
do {
let idvMethods = try idvSession.idvMethods
let selectedIdvMethod = idvMethods[0] // user select 1 of the idvMethods available
// 2. submit the idv method
idvSession.selectIDVMethod(selectedIdvMethod) {
// 3. display page to enter OTP value
}
} catch let error {
// handle error
}
// 4. Failure in step 2, selectIDVMethod, will be handled in completionHandler.
MastercardService.shared.completionHandler = { (session, error) in
// 5. Check if it is a selectIDVMethod error.
if let session = session,
let error = error,
error.description == TMGError.invalidIdvMethod.description {
MastercardService.shared.idvSession = session
// 6. Retry the IDV flow.
}
}public void validateOTP(@NonNull MastercardTAFHelper mastercardTAFHelper, @NonNull String tokenID, @NonNull String correlationID, @NonNull FragmentActivity activity) {
mastercardTAFHelper.createBinding(tokenID,
correlationID,
new TokenBindingListener() {
@Override
public void onIssuerAuthenticationReady(@NonNull IDVSession idvSession) {
// Activate binding
String otp = "12345";
idvSession.validateOTP(otp);
}
@Override
public void onIssuerAuthenticationRequired(IDVSession idvSession) {
// Get list of idv methods
}
@Override
public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
// Check the error or retry
}
@Override
public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
// Perform device authentication using biometric
CharSequence title = "title"; //title to be displayed in Biometric authentication popup.
CharSequence subTitle = "subTitle"; //subTitle to be displayed in Biometric authentication popup.
CharSequence description = "description"; // description to be displayed in Biometric authentication popup.
CharSequence negativeButtonText = "negativeButtonText"; // text of the negative button to be displayed in Biometric authentication popup.
deviceAuthentication.startAuthentication(activity,
title,
subTitle,
description,
negativeButtonText);
}
@Override
public void onSuccess() {
// Handle UI of create binding success
}
@Override
public void onError(TMGClientException exception) {
// Check if there's any error
}
});
}guard let idvSession = MastercardService.shared.idvSession else {
// no idv session
return
}
do {
let otp = "123456" // user entered OTP value
// 1. submit otp value
idvSession.validateOTP(otp)
} catch let error {
// handle error
}
// 2. Failure in step 1, validateOTP, will be handled in completionHandler.
MastercardService.shared.completionHandler = { (session, error) in
// 3. Check if it is a validateOTP error.
if let session = session,
let error = error,
error.description == TMGError.invalidOTPMessage.description {
MastercardService.shared.idvSession = session
// 4. Retry the IDV flow.
}
}