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");
}
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");
}
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));
}
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);
}
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");
}
Aggregations