Search in sources :

Example 1 with StripeResponse

use of com.stripe.net.StripeResponse in project stripe-java by stripe.

the class StripeResponseTest method testResponseIncludedList.

@Test
public void testResponseIncludedList() throws AuthenticationException, InvalidRequestException, APIException, APIConnectionException, CardException {
    CustomerCollection cusCollection = Customer.list(new HashMap<String, Object>());
    StripeResponse resp = cusCollection.getLastResponse();
    assertThat(resp, instanceOf(StripeResponse.class));
    assertEquals(200, resp.code());
    assertTrue(resp.requestId().startsWith("req_"));
    assertTrue(resp.body().length() > 0);
}
Also used : CustomerCollection(com.stripe.model.CustomerCollection) StripeResponse(com.stripe.net.StripeResponse) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 2 with StripeResponse

use of com.stripe.net.StripeResponse in project stripe-java by stripe.

the class StripeResponseTest method testGetIdempotencyKey.

@Test
public void testGetIdempotencyKey() {
    Map<String, List<String>> headerMap = generateHeaderMap();
    StripeResponse stripeResponse = new StripeResponse(200, chargeBody, headerMap);
    assertEquals("12345", stripeResponse.idempotencyKey());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) StripeResponse(com.stripe.net.StripeResponse) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Example 3 with StripeResponse

use of com.stripe.net.StripeResponse in project stripe-java by stripe.

the class StripeResponseTest method testRequestId.

@Test
public void testRequestId() {
    Map<String, List<String>> headerMap = generateHeaderMap();
    StripeResponse stripeResponse = new StripeResponse(200, chargeBody, headerMap);
    assertEquals(stripeResponse.requestId(), "req_12345");
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) StripeResponse(com.stripe.net.StripeResponse) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Example 4 with StripeResponse

use of com.stripe.net.StripeResponse in project stripe-java by stripe.

the class StripeResponseTest method testNoHeaders.

@Test
public void testNoHeaders() {
    StripeResponse stripeResponse = new StripeResponse(200, chargeBody);
    assertEquals(stripeResponse.headers(), null);
    assertEquals(stripeResponse.idempotencyKey(), null);
    assertEquals(stripeResponse.requestId(), null);
}
Also used : StripeResponse(com.stripe.net.StripeResponse) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Example 5 with StripeResponse

use of com.stripe.net.StripeResponse 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)

Aggregations

StripeResponse (com.stripe.net.StripeResponse)8 Test (org.junit.Test)8 BaseStripeTest (com.stripe.BaseStripeTest)6 ArrayList (java.util.ArrayList)3 List (java.util.List)3 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)2 Customer (com.stripe.model.Customer)1 CustomerCollection (com.stripe.model.CustomerCollection)1 RequestOptions (com.stripe.net.RequestOptions)1 StripeHeaders (com.stripe.net.StripeHeaders)1