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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations