Search in sources :

Example 16 with Account

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

the class TestEntitlement method testOverridePrice.

@Test(groups = "slow", description = "Can override a price when creating a subscription")
public void testOverridePrice() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final String productName = "Shotgun";
    final BillingPeriod term = BillingPeriod.ANNUAL;
    final Subscription input = new Subscription();
    input.setAccountId(accountJson.getAccountId());
    input.setExternalKey("identical");
    input.setProductName(productName);
    input.setProductCategory(ProductCategory.BASE);
    input.setBillingPeriod(BillingPeriod.MONTHLY);
    input.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final List<PhasePriceOverride> overrides = new ArrayList<PhasePriceOverride>();
    overrides.add(new PhasePriceOverride(null, null, PhaseType.TRIAL.toString(), BigDecimal.TEN, null));
    input.setPriceOverrides(overrides);
    final Subscription subscription = killBillClient.createSubscription(input, null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
    Assert.assertEquals(subscription.getPriceOverrides().size(), 2);
    Assert.assertEquals(subscription.getEvents().size(), 3);
    Assert.assertEquals(subscription.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT.name());
    Assert.assertEquals(subscription.getEvents().get(0).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription.getEvents().get(0).getPhase(), "shotgun-monthly-1-trial");
    Assert.assertEquals(subscription.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription.getEvents().get(0).getProduct(), "Shotgun");
    Assert.assertEquals(subscription.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING.name());
    Assert.assertEquals(subscription.getEvents().get(1).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription.getEvents().get(1).getPhase(), "shotgun-monthly-1-trial");
    Assert.assertEquals(subscription.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription.getEvents().get(1).getProduct(), "Shotgun");
    Assert.assertEquals(subscription.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE.name());
    Assert.assertEquals(subscription.getEvents().get(2).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription.getEvents().get(2).getPhase(), "shotgun-monthly-1-evergreen");
    Assert.assertEquals(subscription.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription.getEvents().get(2).getProduct(), "Shotgun");
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false, false, AuditLevel.FULL, requestOptions);
    assertEquals(invoices.size(), 1);
    assertEquals(invoices.get(0).getAmount().compareTo(BigDecimal.TEN), 0);
    // Move clock after phase
    clock.addDays(30);
    crappyWaitForLackOfProperSynchonization();
    final Subscription subscription2 = killBillClient.getSubscription(subscription.getSubscriptionId(), requestOptions);
    Assert.assertEquals(subscription2.getEvents().size(), 3);
    clock.addDays(3);
    // Change Plan
    final Subscription newInput = new Subscription();
    newInput.setSubscriptionId(subscription2.getSubscriptionId());
    newInput.setPlanName("pistol-monthly");
    final Subscription subscription3 = killBillClient.updateSubscription(newInput, null, BillingActionPolicy.IMMEDIATE, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, requestOptions);
    Assert.assertEquals(subscription3.getEvents().size(), 4);
    Assert.assertEquals(subscription3.getEvents().get(0).getEventType(), SubscriptionEventType.START_ENTITLEMENT.name());
    Assert.assertEquals(subscription3.getEvents().get(0).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription3.getEvents().get(0).getPhase(), "shotgun-monthly-1-trial");
    Assert.assertEquals(subscription3.getEvents().get(0).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription3.getEvents().get(0).getProduct(), "Shotgun");
    Assert.assertEquals(subscription3.getEvents().get(1).getEventType(), SubscriptionEventType.START_BILLING.name());
    Assert.assertEquals(subscription3.getEvents().get(1).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription3.getEvents().get(1).getPhase(), "shotgun-monthly-1-trial");
    Assert.assertEquals(subscription3.getEvents().get(1).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription3.getEvents().get(1).getProduct(), "Shotgun");
    Assert.assertEquals(subscription3.getEvents().get(2).getEventType(), SubscriptionEventType.PHASE.name());
    Assert.assertEquals(subscription3.getEvents().get(2).getPlan(), "shotgun-monthly-1");
    Assert.assertEquals(subscription3.getEvents().get(2).getPhase(), "shotgun-monthly-1-evergreen");
    Assert.assertEquals(subscription3.getEvents().get(2).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription3.getEvents().get(2).getProduct(), "Shotgun");
    Assert.assertEquals(subscription3.getEvents().get(3).getEventType(), SubscriptionEventType.CHANGE.name());
    Assert.assertEquals(subscription3.getEvents().get(3).getPlan(), "pistol-monthly");
    Assert.assertEquals(subscription3.getEvents().get(3).getPhase(), "pistol-monthly-evergreen");
    Assert.assertEquals(subscription3.getEvents().get(3).getPriceList(), PriceListSet.DEFAULT_PRICELIST_NAME.toString());
    Assert.assertEquals(subscription3.getEvents().get(3).getProduct(), "Pistol");
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) BillingPeriod(org.killbill.billing.catalog.api.BillingPeriod) ArrayList(java.util.ArrayList) PhasePriceOverride(org.killbill.billing.client.model.PhasePriceOverride) Subscription(org.killbill.billing.client.model.Subscription) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 17 with Account

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

the class TestExceptions method testExceptionMapping.

