Skip to content

Commit

Permalink
Changes as per review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
reshmabidikar committed Feb 10, 2023
1 parent de3f7ba commit cbd89e2
Showing 1 changed file with 94 additions and 86 deletions.
180 changes: 94 additions & 86 deletions src/main/java/org/killbill/billing/plugin/adyen/dao/AdyenDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.joda.time.DateTime;
import org.jooq.DSLContext;
import org.jooq.impl.DSL;
import org.jooq.types.ULong;
import org.killbill.billing.catalog.api.Currency;
import org.killbill.billing.payment.api.TransactionType;
import org.killbill.billing.payment.plugin.api.PaymentPluginStatus;
Expand Down Expand Up @@ -214,47 +213,51 @@ public AdyenResponsesRecord addResponse(

return execute(
dataSource.getConnection(),
new WithConnectionCallback<AdyenResponsesRecord>() {
@Override
public AdyenResponsesRecord withConnection(final Connection conn) throws SQLException {
final DSLContext dslContext = DSL.using(conn, dialect, settings);
dslContext
.insertInto(
ADYEN_RESPONSES,
ADYEN_RESPONSES.KB_ACCOUNT_ID,
ADYEN_RESPONSES.KB_PAYMENT_ID,
ADYEN_RESPONSES.KB_PAYMENT_TRANSACTION_ID,
ADYEN_RESPONSES.TRANSACTION_TYPE,
ADYEN_RESPONSES.TRANSACTION_STATUS,
ADYEN_RESPONSES.SESSION_ID,
ADYEN_RESPONSES.REFERENCE,
ADYEN_RESPONSES.AMOUNT,
ADYEN_RESPONSES.CURRENCY,
ADYEN_RESPONSES.ADDITIONAL_DATA,
ADYEN_RESPONSES.CREATED_DATE,
ADYEN_RESPONSES.KB_TENANT_ID)
.values(
kbAccountId.toString(),
kbPaymentId.toString(),
kbTransactionId.toString(),
transactionType.toString(),
status.toString(),
sessionId,
outputDTO.getSecondPaymentReferenceId(),
dbAmount,
dbCurrency,
outputDTO.getAdditionalData() != null
? (asString(outputDTO.getAdditionalData()))
: null,
toLocalDateTime(DateTime.now()),
tenantId.toString())
.execute();
conn ->
DSL.using(conn, dialect, settings)
.transactionResult(
configuration -> {
final DSLContext dslContext = DSL.using(conn, dialect, settings);
dslContext
.insertInto(
ADYEN_RESPONSES,
ADYEN_RESPONSES.KB_ACCOUNT_ID,
ADYEN_RESPONSES.KB_PAYMENT_ID,
ADYEN_RESPONSES.KB_PAYMENT_TRANSACTION_ID,
ADYEN_RESPONSES.TRANSACTION_TYPE,
ADYEN_RESPONSES.TRANSACTION_STATUS,
ADYEN_RESPONSES.SESSION_ID,
ADYEN_RESPONSES.REFERENCE,
ADYEN_RESPONSES.AMOUNT,
ADYEN_RESPONSES.CURRENCY,
ADYEN_RESPONSES.ADDITIONAL_DATA,
ADYEN_RESPONSES.CREATED_DATE,
ADYEN_RESPONSES.KB_TENANT_ID)
.values(
kbAccountId.toString(),
kbPaymentId.toString(),
kbTransactionId.toString(),
transactionType.toString(),
status.toString(),
sessionId,
outputDTO.getSecondPaymentReferenceId(),
dbAmount,
dbCurrency,
outputDTO.getAdditionalData() != null
? (asString(outputDTO.getAdditionalData()))
: null,
toLocalDateTime(DateTime.now()),
tenantId.toString())
.execute();

final long lastId = dslContext.lastID().longValue();
return dslContext.fetchOne(
ADYEN_RESPONSES, ADYEN_RESPONSES.RECORD_ID.eq(ULong.valueOf(lastId)));
}
});
return dslContext.fetchOne(
ADYEN_RESPONSES,
ADYEN_RESPONSES.RECORD_ID.eq(
ADYEN_RESPONSES
.RECORD_ID
.getDataType()
.convert(dslContext.lastID())));
}));
}

