@Test public void testCustomerUpdatePerCallAPIKey() throws StripeException { Customer createdCustomer = Customer.create(defaultCustomerParams, Stripe.apiKey); Map<String, Object> updateParams = new HashMap<String, Object>(); updateParams.put("description", "Updated Description"); Customer updatedCustomer = createdCustomer.update(updateParams, Stripe.apiKey); assertEquals(updatedCustomer.getDescription(), "Updated Description"); }
@Test public void testCancelSubscriptionPerCallAPIKey() throws StripeException { Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey); Customer customer = createDefaultCustomerWithPlan(plan); assertEquals(customer.getSubscription().getStatus(), "active"); Subscription canceledSubscription = customer.cancelSubscription(Stripe.apiKey); assertEquals(canceledSubscription.getStatus(), "canceled"); }
@Test public void testUpcomingInvoicePerCallAPIKey() throws Exception { Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey); createDefaultInvoiceItem(customer); Map<String, Object> upcomingParams = new HashMap<String, Object>(); upcomingParams.put("customer", customer.getId()); Invoice upcomingInvoice = Invoice.upcoming(upcomingParams, Stripe.apiKey); assertFalse(upcomingInvoice.getAttempted()); }
@Test public void testUpdateSubscriptionPerCallAPIKey() throws StripeException { Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey); Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey); Map<String, Object> subscriptionParams = new HashMap<String, Object>(); subscriptionParams.put("plan", plan.getId()); Subscription sub = customer.updateSubscription(subscriptionParams, Stripe.apiKey); assertEquals(sub.getPlan().getId(), plan.getId()); assertEquals(sub.getCustomer(), customer.getId()); }
@Test public void testInvoiceRetrieveForCustomerPerCallAPIKey() throws StripeException { Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey); Customer customer = createDefaultCustomerWithPlan(plan); Map<String, Object> listParams = new HashMap<String, Object>(); listParams.put("customer", customer.getId()); listParams.put("count", 1); Invoice invoice = Invoice.all(listParams, Stripe.apiKey).getData().get(0); assertEquals(invoice.getCustomer(), customer.getId()); }
@Test public void testCustomerRetrievePerCallAPIKey() throws StripeException { Customer createdCustomer = Customer.create(defaultCustomerParams, Stripe.apiKey); Customer retrievedCustomer = Customer.retrieve(createdCustomer.getId()); assertEquals(createdCustomer.getCreated(), retrievedCustomer.getCreated()); assertEquals(createdCustomer.getId(), retrievedCustomer.getId()); }
@Test public void testCancelSubscriptionAtPeriodEndPerCallAPIKey() throws StripeException { Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey); Customer customer = createDefaultCustomerWithPlan(plan); assertEquals(customer.getSubscription().getStatus(), "active"); Map<String, Object> cancelParams = new HashMap<String, Object>(); cancelParams.put("at_period_end", true); Subscription canceledSubscription = customer.cancelSubscription(cancelParams, Stripe.apiKey); assertEquals(canceledSubscription.getStatus(), "active"); assertEquals(canceledSubscription.getCancelAtPeriodEnd(), true); }
static InvoiceItem createDefaultInvoiceItem(Customer customer) throws StripeException { Map<String, Object> invoiceItemParams = new HashMap<String, Object>(); invoiceItemParams.put("amount", 100); invoiceItemParams.put("currency", "usd"); invoiceItemParams.put("customer", customer.getId()); return InvoiceItem.create(invoiceItemParams); }
@Test public void testCustomerListPerCallAPIKey() throws StripeException { Map<String, Object> listParams = new HashMap<String, Object>(); listParams.put("count", 1); List<Customer> Customers = Customer.all(listParams, Stripe.apiKey).getData(); assertEquals(Customers.size(), 1); }
@Test public void testInvoiceItemRetrieve() throws StripeException { Customer customer = Customer.create(defaultCustomerParams); InvoiceItem createdInvoiceItem = createDefaultInvoiceItem(customer); InvoiceItem retrievedInvoiceItem = InvoiceItem.retrieve(createdInvoiceItem.getId()); assertEquals(createdInvoiceItem.getId(), retrievedInvoiceItem.getId()); }
static Customer createDefaultCustomerWithPlan(Plan plan) throws StripeException { Map<String, Object> customerWithPlanParams = new HashMap<String, Object>(); customerWithPlanParams.putAll(defaultCustomerParams); customerWithPlanParams.put("plan", plan.getId()); Customer customer = Customer.create(customerWithPlanParams); return customer; }
@Test public void testCustomerDeletePerCallAPIKey() throws StripeException { Customer createdCustomer = Customer.create(defaultCustomerParams, Stripe.apiKey); DeletedCustomer deletedCustomer = createdCustomer.delete(Stripe.apiKey); Customer deletedRetrievedCustomer = Customer.retrieve(createdCustomer.getId(), Stripe.apiKey); assertTrue(deletedCustomer.getDeleted()); assertEquals(deletedCustomer.getId(), createdCustomer.getId()); assertTrue(deletedRetrievedCustomer.getDeleted()); }
@Test public void testInvoiceItemDeletePerCallAPIKey() throws StripeException { Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey); InvoiceItem createdInvoiceItem = createDefaultInvoiceItem(customer); DeletedInvoiceItem deletedInvoiceItem = createdInvoiceItem.delete(Stripe.apiKey); assertTrue(deletedInvoiceItem.getDeleted()); assertEquals(deletedInvoiceItem.getId(), createdInvoiceItem.getId()); }
@Test public void testInvoiceItemUpdatePerCallAPIKey() throws StripeException { Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey); InvoiceItem createdInvoiceItem = createDefaultInvoiceItem(customer); Map<String, Object> updateParams = new HashMap<String, Object>(); updateParams.put("description", "Updated Description"); updateParams.put("amount", 200); InvoiceItem updatedInvoiceItem = createdInvoiceItem.update(updateParams, Stripe.apiKey); assertTrue(updatedInvoiceItem.getAmount() == 200); assertEquals(updatedInvoiceItem.getDescription(), "Updated Description"); }
@Test public void testCustomerCreateWithCouponPerCallAPIKey() throws StripeException { Coupon coupon = Coupon.create(getUniqueCouponParams(), Stripe.apiKey); Map<String, Object> customerWithCouponParams = new HashMap<String, Object>(); customerWithCouponParams.put("coupon", coupon.getId()); Customer customer = Customer.create(customerWithCouponParams, Stripe.apiKey); assertEquals(customer.getDiscount().getCoupon().getId(), coupon.getId()); customer.deleteDiscount(); assertNull(Customer.retrieve(customer.getId()).getDiscount()); }
@Test public void testCustomerCreateWithPlanPerCallAPIKey() throws StripeException { Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey); Customer customer = createDefaultCustomerWithPlan(plan); assertEquals(customer.getSubscription().getPlan().getId(), plan.getId()); }
@Test public void testInvoiceItemCreatePerCallAPIKey() throws StripeException { Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey); InvoiceItem invoiceItem = createDefaultInvoiceItem(customer); assertTrue(invoiceItem.getAmount() == 100); }
@Test public void testCustomerCreatePerCallAPIKey() throws StripeException { Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey); assertEquals(customer.getActiveCard().getLast4(), "4242"); }