Search in sources :

Example 6 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetInvoicePayment() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    // Getting Invoice #2 (first after Trial period)
    UUID failedInvoiceId = killBillClient.getInvoicesForAccount(account.getAccountId(), false, false, RequestOptions.empty()).get(1).getInvoiceId();
    HashMultimap<String, String> queryParams = HashMultimap.create();
    queryParams.put("withAttempts", "true");
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
    InvoicePayments invoicePayments = killBillClient.getInvoicePayment(failedInvoiceId, inputOptions);
    Assert.assertEquals(invoicePayments.get(0).getTargetInvoiceId(), failedInvoiceId);
    Assert.assertNotNull(invoicePayments.get(0).getPaymentAttempts());
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().size(), 2);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
    // Remove the future notification and check SCHEDULED does not appear any longer
    killBillClient.cancelScheduledPaymentTransaction(null, invoicePayments.get(0).getPaymentAttempts().get(1).getTransactionExternalKey(), inputOptions);
    invoicePayments = killBillClient.getInvoicePayment(failedInvoiceId, inputOptions);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().size(), 1);
    Assert.assertEquals(invoicePayments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
}
Also used : Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) UUID(java.util.UUID) Test(org.testng.annotations.Test)

Example 7 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestPayment method testDeletePaymentMethodWithAutoPayOff.

@Test(groups = "slow")
public void testDeletePaymentMethodWithAutoPayOff() throws Exception {
    final Account account = createAccountWithDefaultPaymentMethod();
    final UUID paymentMethodId = account.getPaymentMethodId();
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).build();
    killBillClient.deletePaymentMethod(paymentMethodId, true, false, inputOptions);
    Tags accountTags = killBillClient.getAccountTags(account.getAccountId(), inputOptions);
    Assert.assertNotNull(accountTags);
    Assert.assertEquals(accountTags.get(0).getTagDefinitionName(), "AUTO_PAY_OFF");
}
Also used : Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) UUID(java.util.UUID) Tags(org.killbill.billing.client.model.Tags) Test(org.testng.annotations.Test)

Example 8 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestCache method testInvalidateCacheByTenant.

