Search in sources :

Example 16 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestPayment method testComboAuthorizationAbortedPayment.

@Test(groups = "slow")
public void testComboAuthorizationAbortedPayment() throws Exception {
    final Account accountJson = getAccount();
    accountJson.setAccountId(null);
    final String paymentExternalKey = UUID.randomUUID().toString();
    final ComboPaymentTransaction comboPaymentTransaction = createComboPaymentTransaction(accountJson, paymentExternalKey);
    mockPaymentControlProviderPlugin.setAborted(true);
    try {
        killBillClient.createPayment(comboPaymentTransaction, Arrays.asList(MockPaymentControlProviderPlugin.PLUGIN_NAME), ImmutableMap.<String, String>of(), requestOptions);
        fail();
    } catch (KillBillClientException e) {
        assertEquals(e.getResponse().getStatusCode(), 422);
    }
    assertFalse(mockPaymentControlProviderPlugin.isOnFailureCallExecuted());
    assertFalse(mockPaymentControlProviderPlugin.isOnSuccessCallExecuted());
}
Also used : Account(org.killbill.billing.client.model.Account) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 17 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionType.

@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionType() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    final BigDecimal amount = BigDecimal.TEN;
    final String pending = PaymentPluginStatus.PENDING.toString();
    final ImmutableMap<String, String> pendingPluginProperties = ImmutableMap.<String, String>of(MockPaymentProviderPlugin.PLUGIN_PROPERTY_PAYMENT_PLUGIN_STATUS_OVERRIDE, pending);
    final ImmutableMap<String, String> pluginProperties = ImmutableMap.of();
    TransactionType transactionType = TransactionType.AUTHORIZE;
    final String paymentExternalKey = UUID.randomUUID().toString();
    final String authTransactionExternalKey = UUID.randomUUID().toString();
    final Payment initialPayment = createVerifyTransaction(account, paymentMethodId, paymentExternalKey, authTransactionExternalKey, transactionType, pending, amount, BigDecimal.ZERO, pendingPluginProperties, 1);
    final PaymentTransaction completeTransactionByPaymentIdAndInvalidTransactionType = new PaymentTransaction();
    completeTransactionByPaymentIdAndInvalidTransactionType.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndInvalidTransactionType.setTransactionType(TransactionType.CAPTURE.name());
    try {
        killBillClient.completePayment(completeTransactionByPaymentIdAndInvalidTransactionType, pluginProperties, requestOptions);
        fail("Payment completion should fail when invalid transaction type has been provided");
    } catch (final KillBillClientException expected) {
    }
    final PaymentTransaction completeTransactionByPaymentIdAndTransactionType = new PaymentTransaction();
    completeTransactionByPaymentIdAndTransactionType.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndTransactionType.setTransactionType(transactionType.name());
    final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentIdAndTransactionType, pluginProperties, requestOptions);
    verifyPayment(account, paymentMethodId, completedPaymentByPaymentId, paymentExternalKey, authTransactionExternalKey, transactionType.toString(), TransactionStatus.SUCCESS.name(), amount, amount, BigDecimal.ZERO, BigDecimal.ZERO, 1, 1);
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) TransactionType(org.killbill.billing.payment.api.TransactionType) Payment(org.killbill.billing.client.model.Payment) KillBillClientException(org.killbill.billing.client.KillBillClientException) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 18 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestAdmin method doCapture.

private void doCapture(final Payment payment, final boolean expectException) throws KillBillClientException {
    // Payment object does not export state, this is purely internal, so to verify that we indeed changed to Failed, we can attempt
    // a capture, which should fail
    final String capture1TransactionExternalKey = UUID.randomUUID().toString();
    final PaymentTransaction captureTransaction = new PaymentTransaction();
    captureTransaction.setPaymentId(payment.getPaymentId());
    captureTransaction.setAmount(BigDecimal.ONE);
    captureTransaction.setCurrency(payment.getCurrency());
    captureTransaction.setPaymentExternalKey(payment.getPaymentExternalKey());
    captureTransaction.setTransactionExternalKey(capture1TransactionExternalKey);
    try {
        killBillClient.captureAuthorization(captureTransaction, requestOptions);
        if (expectException) {
            Assert.fail("Capture should not succeed, after auth was moved to a PAYMENT_FAILURE");
        }
    } catch (final KillBillClientException mabeExpected) {
        if (!expectException) {
            throw mabeExpected;
        }
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException)

Example 19 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestChargeback method testBadRequest.

@Test(groups = "slow", description = "Cannot add a badly formatted chargeback")
public void testBadRequest() throws Exception {
    final Payment payment = createAccountWithInvoiceAndPayment();
    final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
    input.setPaymentId(payment.getPaymentId());
    try {
        killBillClient.createInvoicePaymentChargeback(input, createdBy, reason, comment);
        fail();
    } catch (final KillBillClientException e) {
    }
}
Also used : Payment(org.killbill.billing.client.model.Payment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 20 with KillBillClientException

use of org.killbill.billing.client.KillBillClientException in project killbill by killbill.

the class TestCredit method testBadRequest.

@Test(groups = "slow", description = "Cannot credit a badly formatted credit")
public void testBadRequest() throws Exception {
    final Credit credit = new Credit();
    credit.setAccountId(accountJson.getAccountId());
    credit.setCreditAmount(BigDecimal.TEN.negate());
    // Try to create the credit
    try {
        killBillClient.createCredit(credit, true, createdBy, reason, comment);
        fail();
    } catch (final KillBillClientException e) {
    }
}
Also used : Credit(org.killbill.billing.client.model.Credit) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Aggregations

KillBillClientException (org.killbill.billing.client.KillBillClientException)21 Test (org.testng.annotations.Test)20 Account (org.killbill.billing.client.model.Account)13 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)7 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)6 UUID (java.util.UUID)5 Payment (org.killbill.billing.client.model.Payment)5 BigDecimal (java.math.BigDecimal)3 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)3 TransactionType (org.killbill.billing.payment.api.TransactionType)3 Response (com.ning.http.client.Response)2 RequestOptions (org.killbill.billing.client.RequestOptions)2 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)2 RoleDefinition (org.killbill.billing.client.model.RoleDefinition)2 Tenant (org.killbill.billing.client.model.Tenant)2 UserRoles (org.killbill.billing.client.model.UserRoles)2 Predicate (com.google.common.base.Predicate)1 ArrayList (java.util.ArrayList)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Bundle (org.killbill.billing.client.model.Bundle)1