Search in sources :

Example 6 with PaymentEntry

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

the class PersistentPayment method getById.

public static PaymentEntry getById(String id) {
    Connection connection = Persistence.getInstance().getConnection();
    PaymentEntry paymentEntry = null;
    try (PreparedStatement query = connection.prepareStatement("SELECT * FROM get_payment_by_id(?)")) {
        query.setString(1, id);
        try (ResultSet resultSet = query.executeQuery()) {
            if (resultSet.next()) {
                paymentEntry = StyxifySQL.fetchModel(PaymentEntry.class, resultSet);
                if (resultSet.getString(COLUMN_CLIENT_TOKEN) != null) {
                    AccessToken accessToken = PersistentAccessToken.get(resultSet.getString(COLUMN_CLIENT_TOKEN));
                    paymentEntry.setClientToken(accessToken);
                }
                if (resultSet.getString(COLUMN_STATUS) != null) {
                    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 get_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 7 with PaymentEntry

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

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

the class PersistentSinglePaymentIntegrationTest method prepare.

@BeforeAll
public void prepare() {
    paymentEntry = new PaymentEntry();
    paymentId = UUID.randomUUID().toString();
    // TODO create accesstoken beforehand
    clientToken = Config.getInstance().getProperties().getProperty("test.token.access.pis");
    if (clientToken == null) {
        Assertions.fail("test.token.client.pis has to be set to a valid access token hash in the test resource for Core");
    }
    bic = "1231233D";
}
Also used : PaymentEntry(net.petafuel.styx.core.persistence.models.PaymentEntry) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 9 with PaymentEntry

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

the class PersistentSinglePaymentIntegrationTest method updatePayment.

@Test
@Order(3)
void updatePayment() {
    paymentEntry.setPaymentId(paymentId);
    paymentEntry.setStatus(TransactionStatus.ACCC);
    paymentEntry.setBic("DDDEEE123");
    PaymentEntry paymentEntryFromDatabase = PersistentPayment.updateByPaymentId(paymentEntry.getPaymentId(), paymentEntry.getClientToken().getId(), paymentEntry.getBic(), paymentEntry.getStatus());
    Assert.assertEquals(paymentEntry.getStatus(), paymentEntryFromDatabase.getStatus());
    Assert.assertEquals(paymentEntry.getBic(), paymentEntryFromDatabase.getBic());
    Assert.assertEquals(paymentEntry.getClientToken().getId(), paymentEntryFromDatabase.getClientToken().getId());
    Assert.assertEquals(paymentEntry.getPaymentId(), paymentEntryFromDatabase.getPaymentId());
}
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 10 with PaymentEntry

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

the class PersistentSinglePaymentIntegrationTest method updatePaymentStatus.

@Test
@Order(4)
void updatePaymentStatus() {
    paymentEntry.setStatus(TransactionStatus.ACWP);
    PaymentEntry paymentEntryFromDatabase = PersistentPayment.updateStatusByPaymentId(paymentEntry.getPaymentId(), paymentEntry.getStatus());
    Assert.assertEquals(paymentEntry.getStatus(), paymentEntryFromDatabase.getStatus());
    Assert.assertEquals(paymentEntry.getPaymentId(), paymentEntryFromDatabase.getPaymentId());
}
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)

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