Search in sources :

Example 16 with Account

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

the class TestAccount method testRefreshPaymentMethods.

@Test(groups = "slow", description = "refresh payment methods")
public void testRefreshPaymentMethods() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod("someExternalKey");
    final PaymentMethods paymentMethodsBeforeRefreshing = accountApi.getPaymentMethodsForAccount(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(paymentMethodsBeforeRefreshing.size(), 1);
    assertEquals(paymentMethodsBeforeRefreshing.get(0).getExternalKey(), "someExternalKey");
    // WITH NAME OF AN EXISTING PLUGIN
    accountApi.refreshPaymentMethods(account.getAccountId(), PLUGIN_NAME, NULL_PLUGIN_PROPERTIES, requestOptions);
    final PaymentMethods paymentMethodsAfterExistingPluginCall = accountApi.getPaymentMethodsForAccount(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(paymentMethodsAfterExistingPluginCall.size(), 1);
    assertEquals(paymentMethodsAfterExistingPluginCall.get(0).getExternalKey(), "someExternalKey");
    // WITHOUT PLUGIN NAME
    accountApi.refreshPaymentMethods(account.getAccountId(), PLUGIN_NAME, NULL_PLUGIN_PROPERTIES, requestOptions);
    final PaymentMethods paymentMethodsAfterNoPluginNameCall = accountApi.getPaymentMethodsForAccount(account.getAccountId(), NULL_PLUGIN_PROPERTIES, requestOptions);
    assertEquals(paymentMethodsAfterNoPluginNameCall.size(), 1);
    assertEquals(paymentMethodsAfterNoPluginNameCall.get(0).getExternalKey(), "someExternalKey");
    // WITH WRONG PLUGIN NAME
    try {
        accountApi.refreshPaymentMethods(account.getAccountId(), "GreatestPluginEver", NULL_PLUGIN_PROPERTIES, requestOptions);
        Assert.fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.PAYMENT_NO_SUCH_PAYMENT_PLUGIN.getCode());
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) KillBillClientException(org.killbill.billing.client.KillBillClientException) PaymentMethods(org.killbill.billing.client.model.PaymentMethods) Test(org.testng.annotations.Test)

Example 17 with Account

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

the class TestAccount method testParentAccountOk.

@Test(groups = "slow", description = "Can create and retrieve parent/children accounts")
public void testParentAccountOk() throws Exception {
    final Account parentAccount = createAccount();
    final Account childInput = getAccount();
    childInput.setParentAccountId(parentAccount.getAccountId());
    childInput.setIsPaymentDelegatedToParent(true);
    final Account childAccount = accountApi.createAccount(childInput, requestOptions);
    // Retrieves child account by external key
    final Account retrievedAccount = accountApi.getAccountByKey(childAccount.getExternalKey(), requestOptions);
    Assert.assertTrue(retrievedAccount.equals(childAccount));
    Assert.assertEquals(retrievedAccount.getParentAccountId(), parentAccount.getAccountId());
    Assert.assertTrue(retrievedAccount.isPaymentDelegatedToParent());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Test(org.testng.annotations.Test)

Example 18 with Account

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

the class TestAccount method testResetAccountNotes.

@Test(groups = "slow", description = "Can reset account notes using flag treatNullAsReset")
public void testResetAccountNotes() throws Exception {
    final Account input = createAccount();
    Assert.assertNotNull(input.getExternalKey());
    Assert.assertNotNull(input.getNotes());
    Assert.assertEquals(input.getNotes(), "notes");
    Assert.assertEquals(input.getTimeZone(), "UTC");
    Assert.assertEquals(input.getAddress1(), "12 rue des ecoles");
    Assert.assertEquals(input.getAddress2(), "Poitier");
    Assert.assertEquals(input.getCity(), "Quelque part");
    Assert.assertEquals(input.getState(), "Poitou");
    Assert.assertEquals(input.getCountry(), "France");
    Assert.assertEquals(input.getLocale(), "fr");
    // Set notes to something else
    final Account newInput = new Account(input.getAccountId(), null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, "notes2", null, null, null, EMPTY_AUDIT_LOGS);
    // Update notes, all other fields remaining the same (value set to null but treatNullAsReset defaults to false)
    accountApi.updateAccount(newInput.getAccountId(), newInput, requestOptions);
    Account updatedAccount = accountApi.getAccount(input.getAccountId(), requestOptions);
    Assert.assertNotNull(updatedAccount.getExternalKey());
    Assert.assertNotNull(updatedAccount.getNotes());
    Assert.assertEquals(updatedAccount.getNotes(), "notes2");
    Assert.assertEquals(updatedAccount.getTimeZone(), "UTC");
    Assert.assertEquals(updatedAccount.getAddress1(), "12 rue des ecoles");
    Assert.assertEquals(updatedAccount.getAddress2(), "Poitier");
    Assert.assertEquals(updatedAccount.getCity(), "Quelque part");
    Assert.assertEquals(updatedAccount.getState(), "Poitou");
    Assert.assertEquals(updatedAccount.getCountry(), "France");
    Assert.assertEquals(updatedAccount.getLocale(), "fr");
    // Reset notes, all other fields remaining the same
    updatedAccount.setNotes(null);
    accountApi.updateAccount(updatedAccount.getAccountId(), updatedAccount, true, requestOptions);
    updatedAccount = accountApi.getAccount(input.getAccountId(), requestOptions);
    Assert.assertNotNull(updatedAccount.getExternalKey());
    Assert.assertNull(updatedAccount.getNotes());
    Assert.assertEquals(updatedAccount.getTimeZone(), "UTC");
    Assert.assertEquals(updatedAccount.getAddress1(), "12 rue des ecoles");
    Assert.assertEquals(updatedAccount.getAddress2(), "Poitier");
    Assert.assertEquals(updatedAccount.getCity(), "Quelque part");
    Assert.assertEquals(updatedAccount.getState(), "Poitou");
    Assert.assertEquals(updatedAccount.getCountry(), "France");
    Assert.assertEquals(updatedAccount.getLocale(), "fr");
}
Also used : Account(org.killbill.billing.client.model.gen.Account) Test(org.testng.annotations.Test)

Example 19 with Account

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

the class TestAccount method testUniqueExternalKey.

@Test(groups = "slow", description = "Verify external key is unique")
public void testUniqueExternalKey() throws Exception {
    // Verify the external key is not mandatory
    final Account inputWithNoExternalKey = getAccount(UUID.randomUUID().toString(), null, UUID.randomUUID().toString());
    Assert.assertNull(inputWithNoExternalKey.getExternalKey());
    final Account account = accountApi.createAccount(inputWithNoExternalKey, requestOptions);
    Assert.assertNotNull(account.getExternalKey());
    final Account inputWithSameExternalKey = getAccount(UUID.randomUUID().toString(), account.getExternalKey(), UUID.randomUUID().toString());
    try {
        accountApi.createAccount(inputWithSameExternalKey, requestOptions);
        Assert.fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.ACCOUNT_ALREADY_EXISTS.getCode());
    }
}
Also used : Account(org.killbill.billing.client.model.gen.Account) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 20 with Account

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

the class TestAccount method testGetAccountAuditLogs.

@Test(groups = "slow", description = "retrieve account logs")
public void testGetAccountAuditLogs() throws Exception {
    final Account accountJson = createAccount();
    assertNotNull(accountJson);
    // generate more log data
    final CustomFields customFields = new CustomFields();
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "1", "value1", null));
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "2", "value2", null));
    customFields.add(new CustomField(null, accountJson.getAccountId(), ObjectType.ACCOUNT, "3", "value3", null));
    accountApi.createAccountCustomFields(accountJson.getAccountId(), customFields, requestOptions);
    final CustomFields accountCustomFields = accountApi.getAccountCustomFields(accountJson.getAccountId(), requestOptions);
    assertEquals(accountCustomFields.size(), 3);
    final AuditLogs auditLogsJson = accountApi.getAccountAuditLogs(accountJson.getAccountId(), requestOptions);
    assertEquals(auditLogsJson.size(), 4);
    assertEquals(auditLogsJson.get(0).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogsJson.get(0).getObjectType(), ObjectType.ACCOUNT);
    assertEquals(auditLogsJson.get(0).getObjectId(), accountJson.getAccountId());
    assertEquals(auditLogsJson.get(1).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogsJson.get(1).getObjectType(), ObjectType.CUSTOM_FIELD);
    assertEquals(auditLogsJson.get(1).getObjectId(), accountCustomFields.get(0).getCustomFieldId());
    assertEquals(auditLogsJson.get(2).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogsJson.get(2).getObjectType(), ObjectType.CUSTOM_FIELD);
    assertEquals(auditLogsJson.get(2).getObjectId(), accountCustomFields.get(1).getCustomFieldId());
    assertEquals(auditLogsJson.get(3).getChangeType(), ChangeType.INSERT.toString());
    assertEquals(auditLogsJson.get(3).getObjectType(), ObjectType.CUSTOM_FIELD);
    assertEquals(auditLogsJson.get(3).getObjectId(), accountCustomFields.get(2).getCustomFieldId());
}
Also used : Account(org.killbill.billing.client.model.gen.Account) CustomFields(org.killbill.billing.client.model.CustomFields) AuditLogs(org.killbill.billing.client.model.AuditLogs) CustomField(org.killbill.billing.client.model.gen.CustomField) 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