Search in sources :

Example 11 with PaymentEntry

use of net.petafuel.styx.core.persistence.models.PaymentEntry in project styx by petafuel.

the class PersistentSinglePaymentIntegrationTest method deletePayment.

@Test
@Order(5)
void deletePayment() {
    PersistentPayment.deleteByPaymentId(paymentEntry.getPaymentId());
    PaymentEntry paymentEntryFromDatabase = PersistentPayment.getByPaymentId(paymentEntry.getPaymentId());
    Assert.assertNull(paymentEntryFromDatabase.getPaymentId());
    Assert.assertNull(paymentEntryFromDatabase.getBic());
    Assert.assertNull(paymentEntryFromDatabase.getClientToken());
    Assert.assertNull(paymentEntryFromDatabase.getStatus());
}
Also used : PaymentEntry(net.petafuel.styx.core.persistence.models.PaymentEntry) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Order(org.junit.jupiter.api.Order) Test(org.junit.jupiter.api.Test)

Example 12 with PaymentEntry

use of net.petafuel.styx.core.persistence.models.PaymentEntry 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)

Example 13 with PaymentEntry

use of net.petafuel.styx.core.persistence.models.PaymentEntry in project styx by petafuel.

the class PersistentPayment method create.

public static PaymentEntry create(String id, String paymentId, String clientToken, String bic, TransactionStatus status, PaymentService service, PaymentProduct product) {
    Connection connection = Persistence.getInstance().getConnection();
    PaymentEntry paymentEntry = null;
    try (PreparedStatement query = connection.prepareStatement("SELECT * FROM create_payment(?,?,?,?,?,?,?)")) {
        query.setString(1, id);
        query.setString(2, paymentId);
        query.setString(3, clientToken);
        query.setString(4, bic);
        query.setString(5, status.name());
        query.setString(6, service.name());
        query.setString(7, product.name());
        try (ResultSet resultSet = query.executeQuery()) {
            if (resultSet.next()) {
                paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
                AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
                paymentEntry.setClientToken(accessToken);
                paymentEntry.setStatus(TransactionStatus.valueOf(resultSet.getString(COLUMN_STATUS)));
                paymentEntry.setPaymentService(PaymentService.valueOf(resultSet.getString(COLUMN_SERVICE)));
                paymentEntry.setPaymentProduct(PaymentProduct.valueOf(resultSet.getString(COLUMN_PRODUCT)));
            }
        }
    } catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IntrospectionException e) {
        LOG.error(ERROR_MODEL_MAPPING, e.getMessage());
        throw new PersistenceException(e.getMessage(), e);
    } catch (SQLException e) {
        LOG.error("Error executing create_payment() for paymentId={} bic={} state={} message={}", paymentId, bic, e.getSQLState(), e.getMessage());
        throw new PersistenceException(e.getMessage(), e);
    }
    return paymentEntry;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) IntrospectionException(java.beans.IntrospectionException) PreparedStatement(java.sql.PreparedStatement) InvocationTargetException(java.lang.reflect.InvocationTargetException) AccessToken(net.petafuel.styx.core.persistence.models.AccessToken) PaymentEntry(net.petafuel.styx.core.persistence.models.PaymentEntry) ResultSet(java.sql.ResultSet) PersistenceException(net.petafuel.styx.core.persistence.PersistenceException)

Example 14 with PaymentEntry

use of net.petafuel.styx.core.persistence.models.PaymentEntry in project styx by petafuel.

the class PersistentPayment method updateByPaymentId.

