Skip to content

Instantly share code, notes, and snippets.

Created November 29, 2018 10:02
What would you like to do?
frp implementation sample
public Observable triggerChallenge(final SecondFactor secondFactor) {
def handleSuccess = {resJson->"Challenge triggered successfully")
secondFactor.status = SecondFactor.SecondFactorStatus.PENDING
return secondFactor
def handleFailure = {resJson->"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 ->
makeJsonHttpCallWithMetrics(secondFactor, DirectAcsRouteInterface.Operation.TRIGGER_CHALLENGE,
(params as JSON).toString(),
[method: "POST", contentType : "application/json", sslProtocol: "TLSv1.2",
connectTimeout: 5000, readTimeout: 5000])
// 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) })
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