Search in sources :

Example 1 with RequestOptionsBuilder

use of com.stripe.net.RequestOptions.RequestOptionsBuilder in project stripe-java by stripe.

the class PagingIteratorTest method testAutoPaginationWithParams.

@Test
public void testAutoPaginationWithParams() throws IOException, StripeException {
    // set some arbitrary parameters so that we can verify that the
    // parameters passed to autoPagingIterable() override the initial
    // collection parameters
    Map<String, Object> page0Params = new HashMap<String, Object>();
    page0Params.put("foo", "bar");
    Map<String, Object> autoPagingParams = new HashMap<String, Object>();
    autoPagingParams.put("foo", "baz");
    Map<String, Object> page1Params = new HashMap<String, Object>();
    page1Params.put("foo", "baz");
    page1Params.put("starting_after", "pm_124");
    Map<String, Object> page2Params = new HashMap<String, Object>();
    page2Params.put("foo", "baz");
    page2Params.put("starting_after", "pm_126");
    RequestOptions options = (new RequestOptionsBuilder()).setApiKey("sk_paging_key").build();
    PageableModelCollection collection = PageableModel.list(page0Params, options);
    List<PageableModel> models = new ArrayList<PageableModel>();
    for (PageableModel model : collection.autoPagingIterable(autoPagingParams)) {
        models.add(model);
    }
    assertEquals(5, models.size());
    assertEquals("pm_123", models.get(0).getId());
    assertEquals("pm_124", models.get(1).getId());
    assertEquals("pm_125", models.get(2).getId());
    assertEquals("pm_126", models.get(3).getId());
    assertEquals("pm_127", models.get(4).getId());
    verifyGet(PageableModelCollection.class, "https://api.stripe.com/v1/pageablemodels", page0Params, options);
    verifyGet(PageableModelCollection.class, "https://api.stripe.com/v1/pageablemodels", page1Params, options);
    verifyGet(PageableModelCollection.class, "https://api.stripe.com/v1/pageablemodels", page2Params, options);
    verifyNoMoreInteractions(networkMock);
}
Also used : HashMap(java.util.HashMap) RequestOptions(com.stripe.net.RequestOptions) RequestOptionsBuilder(com.stripe.net.RequestOptions.RequestOptionsBuilder) ArrayList(java.util.ArrayList) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Example 2 with RequestOptionsBuilder

use of com.stripe.net.RequestOptions.RequestOptionsBuilder in project stripe-java by stripe.

the class LiveStripeResponseGetterTest method testAppInfo.

@Test
public void testAppInfo() {
    RequestOptions options = (new RequestOptionsBuilder()).setApiKey("sk_foobar").build();
    Stripe.setAppInfo("MyAwesomePlugin", "1.2.34", "https://myawesomeplugin.info");
    Map<String, String> headers = LiveStripeResponseGetter.getHeaders(options);
    String expectedUserAgent = String.format("Stripe/v1 JavaBindings/%s MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)", Stripe.VERSION);
    assertEquals(expectedUserAgent, headers.get("User-Agent"));
    Gson gson = new Gson();
    Map<String, String> uaMap = gson.fromJson(headers.get("X-Stripe-Client-User-Agent"), new TypeToken<Map<String, String>>() {
    }.getType());
    assertNotNull(uaMap.get("application"));
    Map<String, String> appMap = gson.fromJson(uaMap.get("application"), new TypeToken<Map<String, String>>() {
    }.getType());
    assertEquals("MyAwesomePlugin", appMap.get("name"));
    assertEquals("1.2.34", appMap.get("version"));
    assertEquals("https://myawesomeplugin.info", appMap.get("url"));
}
Also used : RequestOptions(com.stripe.net.RequestOptions) TypeToken(com.google.gson.reflect.TypeToken) RequestOptionsBuilder(com.stripe.net.RequestOptions.RequestOptionsBuilder) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 3 with RequestOptionsBuilder

use of com.stripe.net.RequestOptions.RequestOptionsBuilder in project stripe-java by stripe.

the class AccountTest method testOverloadedSingleArgumentRetrieve.

@Test
public void testOverloadedSingleArgumentRetrieve() throws StripeException {
    Account.retrieve("sk_foobar");
    RequestOptions options = (new RequestOptionsBuilder()).setApiKey("sk_foobar").build();
    verifyGet(Account.class, "https://api.stripe.com/v1/account", options);
    Account.retrieve("anything_else");
    verifyGet(Account.class, "https://api.stripe.com/v1/accounts/anything_else");
    verifyNoMoreInteractions(networkMock);
}
Also used : RequestOptions(com.stripe.net.RequestOptions) RequestOptionsBuilder(com.stripe.net.RequestOptions.RequestOptionsBuilder) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Example 4 with RequestOptionsBuilder

use of com.stripe.net.RequestOptions.RequestOptionsBuilder in project stripe-java by stripe.

the class PagingIteratorTest method testAutoPagination.

@Test
public void testAutoPagination() throws IOException, StripeException {
    // set some arbitrary parameters so that we can verify that they're
    // used for requests on ALL pages
    Map<String, Object> page0Params = new HashMap<String, Object>();
    page0Params.put("foo", "bar");
    Map<String, Object> page1Params = new HashMap<String, Object>();
    page1Params.put("foo", "bar");
    page1Params.put("starting_after", "pm_124");
    Map<String, Object> page2Params = new HashMap<String, Object>();
    page2Params.put("foo", "bar");
    page2Params.put("starting_after", "pm_126");
    RequestOptions options = (new RequestOptionsBuilder()).setApiKey("sk_paging_key").build();
    PageableModelCollection collection = PageableModel.list(page0Params, options);
    List<PageableModel> models = new ArrayList<PageableModel>();
    for (PageableModel model : collection.autoPagingIterable()) {
        models.add(model);
    }
    assertEquals(5, models.size());
    assertEquals("pm_123", models.get(0).getId());
    assertEquals("pm_124", models.get(1).getId());
    assertEquals("pm_125", models.get(2).getId());
    assertEquals("pm_126", models.get(3).getId());
    assertEquals("pm_127", models.get(4).getId());
    verifyGet(PageableModelCollection.class, "https://api.stripe.com/v1/pageablemodels", page0Params, options);
    verifyGet(PageableModelCollection.class, "https://api.stripe.com/v1/pageablemodels", page1Params, options);
    verifyGet(PageableModelCollection.class, "https://api.stripe.com/v1/pageablemodels", page2Params, options);
    verifyNoMoreInteractions(networkMock);
}
Also used : HashMap(java.util.HashMap) RequestOptions(com.stripe.net.RequestOptions) RequestOptionsBuilder(com.stripe.net.RequestOptions.RequestOptionsBuilder) ArrayList(java.util.ArrayList) BaseStripeTest(com.stripe.BaseStripeTest) Test(org.junit.Test)

Aggregations

RequestOptions (com.stripe.net.RequestOptions)4 RequestOptionsBuilder (com.stripe.net.RequestOptions.RequestOptionsBuilder)4 Test (org.junit.Test)4 BaseStripeTest (com.stripe.BaseStripeTest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1