Skip to content

Instantly share code, notes, and snippets.

@ramanathanrv
Created November 29, 2018 10:02
Show Gist options
  • Save ramanathanrv/39d8672fd158c4b4818dfa6d420521ae to your computer and use it in GitHub Desktop.
Save ramanathanrv/39d8672fd158c4b4818dfa6d420521ae to your computer and use it in GitHub Desktop.
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