メッセージ処理
最終更新
役に立ちましたか?
役に立ちましたか?
public class D1PayFirebaseService extends FirebaseMessagingService {
private D1Task d1Task = null;
@Override
public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
if (d1Task == null) {
d1Task = new D1Task.Builder()
.setContext(getApplicationContext())
.build();
}
// if 3DS feature is enabled, create d1Authn instance before proccessing the pushNotification with the same d1Task instance that is used to 'processNotification'
// it is required to display prompt with an activity if it is a push that requests for d1Authn authentication
// Application interaction is required during the processing to display promts to end user.
D1Authn d1Authn = d1Task.getD1Authn(activity, new AuthnCallback(){
@Override
public void onTransactionDataConfirmation(@NunNull Map<String, String> map, @NonNull AuthnUserConfirmationCallback authnUserConfirmationCallback){
// The 'map' contains the transaction data that is to be authenticated.
// Application to display the content, prompt end uer either to 'proceed' or to 'deny' the authentication request.
// To proceed: when uer selects proceed
// once proceed, UI will be prompted for authentication based on the selected AuthnType enrolled.
authnUserConfirmationCallback.proceed();
// To cancel: when user selects cancel
authnUserConfirmationCallback.cancel();
}
@Override
public onBiometricPromptMessage(){
// Provide a message prompt for the authentication prompt. Application can customize the value.
return "Message to be displayed to the user during biometric prompt";
}
});
d1Task.processNotification(remoteMessage.getData(), new D1Task.Callback<String>() {
@Override
public void onSuccess(@Nullable String d1CardID) {
// Proceed with subsequent flows
}
@Override
public void onError(@NonNull D1Exception exception) {
// Refer to D1 SDK Integration – Error Management section
}
});
// Other application logic ...
}
// ...
}extension AppDelegate {
func application(
_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
) {
if let userInfo = userInfo as? [String: Any] {
d1Task.processNotification(userInfo) { response, error in
guard error == nil else {
// Refer to D1 SDK Integration – Error Management section.
completionHandler(.noData)
return
}
guard let response = response, let type = response[PushResponse.Key.messageType] else {
completionHandler(.noData)
return
}
guard type != PushResponse.typeUnknown else {
// The notification is not recognized by the SDK.
completionHandler(.noData)
return
}
guard type == PushResponse.typeMessaging,
let id = response[PushResponse.Key.messageID],
let message = Message.message(withID: id) else {
completionHandler(.noData)
return
}
let content = UNMutableNotificationContent()
// Constructs the notification based on message
content.title = message.title ?? "Notification"
content.body = message.message ?? ""
content.targetContentIdentifier = message.action.
// Shows the notification to the end user.
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { error in }
completionHandler(.newData)
}
} else {
completionHandler(.noData)
}
}
}