Search in sources :

Example 6 with SubscriptionItem

use of com.stripe.model.SubscriptionItem in project stripe-java by stripe.

the class UsageRecordTest method testUsageRecordCreate.

@Test
public void testUsageRecordCreate() throws StripeException {
    Plan plan = createMeteredPlan();
    Subscription sub = createSubscription(plan);
    SubscriptionItem subItem = sub.getSubscriptionItems().getData().get(0);
    Map<String, Object> params = new HashMap<>();
    params.put("quantity", 1000);
    long unixTime = System.currentTimeMillis() / 1000L;
    params.put("timestamp", unixTime);
    params.put("subscription_item", subItem.getId());
    UsageRecord ur = UsageRecord.create(params, null);
    assertEquals(new Long(1000), ur.getQuantity());
    assertEquals(new Long(unixTime), ur.getTimestamp());
}
Also used : SubscriptionItem(com.stripe.model.SubscriptionItem) HashMap(java.util.HashMap) UsageRecord(com.stripe.model.UsageRecord) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 7 with SubscriptionItem

use of com.stripe.model.SubscriptionItem in project stripe-java by stripe.

the class SubscriptionItemTest method testDelete.

@Test
public void testDelete() throws StripeException {
    SubscriptionItem item = new SubscriptionItem();
    item.setId("test_item");
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("prorate", false);
    item.delete(params);
    verifyDelete(DeletedSubscriptionItem.class, "https://api.stripe.com/v1/subscription_items/test_item", params);
    verifyNoMoreInteractions(networkMock);
}
Also used : SubscriptionItem(com.stripe.model.SubscriptionItem) HashMap(java.util.HashMap) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Example 8 with SubscriptionItem

use of com.stripe.model.SubscriptionItem in project stripe-java by stripe.

the class SubscriptionItemTest method testUpdate.

@Test
public void testUpdate() throws StripeException {
    SubscriptionItem item = new SubscriptionItem();
    item.setId("test_item");
    HashMap<String, Object> params = new HashMap<String, Object>();
    params.put("plan", "gold");
    item.update(params);
    verifyPost(SubscriptionItem.class, "https://api.stripe.com/v1/subscription_items/test_item", params);
    verifyNoMoreInteractions(networkMock);
}
Also used : SubscriptionItem(com.stripe.model.SubscriptionItem) HashMap(java.util.HashMap) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Aggregations

SubscriptionItem (com.stripe.model.SubscriptionItem)8 Test (org.junit.Test)8 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)6 Subscription (com.stripe.model.Subscription)6 Customer (com.stripe.model.Customer)5 DeletedSubscriptionItem (com.stripe.model.DeletedSubscriptionItem)5 HashMap (java.util.HashMap)5 BaseStripeTest (com.stripe.BaseStripeTest)2 Plan (com.stripe.model.Plan)1 SubscriptionItemCollection (com.stripe.model.SubscriptionItemCollection)1 UsageRecord (com.stripe.model.UsageRecord)1