comparison stripe/src/luan/modules/stripe/StripeLuan.java @ 402:62b457c50594

add stripe; change Luan.values to only return values, not indexes;
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 28 Apr 2015 22:38:31 -0600
parents
children
comparison
equal deleted inserted replaced
401:322c03d85ada 402:62b457c50594
1 package luan.modules.stripe;
2
3 import luan.Luan;
4 import luan.LuanTable;
5 import luan.LuanProperty;
6 import com.stripe.model.Customer;
7 import com.stripe.model.Charge;
8 import com.stripe.model.Subscription;
9 import java.util.List;
10
11
12 public final class StripeLuan {
13
14 public static LuanTable table(final Customer customer) {
15
16 LuanTable tbl = Luan.newPropertyTable();
17
18 tbl.put( "id", new LuanProperty() {
19 @Override public Object get() {
20 return customer.getId();
21 }
22 } );
23
24 tbl.put( "subscription_status", new LuanProperty() {
25 @Override public Object get() {
26 Subscription s = getSubscription(customer);
27 return s==null ? null : s.getStatus();
28 }
29 } );
30
31 return tbl;
32 }
33
34 public static LuanTable table(final Charge charge) {
35 LuanTable tbl = Luan.newPropertyTable();
36
37 tbl.put( "id", new LuanProperty() {
38 @Override public Object get() {
39 return charge.getId();
40 }
41 } );
42
43 tbl.put( "amount", new LuanProperty() {
44 @Override public Object get() {
45 return charge.getAmount();
46 }
47 /*
48 @Override public boolean set(Object value) {
49 charge.setAmount(check_integer(value)); return true;
50 }
51 */
52 } );
53
54 return tbl;
55 }
56
57 public static Subscription getSubscription(Customer customer) {
58 List<Subscription> list = customer.getSubscriptions().getData();
59 switch(list.size()) {
60 case 0:
61 return null;
62 case 1:
63 return list.get(0);
64 default:
65 throw new RuntimeException("more than 1 subscription");
66 }
67 }
68 /*
69 private static Integer check_integer(Object value) {
70 if( value==null )
71 return (Integer)null;
72 Integer i = Luan.asInteger(value);
73 if( i==null )
74 throw new IllegalArgumentException("value must be an integer");
75 return i;
76 }
77 */
78 }
79
80 // http://javadox.com/com.stripe/stripe-java/1.2.1/overview-summary.html