public static PaymentEntry updateByPaymentId(String paymentId, String clientToken, String bic, TransactionStatus transactionStatus) {
    Connection connection = Persistence.getInstance().getConnection();
    PaymentEntry paymentEntry = null;
    try (PreparedStatement query = connection.prepareStatement("SELECT * FROM update_payment_by_payment_id(?, ?, ?, ?)")) {
        query.setString(1, paymentId);
        query.setString(2, clientToken);
        query.setString(3, bic);
        query.setString(4, transactionStatus.name());
        try (ResultSet resultSet = query.executeQuery()) {
            if (resultSet.next()) {
                paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
                AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
                paymentEntry.setClientToken(accessToken);
                paymentEntry.setStatus(TransactionStatus.valueOf(resultSet.getString(COLUMN_STATUS)));
                paymentEntry.setPaymentService(PaymentService.valueOf(resultSet.getString(COLUMN_SERVICE)));
                paymentEntry.setPaymentProduct(PaymentProduct.valueOf(resultSet.getString(COLUMN_PRODUCT)));
            }
        }
    } catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IntrospectionException e) {
        LOG.error(ERROR_MODEL_MAPPING, e.getMessage());
        throw new PersistenceException(e.getMessage(), e);
    } catch (SQLException e) {
        LOG.error("Error executing update_payment_by_payment_id() for paymentId={} bic={} state={} message={}", paymentId, bic, e.getSQLState(), e.getMessage());
        throw new PersistenceException(e.getMessage(), e);
    }
    return paymentEntry;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) IntrospectionException(java.beans.IntrospectionException) PreparedStatement(java.sql.PreparedStatement) InvocationTargetException(java.lang.reflect.InvocationTargetException) AccessToken(net.petafuel.styx.core.persistence.models.AccessToken) PaymentEntry(net.petafuel.styx.core.persistence.models.PaymentEntry) ResultSet(java.sql.ResultSet) PersistenceException(net.petafuel.styx.core.persistence.PersistenceException)

Example 15 with PaymentEntry

use of net.petafuel.styx.core.persistence.models.PaymentEntry in project styx by petafuel.

the class PersistentPayment method deleteById.

public static PaymentEntry deleteById(String id) {
    Connection connection = Persistence.getInstance().getConnection();
    PaymentEntry paymentEntry = null;
    try (PreparedStatement query = connection.prepareStatement("SELECT * FROM delete_payment_by_id(?)")) {
        query.setString(1, id);
        try (ResultSet resultSet = query.executeQuery()) {
            if (resultSet.next()) {
                paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
                AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
                paymentEntry.setClientToken(accessToken);
                paymentEntry.setStatus(TransactionStatus.valueOf(resultSet.getString(COLUMN_STATUS)));
                paymentEntry.setPaymentService(PaymentService.valueOf(resultSet.getString(COLUMN_SERVICE)));
                paymentEntry.setPaymentProduct(PaymentProduct.valueOf(resultSet.getString(COLUMN_PRODUCT)));
            }
        }
    } catch (InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException | IntrospectionException e) {
        LOG.error(ERROR_MODEL_MAPPING, e.getMessage());
        throw new PersistenceException(e.getMessage(), e);
    } catch (SQLException e) {
        LOG.error("Error executing delete_payment_by_id() for id={} state={} message={}", id, e.getSQLState(), e.getMessage());
        throw new PersistenceException(e.getMessage(), e);
    }
    return paymentEntry;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) IntrospectionException(java.beans.IntrospectionException) PreparedStatement(java.sql.PreparedStatement) InvocationTargetException(java.lang.reflect.InvocationTargetException) AccessToken(net.petafuel.styx.core.persistence.models.AccessToken) PaymentEntry(net.petafuel.styx.core.persistence.models.PaymentEntry) ResultSet(java.sql.ResultSet) PersistenceException(net.petafuel.styx.core.persistence.PersistenceException)

Aggregations

PaymentEntry (net.petafuel.styx.core.persistence.models.PaymentEntry)15 IntrospectionException (java.beans.IntrospectionException)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 Connection (java.sql.Connection)9 PreparedStatement (java.sql.PreparedStatement)9 ResultSet (java.sql.ResultSet)9 SQLException (java.sql.SQLException)9 PersistenceException (net.petafuel.styx.core.persistence.PersistenceException)9 AccessToken (net.petafuel.styx.core.persistence.models.AccessToken)9 Order (org.junit.jupiter.api.Order)4 Test (org.junit.jupiter.api.Test)4 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)4 RedirectStatus (net.petafuel.styx.api.v1.status.entity.RedirectStatus)1 XS2AStandard (net.petafuel.styx.core.banklookup.XS2AStandard)1 BankLookupFailedException (net.petafuel.styx.core.banklookup.exceptions.BankLookupFailedException)1 BankNotFoundException (net.petafuel.styx.core.banklookup.exceptions.BankNotFoundException)1 SAD (net.petafuel.styx.core.banklookup.sad.SAD)1 XS2AFactoryInput (net.petafuel.styx.core.xs2a.factory.XS2AFactoryInput)1 PaymentStatusPoll (net.petafuel.styx.keepalive.tasks.PaymentStatusPoll)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1