Search in sources :

Example 16 with Subscription

use of com.stripe.model.Subscription 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)

Aggregations

BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)16 Subscription (com.stripe.model.Subscription)16 Test (org.junit.Test)16 Customer (com.stripe.model.Customer)15 Plan (com.stripe.model.Plan)11 HashMap (java.util.HashMap)11 SubscriptionItem (com.stripe.model.SubscriptionItem)6 DeletedSubscriptionItem (com.stripe.model.DeletedSubscriptionItem)5 CustomerSubscriptionCollection (com.stripe.model.CustomerSubscriptionCollection)2 SubscriptionCollection (com.stripe.model.SubscriptionCollection)1 SubscriptionItemCollection (com.stripe.model.SubscriptionItemCollection)1 UsageRecord (com.stripe.model.UsageRecord)1