Search in sources :

Example 41 with Account

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

the class TestInvoiceNotification method testTriggerNotification.

@Test(groups = "slow", description = "Can trigger an invoice notification")
public void testTriggerNotification() throws Exception {
    final Account accountJson = createScenarioWithOneInvoice();
    final List<Invoice> invoices = killBillClient.getInvoicesForAccount(accountJson.getAccountId());
    Assert.assertEquals(invoices.size(), 1);
    final Invoice invoice = invoices.get(0);
    killBillClient.triggerInvoiceNotification(invoice.getInvoiceId(), createdBy, reason, comment);
}
Also used : Account(org.killbill.billing.client.model.Account) Invoice(org.killbill.billing.client.model.Invoice) Test(org.testng.annotations.Test)

Example 42 with Account

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

the class TestInvoicePayment method setupScenarioWithPayment.

private InvoicePayment setupScenarioWithPayment() throws Exception {
    final Account accountJson = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    final List<InvoicePayment> paymentsForAccount = killBillClient.getInvoicePaymentsForAccount(accountJson.getAccountId());
    Assert.assertEquals(paymentsForAccount.size(), 1);
    final InvoicePayment paymentJson = paymentsForAccount.get(0);
    // Check the PaymentMethod from paymentMethodId returned in the Payment object
    final UUID paymentMethodId = paymentJson.getPaymentMethodId();
    final PaymentMethod paymentMethodJson = killBillClient.getPaymentMethod(paymentMethodId, true);
    Assert.assertEquals(paymentMethodJson.getPaymentMethodId(), paymentMethodId);
    Assert.assertEquals(paymentMethodJson.getAccountId(), accountJson.getAccountId());
    // Verify the refunds
    final List<PaymentTransaction> objRefundFromJson = getPaymentTransactions(paymentsForAccount, TransactionType.REFUND.toString());
    Assert.assertEquals(objRefundFromJson.size(), 0);
    return paymentJson;
}
Also used : PaymentTransaction(org.killbill.billing.client.model.PaymentTransaction) InvoicePaymentTransaction(org.killbill.billing.client.model.InvoicePaymentTransaction) Account(org.killbill.billing.client.model.Account) InvoicePayment(org.killbill.billing.client.model.InvoicePayment) PaymentMethod(org.killbill.billing.client.model.PaymentMethod) UUID(java.util.UUID)

Example 43 with Account

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

the class TestUsage method testRecordUsage.

