Search in sources :

Example 26 with PaymentModelDao

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());
    }
}
Also used : PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) Test(org.testng.annotations.Test)

Example 27 with PaymentModelDao

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");
}
Also used : DefaultNoOpPaymentInfoPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) Test(org.testng.annotations.Test)

Example 28 with PaymentModelDao

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");
}
Also used : PluginProperty(org.killbill.billing.payment.api.PluginProperty) Payment(org.killbill.billing.payment.api.Payment) DefaultNoOpPaymentInfoPlugin(org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin) PaymentTransactionModelDao(org.killbill.billing.payment.dao.PaymentTransactionModelDao) PaymentModelDao(org.killbill.billing.payment.dao.PaymentModelDao) PaymentTransactionInfoPlugin(org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Aggregations

PaymentModelDao (org.killbill.billing.payment.dao.PaymentModelDao)28 PaymentTransactionModelDao (org.killbill.billing.payment.dao.PaymentTransactionModelDao)21 Test (org.testng.annotations.Test)11 UUID (java.util.UUID)10 PaymentApiException (org.killbill.billing.payment.api.PaymentApiException)9 PaymentTransactionInfoPlugin (org.killbill.billing.payment.plugin.api.PaymentTransactionInfoPlugin)9 Predicate (com.google.common.base.Predicate)8 PaymentAttemptModelDao (org.killbill.billing.payment.dao.PaymentAttemptModelDao)6 PluginProperty (org.killbill.billing.payment.api.PluginProperty)5 LinkedList (java.util.LinkedList)4 State (org.killbill.automaton.State)4 PaymentPluginApi (org.killbill.billing.payment.plugin.api.PaymentPluginApi)4 DefaultNoOpPaymentInfoPlugin (org.killbill.billing.payment.provider.DefaultNoOpPaymentInfoPlugin)4 BigDecimal (java.math.BigDecimal)3 ImmutableList (com.google.common.collect.ImmutableList)2 List (java.util.List)2 DateTime (org.joda.time.DateTime)2 Account (org.killbill.billing.account.api.Account)2 AccountApiException (org.killbill.billing.account.api.AccountApiException)2 InternalTenantContext (org.killbill.billing.callcontext.InternalTenantContext)2