Mercurial Hosting > luan
comparison stripe/src/luan/modules/stripe/Stripe.luan @ 407:7fd9f1b7b878
replace LuanPropertyTable with LuanPropertyMeta
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 29 Apr 2015 13:01:00 -0600 |
parents | 62b457c50594 |
children | 56c23aa70045 |
comparison
equal
deleted
inserted
replaced
406:9321a33b9b1c | 407:7fd9f1b7b878 |
---|---|
1 java() | 1 java() |
2 local Luan = require "luan:Luan" | 2 local Luan = require "luan:Luan" |
3 local error = Luan.error | 3 local error = Luan.error |
4 local assert_integer = Luan.assert_integer | 4 local assert_integer = Luan.assert_integer |
5 local StripeLuan = require "java:luan.modules.stripe.StripeLuan" | 5 local Table = require "luan:Table" |
6 local Stripe = require "java:com.stripe.Stripe" | 6 local Stripe = require "java:com.stripe.Stripe" |
7 local Customer = require "java:com.stripe.model.Customer" | 7 local Customer = require "java:com.stripe.model.Customer" |
8 local Charge = require "java:com.stripe.model.Charge" | 8 local Charge = require "java:com.stripe.model.Charge" |
9 | 9 |
10 currency = "usd" | 10 currency = "usd" |
11 | 11 |
12 function init(api_key) | 12 function init(api_key) |
13 Stripe.apiKey = api_key | 13 Stripe.apiKey = api_key |
14 end | 14 end |
15 | 15 |
16 | |
17 local function customer_table(java_customer) | |
18 | |
19 local function subscription() | |
20 local list = java_customer.getSubscriptions().getData() | |
21 local size = list.size() | |
22 size <= 1 or error "more than 1 subscription" | |
23 return size == 1 and list.get(0) or nil | |
24 end | |
25 | |
26 local this = Table.new_property_table() | |
27 local meta = Luan.get_metatable(this) | |
28 | |
29 meta.get.id = java_customer.getId | |
30 | |
31 function meta.get.subscription_status() | |
32 local s = subscription() | |
33 return s and s.getStatus() | |
34 end | |
35 | |
36 return this | |
37 end | |
38 | |
39 | |
40 local function charge_table(java_charge) | |
41 local this = Table.new_property_table() | |
42 local meta = Luan.get_metatable(this) | |
43 | |
44 meta.get.id = java_charge.getId | |
45 meta.get.amount = java_charge.getAmount | |
46 | |
47 return this | |
48 end | |
49 | |
50 | |
16 function create_customer(params) | 51 function create_customer(params) |
17 local java_customer = Customer.create(params) | 52 local java_customer = Customer.create(params) |
18 return StripeLuan.table(java_customer) | 53 return customer_table(java_customer) |
19 end | 54 end |
20 | 55 |
21 function retrieve_customer(id) | 56 function retrieve_customer(id) |
22 local java_customer = Customer.retrieve(id) | 57 local java_customer = Customer.retrieve(id) |
23 return StripeLuan.table(java_customer) | 58 return customer_table(java_customer) |
24 end | 59 end |
25 | 60 |
26 function create_charge(params) | 61 function create_charge(params) |
27 params.amount or error "missing parameter 'amount'" | 62 params.amount or error "missing parameter 'amount'" |
28 params.amount = assert_integer(params.amount) | 63 params.amount = assert_integer(params.amount) |
29 params.currency = params.currency or currency | 64 params.currency = params.currency or currency |
30 local java_charge = Charge.create(params) | 65 local java_charge = Charge.create(params) |
31 return StripeLuan.table(java_charge) | 66 return charge_table(java_charge) |
32 end | 67 end |
68 | |
69 -- http://javadox.com/com.stripe/stripe-java/1.2.1/overview-summary.html |