コード例 #1
0
 private void verifySubscriptionAddons(final Subscription subscription) {
   Assert.assertEquals(subscription.getAddOns().size(), 2);
   Assert.assertEquals(subscription.getAddOns().get(0).getAddOnCode(), "extra_users");
   Assert.assertEquals(subscription.getAddOns().get(0).getQuantity(), (Integer) 2);
   Assert.assertEquals(subscription.getAddOns().get(0).getUnitAmountInCents(), (Integer) 1000);
   Assert.assertEquals(subscription.getAddOns().get(1).getAddOnCode(), "extra_ip");
   Assert.assertEquals(subscription.getAddOns().get(1).getQuantity(), (Integer) 3);
   Assert.assertEquals(subscription.getAddOns().get(1).getUnitAmountInCents(), (Integer) 200);
 }
コード例 #2
0
  @Test(groups = "fast")
  public void testDeserialization() throws Exception {
    // See http://docs.recurly.com/api/subscriptions
    final String subscriptionData =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            + "<subscription href=\"https://api.recurly.com/v2/subscriptions/44f83d7cba354d5b84812419f923ea96\">\n"
            + "  <account href=\"https://api.recurly.com/v2/accounts/1\"/>\n"
            + "  <plan href=\"https://api.recurly.com/v2/plans/gold\">\n"
            + "    <plan_code>gold</plan_code>\n"
            + "    <name>Gold plan</name>\n"
            + "  </plan>\n"
            + "  <uuid>44f83d7cba354d5b84812419f923ea96</uuid>\n"
            + "  <state>active</state>\n"
            + "  <unit_amount_in_cents type=\"integer\">800</unit_amount_in_cents>\n"
            + "  <currency>EUR</currency>\n"
            + "  <quantity type=\"integer\">1</quantity>\n"
            + "  <activated_at type=\"datetime\">2011-05-27T07:00:00Z</activated_at>\n"
            + "  <canceled_at nil=\"nil\"></canceled_at>\n"
            + "  <expires_at nil=\"nil\"></expires_at>\n"
            + "  <current_period_started_at type=\"datetime\">2011-06-27T07:00:00Z</current_period_started_at>\n"
            + "  <current_period_ends_at type=\"datetime\">2010-07-27T07:00:00Z</current_period_ends_at>\n"
            + "  <trial_started_at nil=\"nil\"></trial_started_at>\n"
            + "  <trial_ends_at nil=\"nil\"></trial_ends_at>\n"
            + "  <starts_at>2010-07-28T07:00:00Z</starts_at>\n"
            + "  <a name=\"cancel\" href=\"https://api.recurly.com/v2/subscriptions/44f83d7cba354d5b84812419f923ea96/cancel\" method=\"put\"/>\n"
            + "  <a name=\"terminate\" href=\"https://api.recurly.com/v2/subscriptions/44f83d7cba354d5b84812419f923ea96/terminate\" method=\"put\"/>\n"
            + "  <a name=\"postpone\" href=\"https://api.recurly.com/v2/subscriptions/44f83d7cba354d5b84812419f923ea96/postpone\" method=\"put\"/>\n"
            + "  <collection_method>manual</collection_method>\n"
            + "  <net_terms type=\"integer\">10</net_terms>\n"
            + "  <po_number>PO19384</po_number>\n"
            + "  <first_renewal_date type=\"datetime\">2011-07-01T07:00:00Z</first_renewal_date>\n"
            + "  <subscription_add_ons type=\"array\">\n"
            + "  </subscription_add_ons>\n"
            + "  <pending_subscription type=\"subscription\">\n"
            + "    <plan href=\"https://api.recurly.com/v2/plans/silver\">\n"
            + "      <plan_code>silver</plan_code>\n"
            + "      <name>Silver plan</name>\n"
            + "    </plan>\n"
            + "    <unit_amount_in_cents type=\"integer\">400</unit_amount_in_cents>\n"
            + "    <quantity type=\"integer\">1</quantity>\n"
            + "    <subscription_add_ons type=\"array\">\n"
            + "    </subscription_add_ons>\n"
            + "  </pending_subscription>\n"
            + "</subscription>";

    final Subscription subscription = verifySubscription(subscriptionData);
    verifyPaginationData(subscription);
    verifyPendingSubscription(subscription);
    Assert.assertEquals(subscription.getAddOns().size(), 0);
  }
