Search in sources :

Example 1 with Product

use of com.stripe.model.Product 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 2 with Product

use of com.stripe.model.Product 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 3 with Product

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

the class ServiceProductTest method testProductUpdate.

@Test
public void testProductUpdate() throws StripeException {
    Product product = Product.create(defaultServiceProductParams);
    HashMap<String, Object> updateParams = new HashMap<>();
    updateParams.put("name", "New name not like the old name");
    updateParams.put("statement_descriptor", "NEW AND IMPROVED");
    Product updatedProduct = product.update(updateParams);
    assertEquals("New name not like the old name", updatedProduct.getName());
    assertEquals("NEW AND IMPROVED", updatedProduct.getStatementDescriptor());
}
Also used : HashMap(java.util.HashMap) Product(com.stripe.model.Product) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Example 4 with Product

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

the class ServiceProductTest method testProductCreate.

@Test
public void testProductCreate() throws StripeException {
    Product product = Product.create(defaultServiceProductParams);
    assertNotNull(product.getId());
    assertEquals("service", product.getType());
    assertEquals(defaultServiceProductParams.get("name"), product.getName());
    assertEquals(defaultServiceProductParams.get("statement_descriptor"), product.getStatementDescriptor());
}
Also used : Product(com.stripe.model.Product) BaseStripeFunctionalTest(com.stripe.BaseStripeFunctionalTest) Test(org.junit.Test)

Aggregations

BaseStripeFunctionalTest (com.stripe.BaseStripeFunctionalTest)4 Product (com.stripe.model.Product)4 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 DeletedProduct (com.stripe.model.DeletedProduct)2 RequestOptions (com.stripe.net.RequestOptions)2 DeletedSKU (com.stripe.model.DeletedSKU)1 SKU (com.stripe.model.SKU)1