Search in sources :

Example 6 with RequestOptions

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

the class RelayTest method testSKUCreateReadUpdate.

@Test
public void testSKUCreateReadUpdate() throws StripeException {
    final RequestOptions relayRequestOptions = RequestOptions.builder().setApiKey("sk_test_JieJALRz7rPz7boV17oMma7a").build();
    Map<String, Object> productCreateParams = new HashMap<String, Object>();
    String productId = "my_first_product_" + UUID.randomUUID();
    productCreateParams.put("id", productId);
    productCreateParams.put("type", "good");
    productCreateParams.put("name", "Watermelon");
    productCreateParams.put("attributes[]", "size");
    Product.create(productCreateParams, relayRequestOptions);
    Map<String, Object> skuCreateParams = new HashMap<String, Object>();
    String skuId = "my_first_sku_" + UUID.randomUUID();
    skuCreateParams.put("id", skuId);
    skuCreateParams.put("product", productId);
    skuCreateParams.put("attributes", ImmutableMap.of("size", "large"));
    skuCreateParams.put("price", 100);
    skuCreateParams.put("currency", "usd");
    skuCreateParams.put("inventory", ImmutableMap.of("type", "infinite"));
    SKU created = SKU.create(skuCreateParams, relayRequestOptions);
    assertEquals(skuId, created.getId());
    assertEquals(productId, created.getProduct());
    assertEquals("large", created.getAttributes().get("size"));
    assertEquals("infinite", created.getInventory().getType());
    SKU retrieved = SKU.retrieve(skuId, relayRequestOptions);
    assertEquals("large", retrieved.getAttributes().get("size"));
    SKU updated = retrieved.update(ImmutableMap.<String, Object>of("price", 200), relayRequestOptions);
    assertEquals((Integer) 200, updated.getPrice());
}
Also used : RequestOptions(com.stripe.net.RequestOptions) HashMap(java.util.HashMap) SKU(com.stripe.model.SKU) DeletedSKU(com.stripe.model.DeletedSKU) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 7 with RequestOptions

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

the class RelayTest method testOrderCreateReadUpdatePayReturn.

@Test
public void testOrderCreateReadUpdatePayReturn() throws StripeException {
    final RequestOptions relayRequestOptions = RequestOptions.builder().setApiKey("sk_test_JieJALRz7rPz7boV17oMma7a").build();
    Map<String, Object> productCreateParams = new HashMap<String, Object>();
    String productId = "my_first_product_" + UUID.randomUUID();
    productCreateParams.put("id", productId);
    productCreateParams.put("type", "good");
    productCreateParams.put("name", "Watermelon");
    productCreateParams.put("attributes[]", "size");
    productCreateParams.put("shippable", false);
    Product.create(productCreateParams, relayRequestOptions);
    Map<String, Object> skuCreateParams = new HashMap<String, Object>();
    String skuId = "my_first_sku_" + UUID.randomUUID();
    skuCreateParams.put("id", skuId);
    skuCreateParams.put("product", productId);
    skuCreateParams.put("attributes", ImmutableMap.of("size", "large"));
    skuCreateParams.put("price", 100);
    skuCreateParams.put("currency", "usd");
    skuCreateParams.put("inventory", ImmutableMap.of("type", "infinite"));
    SKU.create(skuCreateParams, relayRequestOptions);
    Map<String, Object> orderCreateParams = new HashMap<String, Object>();
    orderCreateParams.put("items[]", ImmutableMap.<String, Object>of("type", "sku", "parent", skuId));
    orderCreateParams.put("currency", "usd");
    orderCreateParams.put("email", "foo@bar.com");
    Order created = Order.create(orderCreateParams, relayRequestOptions);
    assertEquals("created", created.getStatus());
    OrderItem item = null;
    for (OrderItem i : created.getItems()) {
        if (skuId.equals(i.getParent())) {
            item = i;
            break;
        }
    }
    assertNotNull(item);
    assertEquals("sku", item.getType());
    final Order retrieved = Order.retrieve(created.getId(), relayRequestOptions);
    item = null;
    for (OrderItem i : created.getItems()) {
        if (skuId.equals(i.getParent())) {
            item = i;
            break;
        }
    }
    assertNotNull(item);
    assertEquals("sku", item.getType());
    Order updated = retrieved.update(ImmutableMap.<String, Object>of("metadata", ImmutableMap.of("foo", "bar")), relayRequestOptions);
    assertEquals("bar", updated.getMetadata().get("foo"));
    Order paid = updated.pay(ImmutableMap.<String, Object>of("source", "tok_visa"), relayRequestOptions);
    assertEquals("paid", paid.getStatus());
    OrderReturn returned = paid.returnOrder(null, relayRequestOptions);
    assertEquals(paid.getId(), returned.getOrder());
}
Also used : Order(com.stripe.model.Order) RequestOptions(com.stripe.net.RequestOptions) HashMap(java.util.HashMap) OrderItem(com.stripe.model.OrderItem) OrderReturn(com.stripe.model.OrderReturn) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 8 with RequestOptions

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

the class RelayTest method testSKUProductDeletion.

