Search in sources :

Example 6 with PersistenceException

use of net.petafuel.styx.core.persistence.PersistenceException in project styx by petafuel.

the class PersistentPayment method updateStatusById.

public static PaymentEntry updateStatusById(String id, TransactionStatus transactionStatus) {
    Connection connection = Persistence.getInstance().getConnection();
    PaymentEntry paymentEntry = null;
    try (PreparedStatement query = connection.prepareStatement("SELECT * FROM update_payment_status_by_id(?, ?)")) {
        query.setString(1, id);
        query.setString(2, 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_status_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)

Example 7 with PersistenceException

use of net.petafuel.styx.core.persistence.PersistenceException 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 8 with PersistenceException

use of net.petafuel.styx.core.persistence.PersistenceException 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 9 with PersistenceException

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

Example 10 with PersistenceException

use of net.petafuel.styx.core.persistence.PersistenceException in project styx by petafuel.

the class PersistentOAuthSession method update.

public static OAuthSession update(OAuthSession model) {
    Connection connection = Persistence.getInstance().getConnection();
    try (PreparedStatement query = connection.prepareStatement("SELECT * FROM update_oauth_session(?, ?, ?, ?, ?, ?)")) {
        query.setString(1, model.getAccessToken());
        query.setString(2, model.getTokenType());
        query.setString(3, model.getRefreshToken());
        query.setTimestamp(4, new Timestamp(model.getAccessTokenExpiresAt().getTime()));
        query.setTimestamp(5, new Timestamp(model.getRefreshTokenExpiresAt().getTime()));
        query.setString(6, model.getState());
        try (ResultSet resultSet = query.executeQuery()) {
            if (resultSet.next()) {
                return dbToModel(resultSet);
            }
        }
        throw new PersistenceException("No OAuthSession found for the given state");
    } catch (SQLException e) {
        logSQLError(e);
        throw new PersistenceException(e.getMessage(), e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PersistenceException(net.petafuel.styx.core.persistence.PersistenceException) PreparedStatement(java.sql.PreparedStatement) Timestamp(java.sql.Timestamp)

Aggregations

Connection (java.sql.Connection)11 PreparedStatement (java.sql.PreparedStatement)11 ResultSet (java.sql.ResultSet)11 SQLException (java.sql.SQLException)11 PersistenceException (net.petafuel.styx.core.persistence.PersistenceException)11 IntrospectionException (java.beans.IntrospectionException)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)10 AccessToken (net.petafuel.styx.core.persistence.models.AccessToken)9 PaymentEntry (net.petafuel.styx.core.persistence.models.PaymentEntry)9 Timestamp (java.sql.Timestamp)1 Aspsp (net.petafuel.styx.core.banklookup.sad.entities.Aspsp)1