@Test(groups = "slow", description = "Can record and retrieve usage data")
public void testRecordUsage() throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final Subscription base = new Subscription();
    base.setAccountId(accountJson.getAccountId());
    base.setProductName("Pistol");
    base.setProductCategory(ProductCategory.BASE);
    base.setBillingPeriod(BillingPeriod.MONTHLY);
    base.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription addOn = new Subscription();
    addOn.setAccountId(accountJson.getAccountId());
    addOn.setProductName("Bullets");
    addOn.setProductCategory(ProductCategory.ADD_ON);
    addOn.setBillingPeriod(BillingPeriod.NO_BILLING_PERIOD);
    addOn.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Bundle bundle = killBillClient.createSubscriptionWithAddOns(ImmutableList.<Subscription>of(base, addOn), null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, createdBy, reason, comment);
    final UUID addOnSubscriptionId = Iterables.<Subscription>find(bundle.getSubscriptions(), new Predicate<Subscription>() {

        @Override
        public boolean apply(final Subscription input) {
            return ProductCategory.ADD_ON.equals(input.getProductCategory());
        }
    }).getSubscriptionId();
    clock.addDays(1);
    final UsageRecord usageRecord1 = new UsageRecord();
    usageRecord1.setAmount(10L);
    usageRecord1.setRecordDate(clock.getUTCToday().minusDays(1));
    final UsageRecord usageRecord2 = new UsageRecord();
    usageRecord2.setAmount(5L);
    usageRecord2.setRecordDate(clock.getUTCToday());
    final UnitUsageRecord unitUsageRecord = new UnitUsageRecord();
    unitUsageRecord.setUnitType("bullets");
    unitUsageRecord.setUsageRecords(ImmutableList.<UsageRecord>of(usageRecord1, usageRecord2));
    final SubscriptionUsageRecord usage = new SubscriptionUsageRecord();
    usage.setSubscriptionId(addOnSubscriptionId);
    usage.setUnitUsageRecords(ImmutableList.<UnitUsageRecord>of(unitUsageRecord));
    killBillClient.createSubscriptionUsageRecord(usage, createdBy, reason, comment);
    final RolledUpUsage retrievedUsage1 = killBillClient.getRolledUpUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday().minusDays(1), clock.getUTCToday());
    Assert.assertEquals(retrievedUsage1.getSubscriptionId(), usage.getSubscriptionId());
    Assert.assertEquals(retrievedUsage1.getRolledUpUnits().size(), 1);
    Assert.assertEquals(retrievedUsage1.getRolledUpUnits().get(0).getUnitType(), unitUsageRecord.getUnitType());
    // endDate is excluded
    Assert.assertEquals((long) retrievedUsage1.getRolledUpUnits().get(0).getAmount(), 10);
    final RolledUpUsage retrievedUsage2 = killBillClient.getRolledUpUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday().minusDays(1), clock.getUTCToday().plusDays(1));
    Assert.assertEquals(retrievedUsage2.getSubscriptionId(), usage.getSubscriptionId());
    Assert.assertEquals(retrievedUsage2.getRolledUpUnits().size(), 1);
    Assert.assertEquals(retrievedUsage2.getRolledUpUnits().get(0).getUnitType(), unitUsageRecord.getUnitType());
    Assert.assertEquals((long) retrievedUsage2.getRolledUpUnits().get(0).getAmount(), 15);
    final RolledUpUsage retrievedUsage3 = killBillClient.getRolledUpUsage(addOnSubscriptionId, unitUsageRecord.getUnitType(), clock.getUTCToday(), clock.getUTCToday().plusDays(1));
    Assert.assertEquals(retrievedUsage3.getSubscriptionId(), usage.getSubscriptionId());
    Assert.assertEquals(retrievedUsage3.getRolledUpUnits().size(), 1);
    Assert.assertEquals(retrievedUsage3.getRolledUpUnits().get(0).getUnitType(), unitUsageRecord.getUnitType());
    Assert.assertEquals((long) retrievedUsage3.getRolledUpUnits().get(0).getAmount(), 5);
    final RolledUpUsage retrievedUsage4 = killBillClient.getRolledUpUsage(addOnSubscriptionId, null, clock.getUTCToday(), clock.getUTCToday().plusDays(1));
    Assert.assertEquals(retrievedUsage4.getSubscriptionId(), usage.getSubscriptionId());
    Assert.assertEquals(retrievedUsage4.getRolledUpUnits().size(), 1);
    Assert.assertEquals(retrievedUsage4.getRolledUpUnits().get(0).getUnitType(), "bullets");
    Assert.assertEquals((long) retrievedUsage4.getRolledUpUnits().get(0).getAmount(), 5);
}
Also used : Account(org.killbill.billing.client.model.Account) RolledUpUsage(org.killbill.billing.client.model.RolledUpUsage) Bundle(org.killbill.billing.client.model.Bundle) UnitUsageRecord(org.killbill.billing.client.model.UnitUsageRecord) SubscriptionUsageRecord(org.killbill.billing.client.model.SubscriptionUsageRecord) UsageRecord(org.killbill.billing.client.model.UsageRecord) UnitUsageRecord(org.killbill.billing.client.model.UnitUsageRecord) Subscription(org.killbill.billing.client.model.Subscription) UUID(java.util.UUID) SubscriptionUsageRecord(org.killbill.billing.client.model.SubscriptionUsageRecord) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 44 with Account

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

the class TestUsage method testRecordUsageTrackingIdExists.

