Permalink
Browse files

go

  • Loading branch information...
1 parent 1129bba commit c89e82679bb92a178ddebac3f542fa433e3636a1 @jamescarr committed Oct 8, 2010
Showing with 88 additions and 0 deletions.
  1. +24 −0 docs/chargify.md
  2. +15 −0 lib/chargify/client.js
  3. +49 −0 spec/unit/chargify-client.spec.js
View
@@ -54,6 +54,30 @@ This is a rough cut... hopefully the full API will be implemented soon! Let me k
// something with each product, see the docs for structure
})
})
+
+## Transactions
+(Coming Soon)
+
+## Charges
+(Coming Soon)
+
+## Refunds
+(Coming Soon)
+
+## Credits
+(Coming Soon)
+
+## Metered Usage
+
+### Recording a usage
+Recording a usage is a matter of calling client.usage.create([subscription], [component], [usage]), where the subscription and component are objects representing both (although all that is needed is ids). This
+makes it convenient if you have references to a subscription and component on hand. Otherwise you can just do it literally:
+ client.usage.create({id:33}, {id:22}, {usage:{quantity:10, memo:'databases in use'}})
+ .on('success', successHandler)
+ .on('failure', failureHandler)
+
+
+
## License
(The MIT License)
View
@@ -73,6 +73,21 @@ function Client(httpClient){
httpClient.get('/products/handle/'+handle+'.json', "", callback(this))
})
}
+
+ this.transactions = {
+ list:emit(function(params){
+ httpClient.get('/transactions.json' + (params? '?'+querystring.encode(params):''), "", callback(this))
+ }),
+ listForSubscription:emit(function(subscription, params){
+ httpClient.get('/subscriptions/'+subscription.id+'/transactions.json' + (params? '?'+querystring.encode(params):''), "", callback(this))
+ })
+ }
+
+ this.usage = {
+ create:emit(function(subscription, component, usage){
+ httpClient.post('/subscriptions/'+subscription.id+'/components/'+component.id+'/usages.json', JSON.stringify(usage), callback(this))
+ })
+ }
}
function SimpleHttpClient(username, password, host){
@@ -138,6 +138,55 @@ vows.describe('client api').addBatch({
path:'/subscriptions/93.json',
body:''
})
+ },
+ 'Transactions':{
+
+ 'list':{
+ 'with no params':calls(function(){
+ return client.transactions.list()
+ }).andExpects({
+ method:'get',
+ path:'/transactions.json',
+ body:''
+ }),
+ 'with optional params':calls(function(){
+ return client.transactions.list({kinds:['credit', 'charge'], max_id:22})
+ }).andExpects({
+ method:'get',
+ path:'/transactions.json?kinds%5B%5D=credit&kinds%5B%5D=charge&max_id=22',
+ body:''
+ })
+ },
+ 'list transactions for a subscription':{
+ 'with no params':calls(function(){
+ return client.transactions.listForSubscription({id:33})
+ }).andExpects({
+ method:'get',
+ path:'/subscriptions/33/transactions.json',
+ body:''
+ }),
+ 'with optional params':calls(function(){
+ return client.transactions.listForSubscription({id:33}, {kinds:['charge'], page:2})
+ }).andExpects({
+ method:'get',
+ path:'/subscriptions/33/transactions.json?kinds%5B%5D=charge&page=2',
+ body:''
+ })
+ },
+ 'Usage':{
+ 'create':calls(function(){
+ return client.usage.create({id:43}, {id:30}, {
+ usage:{
+ quantity:5,
+ memo:'Five gigs used'
+ }
+ })
+ }).andExpects({
+ method:'post',
+ path:'/subscriptions/43/components/30/usages.json',
+ body:JSON.stringify({usage:{quantity:5, memo:'Five gigs used'}})
+ })
+ }
}
}).export(module);

0 comments on commit c89e826

Please sign in to comment.