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());
}
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);
}
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());
}
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());
}
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());
}
Aggregations