@Test(groups = "slow", description = "Test tracking ID already exists")
public void testRecordUsageTrackingIdExists() throws Exception {
    final Account accountJson = createAccountWithDefaultPaymentMethod();
    final Subscription base = new Subscription();
    base.setAccountId(accountJson.getAccountId());
    base.setProductName("Pistol");
    base.setProductCategory(ProductCategory.BASE);
    base.setBillingPeriod(BillingPeriod.MONTHLY);
    base.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Subscription addOn = new Subscription();
    addOn.setAccountId(accountJson.getAccountId());
    addOn.setProductName("Bullets");
    addOn.setProductCategory(ProductCategory.ADD_ON);
    addOn.setBillingPeriod(BillingPeriod.NO_BILLING_PERIOD);
    addOn.setPriceList(PriceListSet.DEFAULT_PRICELIST_NAME);
    final Bundle bundle = killBillClient.createSubscriptionWithAddOns(ImmutableList.<Subscription>of(base, addOn), null, DEFAULT_WAIT_COMPLETION_TIMEOUT_SEC, createdBy, reason, comment);
    final UUID addOnSubscriptionId = Iterables.<Subscription>find(bundle.getSubscriptions(), new Predicate<Subscription>() {

        @Override
        public boolean apply(final Subscription input) {
            return ProductCategory.ADD_ON.equals(input.getProductCategory());
        }
    }).getSubscriptionId();
    final UsageRecord usageRecord1 = new UsageRecord();
    usageRecord1.setAmount(10L);
    usageRecord1.setRecordDate(clock.getUTCToday().minusDays(1));
    final UnitUsageRecord unitUsageRecord = new UnitUsageRecord();
    unitUsageRecord.setUnitType("bullets");
    unitUsageRecord.setUsageRecords(ImmutableList.<UsageRecord>of(usageRecord1));
    final SubscriptionUsageRecord usage = new SubscriptionUsageRecord();
    usage.setSubscriptionId(addOnSubscriptionId);
    usage.setTrackingId(UUID.randomUUID().toString());
    usage.setUnitUsageRecords(ImmutableList.<UnitUsageRecord>of(unitUsageRecord));
    killBillClient.createSubscriptionUsageRecord(usage, createdBy, reason, comment);
    try {
        killBillClient.createSubscriptionUsageRecord(usage, createdBy, reason, comment);
        Assert.fail();
    } catch (final KillBillClientException e) {
        Assert.assertEquals(e.getBillingException().getCode(), (Integer) ErrorCode.USAGE_RECORD_TRACKING_ID_ALREADY_EXISTS.getCode());
    }
}
Also used : Account(org.killbill.billing.client.model.Account) Bundle(org.killbill.billing.client.model.Bundle) UnitUsageRecord(org.killbill.billing.client.model.UnitUsageRecord) SubscriptionUsageRecord(org.killbill.billing.client.model.SubscriptionUsageRecord) UsageRecord(org.killbill.billing.client.model.UsageRecord) UnitUsageRecord(org.killbill.billing.client.model.UnitUsageRecord) KillBillClientException(org.killbill.billing.client.KillBillClientException) Subscription(org.killbill.billing.client.model.Subscription) UUID(java.util.UUID) SubscriptionUsageRecord(org.killbill.billing.client.model.SubscriptionUsageRecord) Predicate(com.google.common.base.Predicate) Test(org.testng.annotations.Test)

Example 45 with Account

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

the class TestPayment method testAuthorizeCompletionUsingPaymentIdAndTransactionExternalKey.

@Test(groups = "slow")
public void testAuthorizeCompletionUsingPaymentIdAndTransactionExternalKey() 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 completeTransactionByPaymentIdAndInvalidTransactionExternalKey = new PaymentTransaction();
    completeTransactionByPaymentIdAndInvalidTransactionExternalKey.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndInvalidTransactionExternalKey.setTransactionExternalKey("bozo");
    try {
        killBillClient.completePayment(completeTransactionByPaymentIdAndInvalidTransactionExternalKey, pluginProperties, requestOptions);
        fail("Payment completion should fail when invalid transaction externalKey has been provided");
    } catch (final KillBillClientException expected) {
    }
    final PaymentTransaction completeTransactionByPaymentIdAndTransactionExternalKey = new PaymentTransaction();
    completeTransactionByPaymentIdAndTransactionExternalKey.setPaymentId(initialPayment.getPaymentId());
    completeTransactionByPaymentIdAndTransactionExternalKey.setTransactionExternalKey(authTransactionExternalKey);
    final Payment completedPaymentByPaymentId = killBillClient.completePayment(completeTransactionByPaymentIdAndTransactionExternalKey, 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)

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