@JsonRequest @ProtectEndpoint(writeOperation = true, requiresProject = false) @Path("/plans") public List<RakamPlan> listPlans(@javax.inject.Named("user_id") UIPermissionParameterProvider.Project project) { Optional<WebUser> webUser = service.getUser(project.userId); if (!webUser.isPresent()) { throw new RakamException(FORBIDDEN); } try { return Plan.list(ImmutableMap.of("limit", 50), requestOptions).getData().stream() .map(e -> new RakamPlan(e.getId(), e.getName(), e.getAmount(), e.getStatementDescriptor())) .collect(Collectors.toList()); } catch (Exception e) { throw Throwables.propagate(e); } }
/** * Create a plan. */ public static Plan create(Map<String, Object> params) throws StripeException { return create(params, (RequestOptions) null); }
/** * Delete a plan. */ public Plan delete() throws StripeException { return delete((RequestOptions) null); }
/** * List all plans. */ public static PlanCollection list(Map<String, Object> params, RequestOptions options) throws StripeException { return requestCollection(classUrl(Plan.class), params, PlanCollection.class, options); } // </editor-fold>
@Test public void testDelete() throws StripeException { final Plan plan = getPlanFixture(); final Plan deletedPlan = plan.delete(); assertNotNull(deletedPlan); assertTrue(deletedPlan.getDeleted()); verifyRequest( ApiResource.RequestMethod.DELETE, String.format("/v1/plans/%s", plan.getId()) ); }
/** * List all plans. */ public static PlanCollection list(Map<String, Object> params) throws StripeException { return list(params, null); }
@Test public void testUpdate() throws StripeException { final Plan plan = getPlanFixture(); final Map<String, Object> params = new HashMap<>(); params.put("name", "Updated Name"); final Plan updatedPlan = plan.update(params); assertNotNull(updatedPlan); verifyRequest( ApiResource.RequestMethod.POST, String.format("/v1/plans/%s", plan.getId()), params ); }
@Test public void testDeserialize() throws Exception { final String data = getFixture("/v1/plans/gold"); final Plan plan = ApiResource.GSON.fromJson(data, Plan.class); assertNotNull(plan); assertNotNull(plan.getId()); assertEquals("plan", plan.getObject()); assertNull(plan.getProductObject()); }
/** * Retrieve a plan. */ public static Plan retrieve(String id) throws StripeException { return retrieve(id, (RequestOptions) null); }
/** * Update a plan. */ @Override public Plan update(Map<String, Object> params) throws StripeException { return update(params, (RequestOptions) null); }
@Test public void testDeserialize() throws Exception { final String data = getResourceAsString("/api_fixtures/event_plan.json"); final Event event = ApiResource.GSON.fromJson(data, Event.class); assertNotNull(event); assertNotNull(event.getId()); assertEquals("event", event.getObject()); final Plan plan = (Plan) event.getData().getObject(); assertNotNull(plan); assertNotNull(plan.getId()); }
@Test public void testList() throws StripeException { final Map<String, Object> params = new HashMap<>(); params.put("limit", 1); PlanCollection plans = Plan.list(params); assertNotNull(plans); verifyRequest( ApiResource.RequestMethod.GET, "/v1/plans", params ); } }
/** * Retrieve a plan. */ public static Plan retrieve(String id, RequestOptions options) throws StripeException { return retrieve(id, null, options); }
private Plan getPlanFixture() throws StripeException { final Plan plan = Plan.retrieve(PLAN_ID); resetNetworkSpy(); return plan; }
@Test public void testCreate() throws StripeException { final Map<String, Object> params = new HashMap<>(); params.put("amount", 1); params.put("currency", "usd"); params.put("id", "sapphire-elite"); params.put("interval", "month"); params.put("name", "Sapphire Elite"); final Plan plan = Plan.create(params); assertNotNull(plan); verifyRequest( ApiResource.RequestMethod.POST, "/v1/plans", params ); }
@Test public void testRetrieve() throws StripeException { final Plan plan = Plan.retrieve(PLAN_ID); assertNotNull(plan); verifyRequest( ApiResource.RequestMethod.GET, String.format("/v1/plans/%s", PLAN_ID) ); }