Exemplo n.º 1
0
 @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");
 }
Exemplo n.º 2
0
 @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");
 }
Exemplo n.º 3
0
 @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());
 }
Exemplo n.º 4
0
 @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());
 }
Exemplo n.º 5
0
 @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());
 }
Exemplo n.º 6
0
 @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());
 }
Exemplo n.º 7
0
 @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);
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 @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);
 }
Exemplo n.º 10
0
 @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());
 }
Exemplo n.º 11
0
 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;
 }
Exemplo n.º 12
0
 @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());
 }
Exemplo n.º 13
0
 @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());
 }
Exemplo n.º 14
0
 @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");
 }
Exemplo n.º 15
0
  @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());
  }
Exemplo n.º 16
0
 @Test
 public void testCustomerCreateWithPlanPerCallAPIKey() throws StripeException {
   Plan plan = Plan.create(getUniquePlanParams(), Stripe.apiKey);
   Customer customer = createDefaultCustomerWithPlan(plan);
   assertEquals(customer.getSubscription().getPlan().getId(), plan.getId());
 }
Exemplo n.º 17
0
 @Test
 public void testInvoiceItemCreatePerCallAPIKey() throws StripeException {
   Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey);
   InvoiceItem invoiceItem = createDefaultInvoiceItem(customer);
   assertTrue(invoiceItem.getAmount() == 100);
 }
Exemplo n.º 18
0
 @Test
 public void testCustomerCreatePerCallAPIKey() throws StripeException {
   Customer customer = Customer.create(defaultCustomerParams, Stripe.apiKey);
   assertEquals(customer.getActiveCard().getLast4(), "4242");
 }