public AdyenNotificationsRecord addNotification(
Expand All @@ -277,51 +280,56 @@ public AdyenNotificationsRecord addNotification(
Short success = (short) (item.isSuccess() ? 1 : 0);
return execute(
dataSource.getConnection(),
new WithConnectionCallback<AdyenNotificationsRecord>() {
@Override
public AdyenNotificationsRecord withConnection(final Connection conn)
throws SQLException {
final DSLContext dslContext = DSL.using(conn, dialect, settings);
dslContext
.insertInto(
ADYEN_NOTIFICATIONS,
ADYEN_NOTIFICATIONS.KB_ACCOUNT_ID,
ADYEN_NOTIFICATIONS.KB_PAYMENT_ID,
ADYEN_NOTIFICATIONS.KB_PAYMENT_TRANSACTION_ID,
ADYEN_NOTIFICATIONS.SUCCESS,
ADYEN_NOTIFICATIONS.EVENT_CODE,
ADYEN_NOTIFICATIONS.MERCHANT_ACCOUNT_CODE,
ADYEN_NOTIFICATIONS.MERCHANT_REFERENCE,
ADYEN_NOTIFICATIONS.ORIGINAL_REFERENCE,
ADYEN_NOTIFICATIONS.REASON,
ADYEN_NOTIFICATIONS.PSP_REFERENCE,
ADYEN_NOTIFICATIONS.AMOUNT,
ADYEN_NOTIFICATIONS.CURRENCY,
ADYEN_NOTIFICATIONS.CREATED_DATE,
ADYEN_NOTIFICATIONS.ADDITIONAL_DATA,
ADYEN_NOTIFICATIONS.KB_TENANT_ID)
.values(
kbAccountId.toString(),
kbPaymentId.toString(),
kbTransactionId.toString(),
success,
item.getEventCode(),
item.getMerchantAccountCode(),
item.getMerchantReference(),
item.getOriginalReference(),
item.getReason(),
item.getPspReference(),
dbAmount,
dbCurrency,
toLocalDateTime(DateTime.now()),
item.getAdditionalData() != null ? (asString(item.getAdditionalData())) : null,
tenantId.toString())
.execute();
final long lastId = dslContext.lastID().longValue();
return dslContext.fetchOne(
ADYEN_NOTIFICATIONS, ADYEN_NOTIFICATIONS.RECORD_ID.eq(ULong.valueOf(lastId)));
}
});
conn ->
DSL.using(conn, dialect, settings)
.transactionResult(
configuration -> {
final DSLContext dslContext = DSL.using(conn, dialect, settings);
dslContext
.insertInto(
ADYEN_NOTIFICATIONS,
ADYEN_NOTIFICATIONS.KB_ACCOUNT_ID,
ADYEN_NOTIFICATIONS.KB_PAYMENT_ID,
ADYEN_NOTIFICATIONS.KB_PAYMENT_TRANSACTION_ID,
ADYEN_NOTIFICATIONS.SUCCESS,
ADYEN_NOTIFICATIONS.EVENT_CODE,
ADYEN_NOTIFICATIONS.MERCHANT_ACCOUNT_CODE,
ADYEN_NOTIFICATIONS.MERCHANT_REFERENCE,
ADYEN_NOTIFICATIONS.ORIGINAL_REFERENCE,
ADYEN_NOTIFICATIONS.REASON,
ADYEN_NOTIFICATIONS.PSP_REFERENCE,
ADYEN_NOTIFICATIONS.AMOUNT,
ADYEN_NOTIFICATIONS.CURRENCY,
ADYEN_NOTIFICATIONS.CREATED_DATE,
ADYEN_NOTIFICATIONS.ADDITIONAL_DATA,
ADYEN_NOTIFICATIONS.KB_TENANT_ID)
.values(
kbAccountId.toString(),
kbPaymentId.toString(),
kbTransactionId.toString(),
success,
item.getEventCode(),
item.getMerchantAccountCode(),
item.getMerchantReference(),
item.getOriginalReference(),
item.getReason(),
item.getPspReference(),
dbAmount,
dbCurrency,
toLocalDateTime(DateTime.now()),
item.getAdditionalData() != null
? (asString(item.getAdditionalData()))
: null,
tenantId.toString())
.execute();
return dslContext.fetchOne(
ADYEN_NOTIFICATIONS,
ADYEN_NOTIFICATIONS.RECORD_ID.eq(
ADYEN_RESPONSES
.RECORD_ID
.getDataType()
.convert(dslContext.lastID())));
}));
}

public AdyenResponsesRecord getSuccessfulPurchaseResponse(
Expand Down

0 comments on commit cbd89e2

Please sign in to comment.