killbill-client-java icon indicating copy to clipboard operation
killbill-client-java copied to clipboard

CreateSubscriptionWithAddons always requires product name, product category, billing period

Open galenp opened this issue 8 years ago • 0 comments

Hi Guys,

KB version 0.18.3

The client currently does the following check... which to me makes sense.

public Bundle createSubscriptionWithAddOns(final Iterable<Subscription> subscriptions, final LocalDate requestedDate, final int timeoutSec, final RequestOptions inputOptions) throws KillBillClientException {
        for (final Subscription subscription : subscriptions) {
            if (subscription.getPlanName() == null) {
                Preconditions.checkNotNull(subscription.getProductName(), "Subscription#productName cannot be null");
                Preconditions.checkNotNull(subscription.getProductCategory(), "Subscription#productCategory cannot be null");
                Preconditions.checkNotNull(subscription.getBillingPeriod(), "Subscription#billingPeriod cannot be null");
                Preconditions.checkNotNull(subscription.getPriceList(), "Subscription#priceList cannot be null");
                if (subscription.getProductCategory() == ProductCategory.BASE) {
                    Preconditions.checkNotNull(subscription.getAccountId(), "Account#accountId cannot be null for base subscription");
                }
            }
        }

If no plan name is provided on the passed in subscriptions then ensure Product Name, Product Category, Billing Period are provided.

The implication from the above is that these details could be obtained by the server by looking up the plan if provided.

However in reality if you call the createEntitlementWithAddOns endpoint and don't supply these additional fields (regardless of plan name) you will cop the below error.

2017-03-24T07:46:18,805+0000 lvl='INFO', log='LoggingFilter', th='catalina-exec-4', xff='', rId='a9b9c59d-6dea-46a0-b484-23612321239d', aRId='', tRId='4', 139 * Server in-bound request
139 > POST http://10.1.1.150:8080/1.0/kb/subscriptions/createEntitlementWithAddOns
139 > x-killbill-apikey: pctest2
139 > x-killbill-apisecret: pctest2secret
139 > x-killbill-createdby: Testing User
139 > x-killbill-comment: kill-bill-net-tests
139 > x-killbill-reason: KillBill Api Test
139 > accept: application/json, text/html
139 > authorization: Basic YWRtaW46cGFzc3dvcmQ=
139 > user-agent: RestSharp/105.0.1.0
139 > content-type: application/json
139 > host: 10.1.1.150:8080
139 > content-length: 648
139 > accept-encoding: gzip, deflate
139 > connection: Keep-Alive
139 > 

2017-03-24T07:46:18,813+0000 lvl='WARN', log='JaxRsResourceBase', th='catalina-exec-4', xff='', rId='a9b9c59d-6dea-46a0-b484-23612321239d', aRId='', tRId='4', Parameter requestedDate is being deprecated: Instead use parameters entitlementDate,billingDate
java.lang.NullPointerException
	at org.killbill.billing.jaxrs.resources.SubscriptionResource$2.apply(SubscriptionResource.java:279)
	at org.killbill.billing.jaxrs.resources.SubscriptionResource$2.apply(SubscriptionResource.java:276)
	at com.google.common.collect.Iterators$7.computeNext(Iterators.java:652)
	at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
	at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
	at com.google.common.collect.Iterators.size(Iterators.java:191)
	at com.google.common.collect.Iterables.size(Iterables.java:108)
	at org.killbill.billing.jaxrs.resources.SubscriptionResource.createEntitlementWithAddOns(SubscriptionResource.java:276)
	at org.killbill.commons.skeleton.metrics.TimedResourceInterceptor.invoke(TimedResourceInterceptor.java:67)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)

I personally think the client is correct and that the server is not handling the scenario correctly.

galenp avatar Mar 24 '17 07:03 galenp