Search in sources :

Example 51 with Account

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

the class TestPayment method testWithTimeoutPayment.

@Test(groups = "slow")
public void testWithTimeoutPayment() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    mockPaymentProviderPlugin.makePluginWaitSomeMilliseconds(10000);
    final PaymentTransaction authTransaction = new PaymentTransaction();
    authTransaction.setAmount(BigDecimal.ONE);
    authTransaction.setCurrency(account.getCurrency());
    authTransaction.setTransactionType(TransactionType.AUTHORIZE.name());
    try {
        killBillClient.createPayment(account.getAccountId(), account.getPaymentMethodId(), authTransaction, ImmutableMap.<String, String>of(), requestOptions);
        fail();
    } catch (KillBillClientException e) {
        assertEquals(504, e.getResponse().getStatusCode());
    }
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) ComboPaymentTransaction(org.killbill.billing.client.model.ComboPaymentTransaction) Account(org.killbill.billing.client.model.Account) KillBillClientException(org.killbill.billing.client.KillBillClientException) Test(org.testng.annotations.Test)

Example 52 with Account

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

the class TestPayment method testCreateRetrievePayment.

@Test(groups = "slow")
public void testCreateRetrievePayment() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final String externalPaymentKey = UUID.randomUUID().toString();
    final UUID paymentId = testCreateRetrievePayment(account, null, externalPaymentKey, 1);
    final Payment payment = killBillClient.getPaymentByExternalKey(externalPaymentKey);
    assertEquals(payment.getPaymentId(), paymentId);
    final PaymentMethod paymentMethodJson = new PaymentMethod(null, UUID.randomUUID().toString(), account.getAccountId(), false, PLUGIN_NAME, new PaymentMethodPluginDetail());
    final PaymentMethod nonDefaultPaymentMethod = killBillClient.createPaymentMethod(paymentMethodJson, createdBy, reason, comment);
    testCreateRetrievePayment(account, nonDefaultPaymentMethod.getPaymentMethodId(), UUID.randomUUID().toString(), 2);
}
Also used : Account(org.killbill.billing.client.model.Account) Payment(org.killbill.billing.client.model.Payment) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) PaymentMethodPluginDetail(org.killbill.billing.client.model.PaymentMethodPluginDetail) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 53 with Account

use of org.killbill.billing.client.model.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();
    for (final ControlTagType controlTagType : ControlTagType.values()) {
        killBillClient.createAccountTag(account.getAccountId(), controlTagType.getId(), requestOptions);
    }
    final Tags allTags = killBillClient.getTags(requestOptions);
    Assert.assertEquals(allTags.size(), ControlTagType.values().length);
    for (final ControlTagType controlTagType : ControlTagType.values()) {
        Assert.assertEquals(killBillClient.searchTags(controlTagType.toString(), requestOptions).size(), 1);
        Assert.assertEquals(killBillClient.searchTags(controlTagType.getDescription(), requestOptions).size(), 1);
    }
}
Also used : Account(org.killbill.billing.client.model.Account) ControlTagType(org.killbill.billing.util.tag.ControlTagType) SystemTags(org.killbill.billing.util.tag.dao.SystemTags) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 54 with Account

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

the class TestOverdue method testControlTagOverdueConfig.

@Test(groups = "slow", description = "Allow overdue condition by control tag defined in overdue config xml file")
public void testControlTagOverdueConfig() throws Exception {
    final String overdueConfigPath = Resources.getResource("overdueWithControlTag.xml").getPath();
    killBillClient.uploadXMLOverdueConfig(overdueConfigPath, requestOptions);
    // Create an account without a payment method and assign a TEST tag
    final Account accountJson = createAccountNoPMBundleAndSubscription();
    final Tags accountTag = killBillClient.createAccountTag(accountJson.getAccountId(), ControlTagType.TEST.getId(), requestOptions);
    assertEquals(accountTag.get(0).getTagDefinitionId(), ControlTagType.TEST.getId());
    // Create an account without a TEST tag
    final Account accountJsonNoTag = createAccountNoPMBundleAndSubscription();
    // No payment will be triggered as the account doesn't have a payment method
    clock.addMonths(1);
    crappyWaitForLackOfProperSynchonization();
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final List<Invoice> invoicesNoTag = killBillClient.getInvoicesForAccount(accountJsonNoTag.getAccountId(), requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoicesNoTag.size(), 2);
    // We're still clear - see the configuration
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJsonNoTag.getAccountId(), requestOptions).getIsClearState());
    clock.addDays(30);
    crappyWaitForLackOfProperSynchonization();
    // This account is expected to move to OD1 state because it matches with controlTag defined
    Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getName(), "OD1");
    // This account is not expected to move to OD1 state because it does not match with controlTag defined
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJsonNoTag.getAccountId(), requestOptions).getIsClearState());
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 55 with Account

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

