use of org.killbill.billing.payment.dao.PaymentModelDao in project killbill by killbill.
the class TestDefaultAdminPaymentApi method testFixPaymentTransactionStateNoPaymentTransactionInfoPlugin.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/551")
public void testFixPaymentTransactionStateNoPaymentTransactionInfoPlugin() throws PaymentApiException {
final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, BigDecimal.TEN, Currency.EUR, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext);
final PaymentModelDao paymentModelDao = paymentDao.getPayment(payment.getId(), internalCallContext);
final PaymentTransactionModelDao paymentTransactionModelDao = paymentDao.getPaymentTransaction(payment.getTransactions().get(0).getId(), internalCallContext);
Assert.assertEquals(paymentModelDao.getStateName(), "AUTH_SUCCESS");
Assert.assertEquals(paymentModelDao.getLastSuccessStateName(), "AUTH_SUCCESS");
Assert.assertEquals(paymentTransactionModelDao.getTransactionStatus(), TransactionStatus.SUCCESS);
Assert.assertEquals(paymentTransactionModelDao.getProcessedAmount().compareTo(BigDecimal.TEN), 0);
Assert.assertEquals(paymentTransactionModelDao.getProcessedCurrency(), Currency.EUR);
Assert.assertEquals(paymentTransactionModelDao.getGatewayErrorCode(), "");
Assert.assertEquals(paymentTransactionModelDao.getGatewayErrorMsg(), "");
try {
// Since no transaction status is passed, PaymentTransactionInfoPlugin should be set
adminPaymentApi.fixPaymentTransactionState(payment, Mockito.mock(DefaultPaymentTransaction.class), null, null, "AUTH_ERRORED", ImmutableList.<PluginProperty>of(), callContext);
} catch (final PaymentApiException e) {
Assert.assertEquals(e.getCode(), ErrorCode.PAYMENT_INVALID_PARAMETER.getCode());
}
}
use of org.killbill.billing.payment.dao.PaymentModelDao in project killbill by killbill.
the class TestDefaultAdminPaymentApi method testFixPaymentTransactionStateFromPaymentTransactionInfoPlugin.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/551")
public void testFixPaymentTransactionStateFromPaymentTransactionInfoPlugin() throws PaymentApiException {
final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, BigDecimal.TEN, Currency.EUR, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(), callContext);
final PaymentModelDao paymentModelDao = paymentDao.getPayment(payment.getId(), internalCallContext);
final PaymentTransactionModelDao paymentTransactionModelDao = paymentDao.getPaymentTransaction(payment.getTransactions().get(0).getId(), internalCallContext);
Assert.assertEquals(paymentModelDao.getStateName(), "AUTH_SUCCESS");
Assert.assertEquals(paymentModelDao.getLastSuccessStateName(), "AUTH_SUCCESS");
Assert.assertEquals(paymentTransactionModelDao.getTransactionStatus(), TransactionStatus.SUCCESS);
Assert.assertEquals(paymentTransactionModelDao.getProcessedAmount().compareTo(BigDecimal.TEN), 0);
Assert.assertEquals(paymentTransactionModelDao.getProcessedCurrency(), Currency.EUR);
Assert.assertEquals(paymentTransactionModelDao.getGatewayErrorCode(), "");
Assert.assertEquals(paymentTransactionModelDao.getGatewayErrorMsg(), "");
final PaymentTransactionInfoPlugin infoPlugin = new DefaultNoOpPaymentInfoPlugin(paymentTransactionModelDao.getPaymentId(), paymentTransactionModelDao.getId(), paymentTransactionModelDao.getTransactionType(), paymentTransactionModelDao.getAmount(), paymentTransactionModelDao.getCurrency(), paymentTransactionModelDao.getEffectiveDate(), paymentTransactionModelDao.getCreatedDate(), PaymentPluginStatus.ERROR, "error-code", "error-msg");
final PaymentTransaction newPaymentTransaction = new DefaultPaymentTransaction(paymentTransactionModelDao.getId(), paymentTransactionModelDao.getAttemptId(), paymentTransactionModelDao.getTransactionExternalKey(), paymentTransactionModelDao.getCreatedDate(), paymentTransactionModelDao.getUpdatedDate(), paymentTransactionModelDao.getPaymentId(), paymentTransactionModelDao.getTransactionType(), paymentTransactionModelDao.getEffectiveDate(), TransactionStatus.PAYMENT_FAILURE, paymentTransactionModelDao.getAmount(), paymentTransactionModelDao.getCurrency(), paymentTransactionModelDao.getProcessedAmount(), paymentTransactionModelDao.getProcessedCurrency(), infoPlugin.getGatewayErrorCode(), infoPlugin.getGatewayError(), infoPlugin);
adminPaymentApi.fixPaymentTransactionState(payment, newPaymentTransaction, null, null, "AUTH_ERRORED", ImmutableList.<PluginProperty>of(), callContext);
final PaymentModelDao refreshedPaymentModelDao = paymentDao.getPayment(payment.getId(), internalCallContext);
final PaymentTransactionModelDao refreshedPaymentTransactionModelDao = paymentDao.getPaymentTransaction(payment.getTransactions().get(0).getId(), internalCallContext);
Assert.assertEquals(refreshedPaymentModelDao.getStateName(), "AUTH_ERRORED");
Assert.assertNull(refreshedPaymentModelDao.getLastSuccessStateName());
Assert.assertEquals(refreshedPaymentTransactionModelDao.getTransactionStatus(), TransactionStatus.PAYMENT_FAILURE);
Assert.assertEquals(refreshedPaymentTransactionModelDao.getProcessedAmount().compareTo(BigDecimal.ZERO), 0);
Assert.assertEquals(refreshedPaymentTransactionModelDao.getProcessedCurrency(), Currency.EUR);
Assert.assertEquals(refreshedPaymentTransactionModelDao.getGatewayErrorCode(), "error-code");
Assert.assertEquals(refreshedPaymentTransactionModelDao.getGatewayErrorMsg(), "error-msg");
}
use of org.killbill.billing.payment.dao.PaymentModelDao in project killbill by killbill.
the class TestIncompletePaymentTransactionTaskWithDB method testUpdateWithinLock.
@Test(groups = "slow", description = "https://github.com/killbill/killbill/issues/809")
public void testUpdateWithinLock() throws PaymentApiException {
final Payment payment = paymentApi.createAuthorization(account, account.getPaymentMethodId(), null, BigDecimal.TEN, Currency.EUR, null, UUID.randomUUID().toString(), UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.UNDEFINED.toString(), false)), callContext);
final PaymentModelDao paymentModel = paymentDao.getPayment(payment.getId(), internalCallContext);
final UUID transactionId = payment.getTransactions().get(0).getId();
final PaymentTransactionModelDao transactionModel = paymentDao.getPaymentTransaction(transactionId, internalCallContext);
Assert.assertEquals(paymentModel.getStateName(), "AUTH_ERRORED");
Assert.assertEquals(transactionModel.getTransactionStatus().toString(), "UNKNOWN");
paymentDao.updatePaymentAndTransactionOnCompletion(account.getId(), null, payment.getId(), TransactionType.AUTHORIZE, "AUTH_SUCCESS", "AUTH_SUCCESS", transactionId, TransactionStatus.SUCCESS, BigDecimal.TEN, Currency.EUR, "200", "Ok", true, internalCallContext);
paymentApi.createCapture(account, payment.getId(), BigDecimal.TEN, Currency.EUR, null, UUID.randomUUID().toString(), ImmutableList.<PluginProperty>of(new PluginProperty(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, PaymentPluginStatus.PROCESSED.toString(), false)), callContext);
final PaymentModelDao paymentAfterCapture = paymentDao.getPayment(payment.getId(), internalCallContext);
Assert.assertEquals(paymentAfterCapture.getStateName(), "CAPTURE_SUCCESS");
PaymentTransactionInfoPlugin paymentTransactionInfoPlugin = new DefaultNoOpPaymentInfoPlugin(payment.getId(), transactionId, TransactionType.AUTHORIZE, BigDecimal.TEN, Currency.EUR, transactionModel.getEffectiveDate(), transactionModel.getCreatedDate(), PaymentPluginStatus.PROCESSED, "200", "OK");
incompletePaymentTransactionTask.updatePaymentAndTransactionIfNeeded(paymentModel.getAccountId(), transactionModel.getId(), payment.getTransactions().get(0).getTransactionStatus(), paymentTransactionInfoPlugin, true, internalCallContext);
final PaymentModelDao paymentAfterJanitor = paymentDao.getPayment(payment.getId(), internalCallContext);
Assert.assertEquals(paymentAfterJanitor.getStateName(), "CAPTURE_SUCCESS");
}
Aggregations