Search in sources :

Example 1 with XS2AFactoryException

use of net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException in project styx by petafuel.

the class SCARequestFactory method create.

@Override
public SCARequest create(Class<? extends SCARequest> providedRequest, XS2AFactoryInput factoryInput) {
    try {
        SCARequest scaRequest;
        if (factoryInput.getConsentId() == null && factoryInput.getConsent() == null) {
            Constructor<? extends SCARequest> constructor = providedRequest.getConstructor(PaymentService.class, PaymentProduct.class, String.class);
            scaRequest = constructor.newInstance(factoryInput.getPaymentService(), factoryInput.getPaymentProduct(), factoryInput.getPaymentId());
        } else {
            Constructor<? extends SCARequest> constructor = providedRequest.getConstructor(String.class);
            scaRequest = constructor.newInstance(factoryInput.getConsentId());
        }
        scaRequest.setAuthorisationId(factoryInput.getAuthorisationId());
        scaRequest.setScaAuthenticationData(factoryInput.getScaAuthenticationData());
        scaRequest.setAuthorisationMethodId(factoryInput.getAuthorisationMethodId());
        scaRequest.setPsuData(factoryInput.getPsuData());
        scaRequest.setPsu(factoryInput.getPsu());
        return scaRequest;
    } catch (NoSuchMethodException e) {
        throw new XS2AFactoryException(MessageFormat.format("No viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalAccessException e) {
        throw new XS2AFactoryException(MessageFormat.format("Unable to access constructor for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InstantiationException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request class is abstract, no viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InvocationTargetException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request constructor threw an exception for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalArgumentException e) {
        throw new XS2AFactoryException(MessageFormat.format("The constructor signature was invalid for this Factory for request={0} error={1}", providedRequest, e.getMessage()), e);
    }
}
Also used : XS2AFactoryException(net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException) SCARequest(net.petafuel.styx.core.xs2a.contracts.SCARequest) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with XS2AFactoryException

use of net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException in project styx by petafuel.

the class AISRequestFactory method create.

@Override
public AISRequest create(Class<? extends AISRequest> providedRequest, XS2AFactoryInput factoryInput) {
    try {
        Constructor<? extends AISRequest> constructor = providedRequest.getConstructor(Consent.class, String.class, String.class, String.class);
        AISRequest aisRequest = constructor.newInstance(factoryInput.getConsent(), factoryInput.getConsentId(), factoryInput.getAccountId(), factoryInput.getTransactionId());
        if (factoryInput.getAuthorisationId() != null) {
            aisRequest.setAuthorisationId(factoryInput.getAuthorisationId());
        }
        aisRequest.setPsu(factoryInput.getPsu());
        aisRequest.setBookingStatus(factoryInput.getBookingStatus());
        aisRequest.setDateFrom(factoryInput.getDateFrom());
        aisRequest.setDateTo(factoryInput.getDateTo());
        aisRequest.setWithBalance(factoryInput.getWithBalance());
        aisRequest.setEntryReferenceFrom(factoryInput.getEntryReferenceFrom());
        aisRequest.setDeltaList(factoryInput.getDeltaList());
        if (aisRequest instanceof CreateConsentRequest) {
            aisRequest.setTppRedirectUri(CallbackProvider.generateCallbackUrl(ServiceRealm.CONSENT, RealmParameter.OK, ThreadContext.get("requestUUID")));
            aisRequest.setTppNokRedirectUri(CallbackProvider.generateCallbackUrl(ServiceRealm.PAYMENT, RealmParameter.FAILED, ThreadContext.get("requestUUID")));
        }
        return aisRequest;
    } catch (NoSuchMethodException e) {
        throw new XS2AFactoryException(MessageFormat.format("No viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalAccessException e) {
        throw new XS2AFactoryException(MessageFormat.format("Unable to access constructor for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InstantiationException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request class is abstract, no viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InvocationTargetException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request constructor threw an exception for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalArgumentException e) {
        throw new XS2AFactoryException(MessageFormat.format("The constructor signature was invalid for this Factory for request={0} error={1}", providedRequest, e.getMessage()), e);
    }
}
Also used : XS2AFactoryException(net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException) AISRequest(net.petafuel.styx.core.xs2a.contracts.AISRequest) CreateConsentRequest(net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.CreateConsentRequest) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with XS2AFactoryException

use of net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException in project styx by petafuel.

the class PISRequestFactory method create.

/**
 * @param providedRequest should a request Class from XS2ARequestClassProvider
 * @param factoryInput    should contain all data necessary for object construction
 * @return the initialized PISRequest will be returned
 */
@Override
public PISRequest create(Class<? extends PISRequest> providedRequest, XS2AFactoryInput factoryInput) {
    try {
        Constructor<? extends PISRequest> constructor = providedRequest.getConstructor(PaymentService.class, PaymentProduct.class, PSU.class, InitializablePayment.class);
        PISRequest pisRequest = constructor.newInstance(factoryInput.getPaymentService(), factoryInput.getPaymentProduct(), factoryInput.getPsu(), factoryInput.getPayment());
        if (factoryInput.getAuthorisationId() != null) {
            pisRequest.setAuthorisationId(factoryInput.getAuthorisationId());
        }
        pisRequest.setPaymentId(factoryInput.getPaymentId());
        pisRequest.setTppRedirectUri(CallbackProvider.generateCallbackUrl(ServiceRealm.PAYMENT, RealmParameter.OK, ThreadContext.get("requestUUID")));
        pisRequest.setTppNokRedirectUri(CallbackProvider.generateCallbackUrl(ServiceRealm.PAYMENT, RealmParameter.FAILED, ThreadContext.get("requestUUID")));
        return pisRequest;
    } catch (NoSuchMethodException e) {
        throw new XS2AFactoryException(MessageFormat.format("No viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalAccessException e) {
        throw new XS2AFactoryException(MessageFormat.format("Unable to access constructor for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InstantiationException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request class is abstract, no viable constructor found for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (InvocationTargetException e) {
        throw new XS2AFactoryException(MessageFormat.format("Request constructor threw an exception for request={0} error={1}", providedRequest, e.getMessage()), e);
    } catch (IllegalArgumentException e) {
        throw new XS2AFactoryException(MessageFormat.format("The constructor signature was invalid for this Factory for request={0} error={1}", providedRequest, e.getMessage()), e);
    }
}
Also used : XS2AFactoryException(net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException) PISRequest(net.petafuel.styx.core.xs2a.contracts.PISRequest) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

InvocationTargetException (java.lang.reflect.InvocationTargetException)3 XS2AFactoryException (net.petafuel.styx.core.xs2a.exceptions.XS2AFactoryException)3 AISRequest (net.petafuel.styx.core.xs2a.contracts.AISRequest)1 PISRequest (net.petafuel.styx.core.xs2a.contracts.PISRequest)1 SCARequest (net.petafuel.styx.core.xs2a.contracts.SCARequest)1 CreateConsentRequest (net.petafuel.styx.core.xs2a.standards.berlingroup.v1_2.http.CreateConsentRequest)1