use of com.stripe.model.SKU 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());
}
use of com.stripe.model.SKU 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());
}
Aggregations