@Test
public void testSKUProductDeletion() throws StripeException {
    final RequestOptions relayRequestOptions = RequestOptions.builder().setApiKey("sk_test_JieJALRz7rPz7boV17oMma7a").build();
    Map<String, Object> productCreateParams = new HashMap<String, Object>();
    String productId = "my_first_product_" + UUID.randomUUID();
    productCreateParams.put("id", productId);
    productCreateParams.put("type", "good");
    productCreateParams.put("name", "Watermelon");
    productCreateParams.put("attributes[]", "size");
    final Product createdProduct = Product.create(productCreateParams, relayRequestOptions);
    Map<String, Object> skuCreateParams = new HashMap<String, Object>();
    String skuId = "my_first_sku_" + UUID.randomUUID();
    skuCreateParams.put("id", skuId);
    skuCreateParams.put("product", productId);
    skuCreateParams.put("attributes", ImmutableMap.of("size", "large"));
    skuCreateParams.put("price", 100);
    skuCreateParams.put("currency", "usd");
    skuCreateParams.put("inventory", ImmutableMap.of("type", "infinite"));
    SKU created = SKU.create(skuCreateParams, relayRequestOptions);
    DeletedSKU deletedSKU = created.delete(relayRequestOptions);
    assertTrue(deletedSKU.getDeleted());
    DeletedProduct deletedProduct = createdProduct.delete(relayRequestOptions);
    assertTrue(deletedProduct.getDeleted());
}
Also used : DeletedSKU(com.stripe.model.DeletedSKU) RequestOptions(com.stripe.net.RequestOptions) HashMap(java.util.HashMap) DeletedProduct(com.stripe.model.DeletedProduct) Product(com.stripe.model.Product) SKU(com.stripe.model.SKU) DeletedSKU(com.stripe.model.DeletedSKU) DeletedProduct(com.stripe.model.DeletedProduct) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 9 with RequestOptions

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

the class RelayTest method testProductCreateReadUpdate.

@Test
public void testProductCreateReadUpdate() throws StripeException {
    RequestOptions relayRequestOptions = RequestOptions.builder().setApiKey("sk_test_JieJALRz7rPz7boV17oMma7a").build();
    Map<String, Object> createParams = new HashMap<String, Object>();
    String id = "my_first_product_" + UUID.randomUUID();
    createParams.put("id", id);
    createParams.put("type", "good");
    createParams.put("name", "Watermelon");
    Product created = Product.create(createParams, relayRequestOptions);
    assertEquals(id, created.getId());
    assertEquals("Watermelon", created.getName());
    Product retrieved = Product.retrieve(id, relayRequestOptions);
    assertEquals("Watermelon", retrieved.getName());
    Product updated = retrieved.update(ImmutableMap.<String, Object>of("name", "Cantelope"), relayRequestOptions);
    assertEquals("Cantelope", updated.getName());
}
Also used : RequestOptions(com.stripe.net.RequestOptions) HashMap(java.util.HashMap) DeletedProduct(com.stripe.model.DeletedProduct) Product(com.stripe.model.Product) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 10 with RequestOptions

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

the class SourceTest method testSourceCreateRead.

@Test
public void testSourceCreateRead() throws StripeException {
    final RequestOptions sourceRequestOptions = RequestOptions.builder().setApiKey("sk_test_JieJALRz7rPz7boV17oMma7a").build();
    Map<String, Object> ownerParams = new HashMap<String, Object>();
    ownerParams.put("email", "payinguser+fill_now@example.com");
    Map<String, Object> sourceCreateParams = new HashMap<String, Object>();
    sourceCreateParams.put("type", "bitcoin");
    sourceCreateParams.put("currency", "usd");
    sourceCreateParams.put("amount", 1000);
    sourceCreateParams.put("owner", ownerParams);
    Source created = Source.create(sourceCreateParams, sourceRequestOptions);
    assertEquals("bitcoin", created.getType());
    assertEquals("receiver", created.getFlow());
    // TODO: It's obviously very unpleasant to have all strings
    // here. The plan is to type-check these once any method makes
    // it to public beta. For now, unfortunately, the user will have
    // to actually cast the data to what they want.
    assertEquals(0, Long.parseLong(created.getTypeData().get("amount_charged")));
    Source retrieved = Source.retrieve(created.getId(), sourceRequestOptions);
    assertEquals(created.getId(), retrieved.getId());
}
Also used : RequestOptions(com.stripe.net.RequestOptions) HashMap(java.util.HashMap) Source(com.stripe.model.Source) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Aggregations

RequestOptions (com.stripe.net.RequestOptions)37 Test (org.junit.Test)16 HashMap (java.util.HashMap)14 BaseStripeTest (com.stripe.BaseStripeTest)13 Charge (com.stripe.model.Charge)12 BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)11 Test (org.junit.jupiter.api.Test)10 RequestOptionsBuilder (com.stripe.net.RequestOptions.RequestOptionsBuilder)4 PaymentInformation (alfio.model.PaymentInformation)3 StripeResponse (com.stripe.net.StripeResponse)3 Balance (com.stripe.model.Balance)2 DeletedProduct (com.stripe.model.DeletedProduct)2 DeletedSKU (com.stripe.model.DeletedSKU)2 EphemeralKey (com.stripe.model.EphemeralKey)2 Product (com.stripe.model.Product)2 Refund (com.stripe.model.Refund)2 SKU (com.stripe.model.SKU)2 FeeCalculator (alfio.manager.support.FeeCalculator)1 PaymentResult (alfio.manager.support.PaymentResult)1 ConfigurationManager (alfio.manager.system.ConfigurationManager)1