コード例 #3
0
 /**
  * Terminate a particular {@link Subscription} by it's UUID
  *
  * @param subscription Subscription to terminate
  */
 public void terminateSubscription(final Subscription subscription, final RefundOption refund) {
   doPUT(
       Subscription.SUBSCRIPTION_RESOURCE
           + "/"
           + subscription.getUuid()
           + "/terminate?refund="
           + refund,
       subscription,
       Subscription.class);
 }
コード例 #4
0
 private void verifyPendingSubscription(final Subscription subscription) {
   Subscription pending = subscription.getPendingSubscription();
   Assert.assertEquals(pending.getPlan().getPlanCode(), "silver");
   Assert.assertEquals(pending.getPlan().getName(), "Silver plan");
   Assert.assertEquals(pending.getUnitAmountInCents(), (Integer) 400);
   Assert.assertEquals(pending.getQuantity(), (Integer) 1);
   Assert.assertEquals(pending.getAddOns().size(), 0);
 }
コード例 #5
0
 private void verifyPaginationData(final Subscription subscription) {
   // Verify nested attributes
   Assert.assertEquals(
       subscription.getAccount().getHref(), "https://api.recurly.com/v2/accounts/1");
   Assert.assertEquals(subscription.getAccount().getAccountCode(), "1");
 }
コード例 #6
0
  private Subscription verifySubscription(final String subscriptionData) throws IOException {
    final Subscription subscription = xmlMapper.readValue(subscriptionData, Subscription.class);
    Assert.assertEquals(subscription.getUuid(), "44f83d7cba354d5b84812419f923ea96");
    Assert.assertEquals(subscription.getState(), "active");
    Assert.assertEquals(subscription.getUnitAmountInCents(), (Integer) 800);
    Assert.assertEquals(subscription.getCurrency(), "EUR");
    Assert.assertEquals(subscription.getQuantity(), (Integer) 1);
    Assert.assertEquals(subscription.getActivatedAt(), new DateTime("2011-05-27T07:00:00Z"));
    Assert.assertNull(subscription.getCanceledAt(), "");
    Assert.assertNull(subscription.getExpiresAt(), "");
    Assert.assertEquals(
        subscription.getCurrentPeriodStartedAt(), new DateTime("2011-06-27T07:00:00Z"));
    Assert.assertEquals(
        subscription.getCurrentPeriodEndsAt(), new DateTime("2010-07-27T07:00:00Z"));
    Assert.assertNull(subscription.getTrialStartedAt(), "");
    Assert.assertNull(subscription.getTrialEndsAt(), "");
    Assert.assertEquals(subscription.getStartsAt(), new DateTime("2010-07-28T07:00:00Z"));
    Assert.assertEquals(subscription.getCollectionMethod(), "manual");
    Assert.assertEquals(subscription.getNetTerms(), (Integer) 10);
    Assert.assertEquals(subscription.getPoNumber(), "PO19384");
    Assert.assertEquals(subscription.getFirstRenewalDate(), new DateTime("2011-07-01T07:00:00Z"));

    return subscription;
  }
コード例 #7
0
 /**
  * Reactivating a canceled subscription
  *
  * <p>Reactivate a canceled subscription so it renews at the end of the current bill cycle.
  *
  * @param subscription Subscription object
  * @return -?-
  */
 public Subscription reactivateSubscription(final Subscription subscription) {
   return doPUT(
       Subscription.SUBSCRIPTION_RESOURCE + "/" + subscription.getUuid() + "/reactivate",
       subscription,
       Subscription.class);
 }
コード例 #8
0
 /**
  * Cancel a subscription
  *
  * <p>Cancel a subscription so it remains active and then expires at the end of the current bill
  * cycle.
  *
  * @param subscription Subscription object
  * @return -?-
  */
 public Subscription cancelSubscription(final Subscription subscription) {
   return doPUT(
       Subscription.SUBSCRIPTION_RESOURCE + "/" + subscription.getUuid() + "/cancel",
       subscription,
       Subscription.class);
 }