Skip to content

Instantly share code, notes, and snippets.

@ramanathanrv
Created Nov 29, 2018
Embed
What would you like to do?
frp implementation sample
public Observable triggerChallenge(final SecondFactor secondFactor) {
def handleSuccess = {resJson->
log.info("Challenge triggered successfully")
secondFactor.status = SecondFactor.SecondFactorStatus.PENDING
return secondFactor
}
def handleFailure = {resJson->
log.info("Challenge trigger failed")
secondFactor.status = SecondFactor.SecondFactorStatus.FAIL
// changing txnDetail here is a contamination.
// Instead failure reason must be recorded in the second factor object
secondFactor.txnDetail.bankErrorMessage = resJson.resDesc?:resJson.errorMessages
secondFactor.txnDetail.bankErrorCode = resJson.resCode
secondFactor.txnDetail.errorMessage = txnDetail.bankErrorMessage
return secondFactor
}
Observable<SecondFactor> challengeObservable = Observable.just(secondFactor)
.map({sf ->
assembleChallengeTriggerParams(sf)
})
.map({params->
makeJsonHttpCallWithMetrics(secondFactor, DirectAcsRouteInterface.Operation.TRIGGER_CHALLENGE,
(params as JSON).toString(),
[method: "POST", contentType : "application/json", sslProtocol: "TLSv1.2",
connectTimeout: 5000, readTimeout: 5000])
})
.doOnError({err->
// we have hit an error in the network call
log.error("Error while trying to trigger challenge: ${err.message}")
// return Observable.<SecondFactor>error(err)
handleFailure([errorMessages: "ACS server invocation failure"])
return Observable.<SecondFactor>error(err)
})
.filter({resJson-> verifyTriggerChallengeResponse(secondFactor, resJson) })
.map({resJson->
secondFactor.epgTxnId = resJson.acsTxnId
return isSuccessful(resJson) ? handleSuccess(resJson) : handleFailure(resJson)
})
return challengeObservable
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment