Search in sources :

Example 56 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestPaymentMethod method testGePaymentMethodsByKey.

@Test(groups = "slow", description = "Create/retrieve by externalKey")
public void testGePaymentMethodsByKey() throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod("foo");
    final PaymentMethod paymentMethodJson1 = paymentMethodApi.getPaymentMethodByKey("foo", NULL_PLUGIN_PROPERTIES, requestOptions);
    final PaymentMethod paymentMethodJson2 = paymentMethodApi.getPaymentMethod(accountJson.getPaymentMethodId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(paymentMethodJson1, paymentMethodJson2);
    final PaymentMethod paymentMethodJson3 = paymentMethodApi.getPaymentMethodByKey("doesnotexist", NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertNull(paymentMethodJson3);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) PaymentMethod(org.killbill.billing.client.model.gen.PaymentMethod) Test(org.testng.annotations.Test)

Example 57 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestPerTenantConfig method testFailedPaymentWithPerTenantRetryConfig.

@Test(groups = "slow")
public void testFailedPaymentWithPerTenantRetryConfig() throws Exception {
    // Create the tenant
    createTenant("tenantSuperTuned", "2367$$ffr79", true);
    // Configure our plugin to fail
    mockPaymentProviderPlugin.makeAllInvoicesFailWithError(true);
    // Upload the config
    final ObjectMapper mapper = new ObjectMapper();
    final HashMap<String, String> perTenantProperties = new HashMap<String, String>();
    perTenantProperties.put("org.killbill.payment.retry.days", "1,1,1");
    final String perTenantConfig = mapper.writeValueAsString(perTenantProperties);
    callbackServlet.pushExpectedEvent(ExtBusEventType.TENANT_CONFIG_CHANGE);
    final TenantKeyValue tenantKey = tenantApi.uploadPerTenantConfiguration(perTenantConfig, requestOptions);
    callbackServlet.assertListenerStatus();
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice(false);
    final Payments payments = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(payments.size(), 1);
    Assert.assertEquals(payments.get(0).getTransactions().size(), 1);
    // 
    // Because we have specified a retry interval of one day we should see the new attempt after moving clock 1 day (and not 8 days which is default)
    // 
    // 
    // Now unregister special per tenant config and when the first retry occurs one day after (and still fails), it now sets a retry date of 8 days
    // 
    callbackServlet.pushExpectedEvents(ExtBusEventType.TENANT_CONFIG_DELETION);
    tenantApi.deletePerTenantConfiguration(requestOptions);
    callbackServlet.assertListenerStatus();
    callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_FAILED, ExtBusEventType.PAYMENT_FAILED);
    clock.addDays(1);
    callbackServlet.assertListenerStatus();
    final Payments payments2 = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(payments2.size(), 1);
    Assert.assertEquals(payments2.get(0).getTransactions().size(), 2);
    Assert.assertEquals(payments2.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE);
    Assert.assertEquals(payments2.get(0).getTransactions().get(1).getStatus(), TransactionStatus.PAYMENT_FAILURE);
    clock.addDays(1);
    callbackServlet.assertListenerStatus();
    // No retry with default config
    final Payments payments3 = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(payments3.size(), 1);
    Assert.assertEquals(payments3.get(0).getTransactions().size(), 2);
    mockPaymentProviderPlugin.makeAllInvoicesFailWithError(false);
    callbackServlet.pushExpectedEvents(ExtBusEventType.INVOICE_PAYMENT_SUCCESS, ExtBusEventType.PAYMENT_SUCCESS);
    clock.addDays(7);
    callbackServlet.assertListenerStatus();
    final Payments payments4 = accountApi.getPaymentsForAccount(accountJson.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    Assert.assertEquals(payments4.size(), 1);
    Assert.assertEquals(payments4.get(0).getTransactions().size(), 3);
    Assert.assertEquals(payments4.get(0).getTransactions().get(0).getStatus(), TransactionStatus.PAYMENT_FAILURE);
    Assert.assertEquals(payments4.get(0).getTransactions().get(1).getStatus(), TransactionStatus.PAYMENT_FAILURE);
    Assert.assertEquals(payments4.get(0).getTransactions().get(2).getStatus(), TransactionStatus.SUCCESS);
}
Also used : Account(org.killbill.billing.client.model.gen.Account) HashMap(java.util.HashMap) Payments(org.killbill.billing.client.model.Payments) TenantKeyValue(org.killbill.billing.client.model.gen.TenantKeyValue) ObjectMapper(org.killbill.billing.util.jackson.ObjectMapper) Test(org.testng.annotations.Test)

Example 58 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestTag method testGetTagAuditLogsWithHistory.

@Test(groups = "slow", description = "retrieve account logs")
public void testGetTagAuditLogsWithHistory() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    final TagDefinition accountTagDefInput = new TagDefinition().setName("tag_name").setDescription("nothing special").setApplicableObjectTypes(ImmutableList.<ObjectType>of(ObjectType.ACCOUNT));
    final TagDefinition accountTagDef = tagDefinitionApi.createTagDefinition(accountTagDefInput, requestOptions);
    accountApi.createAccountTags(accountJson.getAccountId(), ImmutableList.<UUID>of(accountTagDef.getId()), requestOptions);
    // get all audit for the account
    final List<AuditLog> auditLogsJson = accountApi.getAccountAuditLogs(accountJson.getAccountId(), requestOptions);
    Assert.assertEquals(auditLogsJson.size(), 2);
    UUID objectId = null;
    for (AuditLog auditLog : auditLogsJson) {
        if (auditLog.getObjectType().equals(ObjectType.TAG)) {
            objectId = auditLog.getObjectId();
            break;
        }
    }
    assertNotNull(objectId);
    final List<AuditLog> tagAuditLogWithHistories = tagApi.getTagAuditLogsWithHistory(objectId, requestOptions);
    assertEquals(tagAuditLogWithHistories.size(), 1);
    assertEquals(tagAuditLogWithHistories.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(tagAuditLogWithHistories.get(0).getObjectType(), ObjectType.TAG);
    assertEquals(tagAuditLogWithHistories.get(0).getObjectId(), objectId);
    final LinkedHashMap history1 = (LinkedHashMap) tagAuditLogWithHistories.get(0).getHistory();
    assertNotNull(history1);
    assertEquals(history1.get("tagDefinitionId"), accountTagDef.getId().toString());
    assertEquals(history1.get("objectId"), accountJson.getAccountId().toString());
    assertEquals(history1.get("objectType"), ObjectType.ACCOUNT.toString());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) TagDefinition(org.killbill.billing.client.model.gen.TagDefinition) UUID(java.util.UUID) AuditLog(org.killbill.billing.client.model.gen.AuditLog) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 59 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestTag method testSystemTagsPagination.

@Test(groups = "slow", description = "Can search system tags")
public void testSystemTagsPagination() throws Exception {
    final Account account = createAccount();
    int nbAllowedControlTagType = 0;
    for (final ControlTagType controlTagType : ControlTagType.values()) {
        if (controlTagType.getApplicableObjectTypes().contains(ObjectType.ACCOUNT)) {
            accountApi.createAccountTags(account.getAccountId(), ImmutableList.<UUID>of(controlTagType.getId()), requestOptions);
            nbAllowedControlTagType++;
        }
    }
    final Tags allTags = accountApi.getAccountTags(account.getAccountId(), requestOptions);
    Assert.assertEquals(allTags.size(), nbAllowedControlTagType);
    for (final ControlTagType controlTagType : ControlTagType.values()) {
        if (controlTagType.getApplicableObjectTypes().contains(ObjectType.ACCOUNT)) {
            Assert.assertEquals(tagApi.searchTags(controlTagType.toString(), requestOptions).size(), 1);
            // TODO Hack until we fix client api
            Assert.assertEquals(tagApi.searchTags(Utf8UrlEncoder.encodePath(controlTagType.getDescription()), requestOptions).size(), 1);
        }
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) ControlTagType(org.killbill.billing.util.tag.ControlTagType) Tags(org.killbill.billing.client.model.Tags) SystemTags(org.killbill.billing.util.tag.dao.SystemTags) Test(org.testng.annotations.Test)

Example 60 with Account

use of org.killbill.billing.client.model.gen.Account in project killbill by killbill.

the class TestTag method testNotApplicableType.

@Test(groups = "slow", description = "Cannot create a control tag against wrong object type")
public void testNotApplicableType() throws Exception {
    final Account account = createAccount();
    try {
        accountApi.createAccountTags(account.getAccountId(), ImmutableList.<UUID>of(ControlTagType.WRITTEN_OFF.getId()), requestOptions);
        Assert.fail("Creating a (control) tag against a wrong object type should fail");
    } catch (final Exception e) {
        Assert.assertTrue(true);
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.gen.Account)153 Test (org.testng.annotations.Test)139 DateTime (org.joda.time.DateTime)43 UUID (java.util.UUID)38 InvoicePayment (org.killbill.billing.client.model.gen.InvoicePayment)37 Subscription (org.killbill.billing.client.model.gen.Subscription)34 Invoice (org.killbill.billing.client.model.gen.Invoice)33 BigDecimal (java.math.BigDecimal)29 Payment (org.killbill.billing.client.model.gen.Payment)28 PaymentTransaction (org.killbill.billing.client.model.gen.PaymentTransaction)21 KillBillClientException (org.killbill.billing.client.KillBillClientException)19 Invoices (org.killbill.billing.client.model.Invoices)19 ComboPaymentTransaction (org.killbill.billing.client.model.gen.ComboPaymentTransaction)19 InvoiceItem (org.killbill.billing.client.model.gen.InvoiceItem)19 LocalDate (org.joda.time.LocalDate)13 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 Tags (org.killbill.billing.client.model.Tags)13 PaymentMethod (org.killbill.billing.client.model.gen.PaymentMethod)12 InvoicePaymentTransaction (org.killbill.billing.client.model.gen.InvoicePaymentTransaction)11 Payments (org.killbill.billing.client.model.Payments)10