Search in sources :

Example 6 with BankLookupFailedException

use of net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException in project styx by petafuel.

the class OAuthCallbackProcessor method handlePaymentRealm.

private static RedirectStatus handlePaymentRealm(ServiceRealm serviceRealm, RealmParameter realmParameter, String identifier, OAuthCallback oAuthCallback) {
    String path = String.format("%s/%s/%s", serviceRealm.name().toLowerCase(), realmParameter.name().toLowerCase(), identifier);
    if (oAuthCallback.getError() == null && handleSuccessfulOAuth2(oAuthCallback.getCode(), oAuthCallback.getState(), path)) {
        PaymentEntry paymentEntry = PersistentPayment.getById(identifier);
        XS2AStandard xs2AStandard;
        try {
            xs2AStandard = (new SAD()).getBankByBIC(paymentEntry.getBic());
        } catch (BankNotFoundException | BankLookupFailedException e) {
            LOG.error("OAuth Callback on serviceRealm={}, identifier={}, realmParameter={} failed due to SAD not being able to initialize the aspsp connected to the payment SCA", serviceRealm, identifier, realmParameter, e);
            return new RedirectStatus(StatusType.ERROR, identifier);
        }
        // In case of oauth we will not schedule the task during payment initiation but here after we received a callback
        XS2AFactoryInput xs2AFactoryInput = new XS2AFactoryInput();
        xs2AFactoryInput.setPaymentId(paymentEntry.getPaymentId());
        xs2AFactoryInput.setPaymentService(paymentEntry.getPaymentService());
        xs2AFactoryInput.setPaymentProduct(paymentEntry.getPaymentProduct());
        ThreadManager.getInstance().queueTask(new PaymentStatusPoll(xs2AFactoryInput, xs2AStandard.getAspsp().getBic(), UUID.fromString(paymentEntry.getId())));
        return new RedirectStatus(StatusType.SUCCESS, oAuthCallback.getState());
    } else {
        LOG.error(FAILED_OAUTH2, oAuthCallback.getError(), oAuthCallback.getErrorDescription(), oAuthCallback.getState());
        return new RedirectStatus(StatusType.ERROR, oAuthCallback.getState());
    }
}
Also used : XS2AStandard(net.petafuel.styx.core.banklookup.XS2AStandard) RedirectStatus(net.petafuel.styx.api.v1.status.entity.RedirectStatus) PaymentEntry(net.petafuel.styx.core.persistence.models.PaymentEntry) SAD(net.petafuel.styx.core.banklookup.sad.SAD) XS2AFactoryInput(net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput) PaymentStatusPoll(net.petafuel.styx.keepalive.tasks.PaymentStatusPoll) BankLookupFailedException(net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException) BankNotFoundException(net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)

Aggregations

BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)6 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)6 SAD (net.petafuel.styx.core.banklookup.sad.SAD)4 Aspsp (net.petafuel.styx.core.banklookup.sad.entities.Aspsp)4 XS2AStandard (net.petafuel.styx.core.banklookup.XS2AStandard)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 Stream (java.util.stream.Stream)2 Persistence (net.petafuel.styx.core.persistence.Persistence)2 PersistentSAD (net.petafuel.styx.core.persistence.layers.PersistentSAD)2 Assert (org.junit.Assert)2 Assertions (org.junit.jupiter.api.Assertions)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Tag (org.junit.jupiter.api.Tag)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Arguments (org.junit.jupiter.params.provider.Arguments)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1