デバイスバインディングを作成する
加盟店アプリはcreate bindingフローをトリガします
ステップ
説明
エンドユーザーの選択とOTP送信
ステップ
説明
OTP検証
ステップ
説明
最終更新
役に立ちましたか?
役に立ちましたか?
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) {
// idv 方法のリストを取得
List<IDVMethod> idvMethods = idvSession.getIdvMethods();
}
@Override
public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
// エラーをチェックするか再試行する
}
@Override
public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
// 生体認証を使用してデバイス認証を実行する
}
@Override
public void onSuccess() {
// create binding成功時のUIを処理する
}
@Override
public void onError(TMGClientException exception) {
// エラーがないか確認する
}
});
}// Mastercardフローに必要なプロパティを保持するシングルトンクラス
class MastercardService {
static var shared = MastercardService()
var idvSession: MastercardTAFHelper.IDVSession? = nil
var completionHandler: ((MastercardTAFHelper.IDVSession?, TMGError?) -> Void)? = nil
}
let tokenID: String = ""
let correlationID: String = ""
// create bindingを開始
mastercardTAFHelper.createBinding(forTokenID: tokenID, correlationID: correlationID,
idvSessionHandler: { idvSession in
// idvセッションをローカルに保持する
MastercardService.shared.idvSession = idvSession
// idv 方法のリスト
let methods = idvSession.idvMethods
// ユーザーにidv方法を表示する
},
deviceAuthenticationHandler: { auth in
// faceID
let customMessage = "" // カスタムメッセージを渡します。例: "Face IDで認証"
auth.startAuthentication(withMessage: customMessage)
},
completionHandler: { session, error in
// completion handler をローカルに保持する
MastercardService.shared.completionHandler?(session, error)
// バインディング成功
if error == nil {
}
// 失敗時はエラー処理またはidvセッションの再試行を行う
}
)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) {
// OTPを検証する
}
@Override
public void onIssuerAuthenticationRequired(IDVSession idvSession) {
// idv 方法のリストを取得
List<IDVMethod> idvMethods = idvSession.getIdvMethods();
// 選択したidv方法を送信する
IDVMethod selectedIdvMethod = idvMethods.get(0);
idvSession.selectIDVMethod(selectedIdvMethod);
}
@Override
public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
// エラーをチェックするか再試行する
}
@Override
public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
// 生体認証を使用してデバイス認証を実行する
}
@Override
public void onSuccess() {
// create binding成功時のUIを処理する
}
@Override
public void onError(TMGClientException exception) {
// エラーがないか確認する
}
});
}guard let idvSession = MastercardService.shared.idvSession else {
// idvセッションがない
return
}
// 1. idv方法の一覧を表示する
do {
let idvMethods = try idvSession.idvMethods
let selectedIdvMethod = idvMethods[0] // ユーザーは利用可能なidvMethodsの中から1つを選択
// 2. idv方法を送信する
idvSession.selectIDVMethod(selectedIdvMethod) {
// 3. OTP入力ページを表示する
}
} catch let error {
// エラーを処理する
}
// 4. ステップ2のselectIDVMethodの失敗はcompletionHandlerで処理されます。
MastercardService.shared.completionHandler = { (session, error) in
// 5. それがselectIDVMethodのエラーかどうかを確認する。
if let session = session,
let error = error,
error.description == TMGError.invalidIdvMethod.description {
MastercardService.shared.idvSession = session
// 6. IDVフローを再試行する。
}
}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) {
// バインディングを有効化する
String otp = "12345";
idvSession.validateOTP(otp);
}
@Override
public void onIssuerAuthenticationRequired(IDVSession idvSession) {
// idv 方法のリストを取得
}
@Override
public void onIssuerAuthenticationError(@NonNull IDVSession pendingBindingSession, TMGClientException tmgClientException) {
// エラーをチェックするか再試行する
}
@Override
public void onDeviceAuthentication(DeviceAuthentication deviceAuthentication) {
// 生体認証を使用してデバイス認証を実行する
CharSequence title = "title"; // 生体認証ポップアップに表示するタイトル。
CharSequence subTitle = "subTitle"; // 生体認証ポップアップに表示するサブタイトル。
CharSequence description = "description"; // 生体認証ポップアップに表示する説明。
CharSequence negativeButtonText = "negativeButtonText"; // 生体認証ポップアップに表示する否定ボタンのテキスト。
deviceAuthentication.startAuthentication(activity,
title,
subTitle,
description,
negativeButtonText);
}
@Override
public void onSuccess() {
// create binding成功時のUIを処理する
}
@Override
public void onError(TMGClientException exception) {
// エラーがないか確認する
}
});
}guard let idvSession = MastercardService.shared.idvSession else {
// idvセッションがない
return
}
do {
let otp = "123456" // ユーザーが入力したOTP値
// 1. otp値を送信する
idvSession.validateOTP(otp)
} catch let error {
// エラーを処理する
}
// 2. ステップ1のvalidateOTPの失敗はcompletionHandlerで処理されます。
MastercardService.shared.completionHandler = { (session, error) in
// 3. それがvalidateOTPのエラーかどうかを確認する。
if let session = session,
let error = error,
error.description == TMGError.invalidOTPMessage.description {
MastercardService.shared.idvSession = session
// 4. IDVフローを再試行する。
}
}