Search in sources :

Example 56 with Customer

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

the class CouponTest method testCustomerCreateWithCouponPerCallAPIKey.

@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());
}
Also used : Coupon(com.stripe.model.Coupon) DeletedCoupon(com.stripe.model.DeletedCoupon) HashMap(java.util.HashMap) Customer(com.stripe.model.Customer) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 57 with Customer

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

the class StripeResponseTest method testResponseIncluded.

@Test
public void testResponseIncluded() throws AuthenticationException, InvalidRequestException, APIException, APIConnectionException, CardException {
    String idempotencyKey = Long.toString(System.currentTimeMillis());
    RequestOptions requestOptions = RequestOptions.builder().setStripeVersion(Stripe.apiVersion).setIdempotencyKey(idempotencyKey).build();
    Customer cus = Customer.create(defaultCustomerParams, requestOptions);
    cus = Customer.retrieve(cus.getId(), requestOptions);
    StripeResponse resp = cus.getLastResponse();
    assertThat(resp, instanceOf(StripeResponse.class));
    assertEquals(200, resp.code());
    assertEquals(idempotencyKey, resp.idempotencyKey());
    assertTrue(resp.requestId().startsWith("req_"));
    assertTrue(resp.body().length() > 0);
}
Also used : RequestOptions(com.stripe.net.RequestOptions) Customer(com.stripe.model.Customer) StripeResponse(com.stripe.net.StripeResponse) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 58 with Customer

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

the class SubscriptionItemTest method testSubscriptionItemRetrieve.

@Test
public void testSubscriptionItemRetrieve() throws StripeException {
    Customer customer = Customer.create(defaultCustomerParams);
    Subscription subscription = createDefaultSubscription(customer);
    SubscriptionItem subscriptionItem = createDefaultSubscriptionItem(subscription);
    SubscriptionItem retrievedSubscriptionItem = SubscriptionItem.retrieve(subscriptionItem.getId());
    assertEquals(subscriptionItem.getId(), retrievedSubscriptionItem.getId());
}
Also used : DeletedSubscriptionItem(com.stripe.model.DeletedSubscriptionItem) SubscriptionItem(com.stripe.model.SubscriptionItem) Customer(com.stripe.model.Customer) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 59 with Customer

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

the class SubscriptionTest method testNewStyleSubscriptionAPI.

@Test
public void testNewStyleSubscriptionAPI() throws StripeException {
    final Plan plan = Plan.create(getUniquePlanParams());
    final Plan plan2 = Plan.create(getUniquePlanParams());
    Customer customer = Customer.create(defaultCustomerParams);
    // Create
    Map<String, Object> subCreateParams = new HashMap<String, Object>();
    subCreateParams.put("plan", plan.getId());
    Subscription sub = customer.createSubscription(subCreateParams);
    assertEquals(plan.getId(), sub.getPlan().getId());
    customer = Customer.retrieve(customer.getId());
    assertEquals(1, customer.getSubscriptions().getData().size());
    assertEquals(sub.getId(), customer.getSubscriptions().getData().get(0).getId());
    // Retrieve
    Subscription retrievedSub = customer.getSubscriptions().retrieve(sub.getId());
    assertEquals(sub.getId(), retrievedSub.getId());
    // List
    CustomerSubscriptionCollection list = customer.getSubscriptions().all(null);
    assertEquals(1, list.getData().size());
    assertEquals(sub.getId(), list.getData().get(0).getId());
    // Update
    Map<String, Object> subUpdateParams = new HashMap<String, Object>();
    subUpdateParams.put("plan", plan2.getId());
    sub = sub.update(subUpdateParams);
    assertEquals(plan2.getId(), sub.getPlan().getId());
    // Cancel
    sub = sub.cancel(null);
    assertNotNull(sub.getCanceledAt());
}
Also used : CustomerSubscriptionCollection(com.stripe.model.CustomerSubscriptionCollection) Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 60 with Customer

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

the class SubscriptionTest method testCreateSubscriptionThroughCollection.

@Test
public void testCreateSubscriptionThroughCollection() throws StripeException {
    Plan plan = Plan.create(getUniquePlanParams());
    Customer customer = Customer.create(defaultCustomerParams);
    // Create
    Map<String, Object> subCreateParams = new HashMap<String, Object>();
    subCreateParams.put("plan", plan.getId());
    Subscription sub = customer.getSubscriptions().create(subCreateParams);
    assertEquals(plan.getId(), sub.getPlan().getId());
    // Verify
    customer = Customer.retrieve(customer.getId());
    assertEquals(1, customer.getSubscriptions().getData().size());
    assertEquals(sub.getId(), customer.getSubscriptions().getData().get(0).getId());
}
Also used : Customer(com.stripe.model.Customer) HashMap(java.util.HashMap) Plan(com.stripe.model.Plan) Subscription(com.stripe.model.Subscription) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Aggregations

Customer (com.stripe.model.Customer)65 Test (org.junit.Test)63 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)60 HashMap (java.util.HashMap)40 DeletedCustomer (com.stripe.model.DeletedCustomer)24 ExternalAccount (com.stripe.model.ExternalAccount)16 Plan (com.stripe.model.Plan)16 Subscription (com.stripe.model.Subscription)15 DeletedExternalAccount (com.stripe.model.DeletedExternalAccount)13 DeletedInvoiceItem (com.stripe.model.DeletedInvoiceItem)10 InvoiceItem (com.stripe.model.InvoiceItem)10 Invoice (com.stripe.model.Invoice)7 Card (com.stripe.model.Card)6 DeletedSubscriptionItem (com.stripe.model.DeletedSubscriptionItem)5 SubscriptionItem (com.stripe.model.SubscriptionItem)5 BaseStripeTest (com.stripe.BaseStripeTest)3 BankAccount (com.stripe.model.BankAccount)3 DeletedBankAccount (com.stripe.model.DeletedBankAccount)3 ExternalAccountCollection (com.stripe.model.ExternalAccountCollection)3 Coupon (com.stripe.model.Coupon)2