@Test(groups = "slow", enabled = false)
public void testExceptionMapping() throws Exception {
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final List<InvoicePayment> payments = killBillClient.getInvoicePaymentsForAccount(account.getAccountId());
    final InvoicePaymentTransaction input = new InvoicePaymentTransaction();
    input.setPaymentId(payments.get(0).getPaymentId());
    input.setAmount(BigDecimal.TEN.negate());
    try {
        killBillClient.createInvoicePaymentChargeback(input, createdBy, reason, comment);
        fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getBillingException().getClassName(), InvoiceApiException.class.getName());
        Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.CHARGE_BACK_AMOUNT_IS_NEGATIVE.getCode());
        Assert.assertFalse(e.getBillingException().getStackTrace().isEmpty());
    }
}
Also used : Account(org.killbill.billing.client.model.Account) 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 18 with Account

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

the class TestExternalRefund method testAutomaticPaymentAndRefundWithAdjustments.

@Test(groups = "slow", description = "#255 - Scenario 0 - Can refund an automatic payment over item adjustments. This is a test to validate the correct behaviour.")
public void testAutomaticPaymentAndRefundWithAdjustments() throws Exception {
    final DateTime initialDate = new DateTime(2012, 4, 25, 0, 3, 42, 0);
    clock.setDeltaFromReality(initialDate.getMillis() - clock.getUTCNow().getMillis());
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final Payments paymentsForAccount = killBillClient.getPaymentsForAccount(accountJson.getAccountId(), requestOptions);
    final Payment payment = paymentsForAccount.get(paymentsForAccount.size() - 1);
    Invoices invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, true, requestOptions);
    final List<InvoiceItem> itemsToBeAdjusted = invoices.get(1).getItems();
    // regular refund
    final InvoicePaymentTransaction invoicePaymentTransactionRequest = new InvoicePaymentTransaction();
    invoicePaymentTransactionRequest.setAmount(BigDecimal.valueOf(249.95));
    invoicePaymentTransactionRequest.setCurrency(accountJson.getCurrency().toString());
    invoicePaymentTransactionRequest.setPaymentId(payment.getPaymentId());
    invoicePaymentTransactionRequest.setIsAdjusted(true);
    invoicePaymentTransactionRequest.setAdjustments(itemsToBeAdjusted);
    final InvoicePayment invoicePaymentRefund = killBillClient.createInvoicePaymentRefund(invoicePaymentTransactionRequest, requestOptions);
    assertNotNull(invoicePaymentRefund);
    assertSingleInvoicePaymentRefund(invoicePaymentRefund);
    assertRefundInvoiceAdjustments(accountJson.getAccountId());
    assertRefundAccountBalance(accountJson.getAccountId(), BigDecimal.ZERO, BigDecimal.ZERO);
}
Also used : Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) Payment(org.killbill.billing.client.model.Payment) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Invoices(org.killbill.billing.client.model.Invoices) DateTime(org.joda.time.DateTime) Test(org.testng.annotations.Test)

Example 19 with Account

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

the class TestInvoice method testInvoiceTransferCreditAccountNoParent.

@Test(groups = "slow", description = "Fail to transfer credit from an account without parent account", expectedExceptions = KillBillClientException.class, expectedExceptionsMessageRegExp = ".* does not have a Parent Account associated")
public void testInvoiceTransferCreditAccountNoParent() throws Exception {
    final Account account = createAccount();
    // transfer credit to parent account
    killBillClient.transferChildCreditToParent(account.getAccountId(), requestOptions);
}
Also used : Account(org.killbill.billing.client.model.Account) Test(org.testng.annotations.Test)

Example 20 with Account

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

the class TestInvoice method testExternalChargeOnExistingInvoiceWithAutomaticPayment.

@Test(groups = "slow", description = "Can create an external charge on an existing invoice and trigger a payment")
public void testExternalChargeOnExistingInvoiceWithAutomaticPayment() throws Exception {
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Get the invoices
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId(), true, false);
    // 2 invoices but look for the non zero dollar one
    assertEquals(invoices.size(), 2);
    final UUID invoiceId = invoices.get(1).getInvoiceId();
    final BigDecimal originalInvoiceAmount = invoices.get(1).getAmount();
    final int originalNumberOfItemsForInvoice = invoices.get(1).getItems().size();
    // Post an external charge
    final BigDecimal chargeAmount = BigDecimal.TEN;
    final InvoiceItem externalCharge = new InvoiceItem();
    externalCharge.setAccountId(accountJson.getAccountId());
    externalCharge.setAmount(chargeAmount);
    externalCharge.setCurrency(accountJson.getCurrency());
    externalCharge.setInvoiceId(invoiceId);
    final InvoiceItem createdExternalCharge = killBillClient.createExternalCharge(externalCharge, clock.getUTCToday(), true, true, createdBy, reason, comment);
    final Invoice invoiceWithItems = killBillClient.getInvoice(createdExternalCharge.getInvoiceId(), true);
    assertEquals(invoiceWithItems.getItems().size(), originalNumberOfItemsForInvoice + 1);
    assertNull(invoiceWithItems.getItems().get(originalNumberOfItemsForInvoice).getBundleId());
    // Verify the new invoice balance
    final Invoice adjustedInvoice = killBillClient.getInvoice(invoiceId);
    assertEquals(adjustedInvoice.getBalance().compareTo(BigDecimal.ZERO), 0);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) InvoiceItem(org.killbill.billing.client.model.InvoiceItem) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) 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