Failed to remove subscription's add-ons #23

Closed
oohira opened this Issue Dec 20, 2013 · 2 comments

Comments

Projects
None yet
2 participants
@oohira
Contributor

oohira commented Dec 20, 2013

I wrote following Java code to update a subscription from plan A (with add-ons) to plan B (without add-ons).

SubscriptionUpdate subscriptionUpdate = new SubscriptionUpdate();
subscriptionUpdate.setPlanCode("plan-01");
subscriptionUpdate.setTimeframe(SubscriptionUpdate.Timeframe.now);
...
recurlyClient.updateSubscription(subscriptionUuid, subscriptionUpdate);

And following XML was sent to Recurly.

<subscription> 
    <plan_code>plan-01</plan_code> 
    <timeframe>now</timeframe> 
</subscription>

According to API Documents (https://docs.recurly.com/api/subscriptions/subscription-add-ons), add-ons should be removed when <subscription_add_ons> element is not specified. However, Recurly returned an error like this.

<errors> 
    <error field="subscription.subscription_add_ons[add_on_code=Team_User_01].add_on" symbol="invalid">is invalid</error> 
</errors>

By trial and error, I found that <subscription_add_ons> element is required. So following request was accepted, and add-ons were removed expectedly.

<subscription> 
    <plan_code>ind-01</plan_code> 
    <timeframe>now</timeframe> 
    <subscription_add_ons type="array" /> 
</subscription>

To output the empty <subscription_add_ons> element, I tried following Java code. Unfortunately, this resulted in a wrong XML.

SubscriptionUpdate subscriptionUpdate = new SubscriptionUpdate();
subscriptionUpdate.setPlanCode("plan-01");
subscriptionUpdate.setTimeframe(SubscriptionUpdate.Timeframe.now);
subscriptionUpdate.setAddOns(new SubscriptionAddOns()); // <- ADDED
...
recurlyClient.updateSubscription(subscriptionUuid, subscriptionUpdate);
<subscription xmlns="">
    <plan_code>ind-01</plan_code> 
    <timeframe>now</timeframe> 
    <subscription_add_ons>
        <subscription_add_on>
            <startUrl/><prevUrl/><nextUrl/><nbRecords/><start/><next/><prev/><empty>true</empty>
        </subscription_add_on>
    </subscription_add_ons>
</subscription>

Is there any workaround of this problem?

FYI: Another language binding like python has a method to set an empty add-ons. Following code is quoted from Recurly's API Doc sample.

#
#Remove all add-ons
#
subscription.subscription_add_ons = []

@ghost ghost assigned pierre Dec 22, 2013

@pierre pierre closed this in 5e654bf Dec 22, 2013

@pierre

This comment has been minimized.

Show comment
Hide comment
@pierre

pierre Dec 22, 2013

Member

Thank you for the detailed bug report, it definitively helped narrowing down the bug.

I have pushed a fix on master, could you give it a try?

The code below should work now:

SubscriptionUpdate subscriptionUpdate = new SubscriptionUpdate();
subscriptionUpdate.setPlanCode("plan-01");
subscriptionUpdate.setTimeframe(SubscriptionUpdate.Timeframe.now);
subscriptionUpdate.setAddOns(new SubscriptionAddOns());
recurlyClient.updateSubscription(subscriptionUuid, subscriptionUpdate);
Member

pierre commented Dec 22, 2013

Thank you for the detailed bug report, it definitively helped narrowing down the bug.

I have pushed a fix on master, could you give it a try?

The code below should work now:

SubscriptionUpdate subscriptionUpdate = new SubscriptionUpdate();
subscriptionUpdate.setPlanCode("plan-01");
subscriptionUpdate.setTimeframe(SubscriptionUpdate.Timeframe.now);
subscriptionUpdate.setAddOns(new SubscriptionAddOns());
recurlyClient.updateSubscription(subscriptionUuid, subscriptionUpdate);

oohira added a commit to oohira/recurly-java-library that referenced this issue Dec 24, 2013

@oohira

This comment has been minimized.

Show comment
Hide comment
@oohira

oohira Dec 25, 2013

Contributor

I confirmed the bug fix, and added some test code #24. Thank you.

Contributor

oohira commented Dec 25, 2013

I confirmed the bug fix, and added some test code #24. Thank you.

pierre added a commit that referenced this issue Dec 27, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment