Skip to content

Commit

Permalink
Merge pull request #481 from recurly/Add-proration-support
Browse files Browse the repository at this point in the history
Add proration support to subscription update
  • Loading branch information
douglasmiller authored May 7, 2024
2 parents 447356b + a422e80 commit 940e0ae
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2010-2014 Ning, Inc.
* Copyright 2014-2015 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.ning.billing.recurly.model;

import com.google.common.base.Objects;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
* Class that represents ProrationSettings details in the Recurly API.
*/
@XmlRootElement(name = "proration_settings")
public class ProrationSettings extends RecurlyObject {

@XmlElement(name = "credit")
private String credit;

@XmlElement(name = "charge")
private String charge;

public String getCharge() {
return charge;
}

public void setCharge(final Object charge) {
this.charge = stringOrNull(charge);
}

public String getCredit() {
return credit;
}

public void setCredit(final Object credit) {
this.credit = stringOrNull(credit);
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("ProrationSettings");
sb.append("{ charge='").append(charge).append('\'');
sb.append(", credit='").append(credit).append('\'');
sb.append(" }");
return sb.toString();
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

final ProrationSettings proration_settings = (ProrationSettings) o;

if (charge != null ? !charge.equals(proration_settings.charge) : proration_settings.charge != null) {
return false;
}

if (credit != null ? !credit.equals(proration_settings.credit) : proration_settings.credit != null) {
return false;
}

return true;
}

@Override
public int hashCode() {
return Objects.hashCode(
charge,
credit
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static enum Timeframe {
@XmlElement(name = "shipping_address")
private ShippingAddress shippingAddress;

@XmlElement(name = "proration_settings")
private ProrationSettings prorationSettings;

@XmlElement(name = "shipping_address_id")
private Long shippingAddressId;

Expand Down Expand Up @@ -94,6 +97,14 @@ public void setRampIntervals(final SubscriptionRampIntervals rampIntervals) {
this.rampIntervals = rampIntervals;
}

public ProrationSettings getProrationSettings() {
return prorationSettings;
}

public void setProrationSettings(final ProrationSettings prorationSettings) {
this.prorationSettings = prorationSettings;
}

public Timeframe getTimeframe() {
return timeframe;
}
Expand Down Expand Up @@ -280,6 +291,7 @@ public int hashCode() {
billingInfoUuid,
customFields,
netTerms,
prorationSettings,
netTermsType,
poNumber,
revenueScheduleType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,37 @@ public void testSerializationWithoutAddOns() throws Exception {
"</subscription>");
}

@Test(groups = "fast")
public void testSerializationWithProrationFlexibility() throws Exception {
final ProrationSettings prorationSettings = new ProrationSettings();
prorationSettings.setCredit("full_amount");
prorationSettings.setCharge("none");

final SubscriptionUpdate subscription = new SubscriptionUpdate();
subscription.setPlanCode("gold");
subscription.setTimeframe(SubscriptionUpdate.Timeframe.now);
subscription.setUnitAmountInCents(800);
subscription.setQuantity(1);
subscription.setBillingInfoUuid("uniqueUuid");
subscription.setProrationSettings(prorationSettings);

final String xml = xmlMapper.writeValueAsString(subscription);
Assert.assertEquals(xml, "<subscription xmlns=\"\">" +
"<timeframe>now</timeframe>" +
"<unit_amount_in_cents>800</unit_amount_in_cents>" +
"<quantity>1</quantity>" +
"<plan_code>gold</plan_code>" +
"<proration_settings>" +
"<credit>full_amount</credit>" +
"<charge>none</charge>" +
"</proration_settings>" +
"<billing_info_uuid>uniqueUuid</billing_info_uuid>" +
"</subscription>");

Assert.assertEquals(subscription.getProrationSettings().toString(),
"ProrationSettings{ charge='none', credit='full_amount' }");
}

@Test(groups = "fast")
public void testSerializationWithEmptyAddOns() throws Exception {
final SubscriptionUpdate subscription = new SubscriptionUpdate();
Expand Down

0 comments on commit 940e0ae

Please sign in to comment.