@Test(groups = "slow", description = "Can Invalidate (clear) all Tenant Caches for current Tenant")
public void testInvalidateCacheByTenant() throws Exception {
    // creating a new Tenant for this test
    final String testApiKey = "testApiKey";
    final String testApiSecret = "testApiSecret";
    final Tenant tenant = new Tenant();
    tenant.setApiKey(testApiKey);
    tenant.setApiSecret(testApiSecret);
    loginTenant(testApiKey, testApiSecret);
    Tenant currentTenant = killBillClient.createTenant(tenant, false, requestOptions);
    // using custom RequestOptions with the new Tenant created before
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withTenantApiKey(currentTenant.getApiKey()).withTenantApiSecret(currentTenant.getApiSecret()).build();
    // Uploading the test catalog using the new Tenant created before
    killBillClient.uploadXMLCatalog(Resources.getResource("SpyCarAdvanced.xml").getPath(), inputOptions);
    // creating an Account with PaymentMethod and a Subscription
    createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoiceWithInputOptions(inputOptions);
    // get all caches per tenant level
    final Ehcache tenantRecordIdCache = cacheManager.getEhcache(CacheType.TENANT_RECORD_ID.getCacheName());
    final Ehcache tenantPaymentStateMachineConfigCache = cacheManager.getEhcache(CacheType.TENANT_PAYMENT_STATE_MACHINE_CONFIG.getCacheName());
    final Ehcache tenantCache = cacheManager.getEhcache(CacheType.TENANT.getCacheName());
    final Ehcache tenantKvCache = cacheManager.getEhcache(CacheType.TENANT_KV.getCacheName());
    final Ehcache tenantConfigCache = cacheManager.getEhcache(CacheType.TENANT_CONFIG.getCacheName());
    final Ehcache tenantOverdueConfigCache = cacheManager.getEhcache(CacheType.TENANT_OVERDUE_CONFIG.getCacheName());
    final Ehcache tenantCatalogCache = cacheManager.getEhcache(CacheType.TENANT_CATALOG.getCacheName());
    // getting current Tenant's record Id from the specific Cache
    Long tenantRecordId = (Long) tenantRecordIdCache.get(currentTenant.getTenantId().toString()).getObjectValue();
    // verify that they are not null and have the expected tenant information
    assertNotNull(tenantRecordIdCache);
    assertNotNull(tenantRecordIdCache.get(currentTenant.getTenantId().toString()));
    assertNotNull(tenantPaymentStateMachineConfigCache);
    assertTrue(hasKeysByTenantRecordId(tenantPaymentStateMachineConfigCache, tenantRecordId.toString()));
    assertNotNull(tenantCache);
    assertNotNull(tenantCache.get(testApiKey));
    assertNotNull(tenantKvCache);
    assertTrue(hasKeysByTenantRecordId(tenantKvCache, tenantRecordId.toString()));
    assertNotNull(tenantConfigCache);
    assertNotNull(tenantConfigCache.get(tenantRecordId));
    assertNotNull(tenantOverdueConfigCache);
    assertNotNull(tenantOverdueConfigCache.get(tenantRecordId));
    assertNotNull(tenantCatalogCache);
    assertNotNull(tenantCatalogCache.get(tenantRecordId));
    // invalidate caches per tenant level
    killBillClient.invalidateCacheByTenant(inputOptions);
    // verify that now the caches don't have the previous values
    Assert.assertNull(tenantRecordIdCache.get(currentTenant.getTenantId().toString()));
    assertFalse(hasKeysByTenantRecordId(tenantPaymentStateMachineConfigCache, tenantRecordId.toString()));
    Assert.assertNull(tenantCache.get(testApiKey));
    assertFalse(hasKeysByTenantRecordId(tenantKvCache, tenantRecordId.toString()));
    Assert.assertNull(tenantConfigCache.get(tenantRecordId));
    Assert.assertNull(tenantOverdueConfigCache.get(tenantRecordId));
    Assert.assertNull(tenantCatalogCache.get(tenantRecordId));
}
Also used : Tenant(org.killbill.billing.client.model.Tenant) RequestOptions(org.killbill.billing.client.RequestOptions) Ehcache(net.sf.ehcache.Ehcache) Test(org.testng.annotations.Test)

Example 9 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestCatalog method testAddSimplePlanWithoutKBDefault.

@Test(groups = "slow", description = "Upload and retrieve a per plugin payment state machine config")
public void testAddSimplePlanWithoutKBDefault() throws Exception {
    // Create another tenant initialized with no default catalog,...
    final Tenant otherTenantNoKBDefault = new Tenant();
    otherTenantNoKBDefault.setApiKey(UUID.randomUUID().toString());
    otherTenantNoKBDefault.setApiSecret(UUID.randomUUID().toString());
    killBillClient.createTenant(otherTenantNoKBDefault, false, requestOptions);
    final RequestOptions requestOptionsOtherTenant = requestOptions.extend().withTenantApiKey(otherTenantNoKBDefault.getApiKey()).withTenantApiSecret(otherTenantNoKBDefault.getApiSecret()).build();
    // Verify the template catalog is not returned
    List<Catalog> catalogsJson = killBillClient.getJSONCatalog(requestOptionsOtherTenant);
    Assert.assertEquals(catalogsJson.size(), 0);
    killBillClient.addSimplePan(new SimplePlan("foo-monthly", "Foo", ProductCategory.BASE, Currency.USD, BigDecimal.TEN, BillingPeriod.MONTHLY, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of()), requestOptionsOtherTenant);
    catalogsJson = killBillClient.getJSONCatalog(requestOptionsOtherTenant);
    Assert.assertEquals(catalogsJson.size(), 1);
    Assert.assertEquals(catalogsJson.get(0).getProducts().size(), 1);
    Assert.assertEquals(catalogsJson.get(0).getProducts().get(0).getName(), "Foo");
    Assert.assertEquals(catalogsJson.get(0).getPriceLists().size(), 1);
    Assert.assertEquals(catalogsJson.get(0).getPriceLists().get(0).getName(), "DEFAULT");
    Assert.assertEquals(catalogsJson.get(0).getPriceLists().get(0).getPlans().size(), 1);
    Assert.assertEquals(catalogsJson.get(0).getPriceLists().get(0).getPlans().get(0), "foo-monthly");
    killBillClient.addSimplePan(new SimplePlan("foo-annual", "Foo", ProductCategory.BASE, Currency.USD, new BigDecimal("100.00"), BillingPeriod.ANNUAL, 0, TimeUnit.UNLIMITED, ImmutableList.<String>of()), requestOptionsOtherTenant);
    catalogsJson = killBillClient.getJSONCatalog(requestOptionsOtherTenant);
    Assert.assertEquals(catalogsJson.size(), 1);
    Assert.assertEquals(catalogsJson.get(0).getProducts().size(), 1);
    Assert.assertEquals(catalogsJson.get(0).getProducts().get(0).getName(), "Foo");
    Assert.assertEquals(catalogsJson.get(0).getPriceLists().size(), 1);
    Assert.assertEquals(catalogsJson.get(0).getPriceLists().get(0).getName(), "DEFAULT");
    Assert.assertEquals(catalogsJson.get(0).getPriceLists().get(0).getPlans().size(), 2);
}
Also used : SimplePlan(org.killbill.billing.client.model.SimplePlan) Tenant(org.killbill.billing.client.model.Tenant) RequestOptions(org.killbill.billing.client.RequestOptions) Catalog(org.killbill.billing.client.model.Catalog) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test)

Example 10 with RequestOptions

use of org.killbill.billing.client.RequestOptions in project killbill by killbill.

the class TestPayment method testWithFailedPaymentAndScheduledAttemptsGetPaymentsForAccount.

@Test(groups = "slow")
public void testWithFailedPaymentAndScheduledAttemptsGetPaymentsForAccount() throws Exception {
    mockPaymentProviderPlugin.makeNextPaymentFailWithError();
    final Account account = createAccountWithPMBundleAndSubscriptionAndWaitForFirstInvoice();
    HashMultimap<String, String> queryParams = HashMultimap.create();
    queryParams.put("withAttempts", "true");
    RequestOptions inputOptions = RequestOptions.builder().withCreatedBy(createdBy).withReason(reason).withComment(comment).withQueryParams(queryParams).build();
    Payments payments = killBillClient.getPaymentsForAccount(account.getAccountId(), inputOptions);
    Assert.assertNotNull(payments.get(0).getPaymentAttempts());
    Assert.assertEquals(payments.get(0).getPaymentAttempts().get(0).getStateName(), "RETRIED");
    Assert.assertEquals(payments.get(0).getPaymentAttempts().get(1).getStateName(), "SCHEDULED");
}
Also used : Account(org.killbill.billing.client.model.Account) RequestOptions(org.killbill.billing.client.RequestOptions) Payments(org.killbill.billing.client.model.Payments) InvoicePayments(org.killbill.billing.client.model.InvoicePayments) Test(org.testng.annotations.Test)

Aggregations

RequestOptions (org.killbill.billing.client.RequestOptions)12 Test (org.testng.annotations.Test)9 Account (org.killbill.billing.client.model.Account)5 InvoicePayments (org.killbill.billing.client.model.InvoicePayments)4 UUID (java.util.UUID)3 Payments (org.killbill.billing.client.model.Payments)3 Tenant (org.killbill.billing.client.model.Tenant)3 BigDecimal (java.math.BigDecimal)2 KillBillClientException (org.killbill.billing.client.KillBillClientException)2 Payment (org.killbill.billing.client.model.Payment)2 PaymentTransaction (org.killbill.billing.client.model.PaymentTransaction)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Ehcache (net.sf.ehcache.Ehcache)1 AccountTimeline (org.killbill.billing.client.model.AccountTimeline)1 Catalog (org.killbill.billing.client.model.Catalog)1 ComboPaymentTransaction (org.killbill.billing.client.model.ComboPaymentTransaction)1 SimplePlan (org.killbill.billing.client.model.SimplePlan)1 Tags (org.killbill.billing.client.model.Tags)1 TenantKey (org.killbill.billing.client.model.TenantKey)1 TransactionType (org.killbill.billing.payment.api.TransactionType)1