the class TestOverdue method testOverdueStatus.

@Test(groups = "slow", description = "Can retrieve the account overdue status")
public void testOverdueStatus() throws Exception {
    // Create an account without a payment method
    final Account accountJson = createAccountNoPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    // We're still clear - see the configuration
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
    clock.addDays(30);
    crappyWaitForLackOfProperSynchonization();
    Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getName(), "OD1");
    clock.addDays(10);
    crappyWaitForLackOfProperSynchonization();
    Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getName(), "OD2");
    clock.addDays(10);
    crappyWaitForLackOfProperSynchonization();
    Assert.assertEquals(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getName(), "OD3");
    // Post external payments, paying the most recent invoice first: this is to avoid a race condition where
    // a refresh overdue notification kicks in after the first payment, which makes the account goes CLEAR and
    // triggers an AUTO_INVOICE_OFF tag removal (hence adjustment of the other invoices balance).
    final Invoices invoicesForAccount = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), requestOptions);
    final List<Invoice> mostRecentInvoiceFirst = Ordering.<Invoice>from(new Comparator<Invoice>() {

        @Override
        public int compare(final Invoice invoice1, final Invoice invoice2) {
            return invoice1.getInvoiceDate().compareTo(invoice2.getInvoiceDate());
        }
    }).reverse().sortedCopy(invoicesForAccount);
    for (final Invoice invoice : mostRecentInvoiceFirst) {
        if (invoice.getBalance().compareTo(BigDecimal.ZERO) > 0) {
            final InvoicePayment invoicePayment = new InvoicePayment();
            invoicePayment.setPurchasedAmount(invoice.getAmount());
            invoicePayment.setAccountId(accountJson.getAccountId());
            invoicePayment.setTargetInvoiceId(invoice.getInvoiceId());
            killBillClient.createInvoicePayment(invoicePayment, true, requestOptions);
        }
    }
    // Wait a bit for overdue to pick up the payment events...
    crappyWaitForLackOfProperSynchonization();
    // Verify we're in clear state
    Assert.assertTrue(killBillClient.getOverdueStateForAccount(accountJson.getAccountId(), requestOptions).getIsClearState());
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Invoice(org.killbill.billing.client.model.Invoice) Invoices(org.killbill.billing.client.model.Invoices) Test(org.testng.annotations.Test)

Aggregations

Account (org.killbill.billing.client.model.Account)123 Test (org.testng.annotations.Test)109 UUID (java.util.UUID)32 DateTime (org.joda.time.DateTime)32 Invoice (org.killbill.billing.client.model.Invoice)30 BigDecimal (java.math.BigDecimal)27 Payment (org.killbill.billing.client.model.Payment)24 Subscription (org.killbill.billing.client.model.Subscription)24 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)17 InvoiceItem (org.killbill.billing.client.model.InvoiceItem)16 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)16 KillBillClientException (org.killbill.billing.client.KillBillClientException)14 InvoicePayment (org.killbill.billing.client.model.InvoicePayment)14 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)13 PaymentMethod (org.killbill.billing.client.model.PaymentMethod)13 InvoicePaymentTransaction (org.killbill.billing.client.model.InvoicePaymentTransaction)10 Payments (org.killbill.billing.client.model.Payments)10 Tags (org.killbill.billing.client.model.Tags)10 Invoices (org.killbill.billing.client.model.Invoices)9 PaymentMethodPluginDetail (org.killbill.billing.client.model.PaymentMethodPluginDetail)9