stripe-cli 0.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5923ebb4d766facc1a20aa141bbb9b2fa4c20414
4
+ data.tar.gz: ad96a4646bedecc024a25c32d7aa02a227621557
5
+ SHA512:
6
+ metadata.gz: 7d1277e104b7f9c6dd41077715252cad28cc17f200773425167497a479a1609314142c8fd9aad06d156da384c43e5fb78b1938f3fdd4f93cf6193247687a2c43
7
+ data.tar.gz: 2752a182355bde4ba24a4f782ecada84f5911802ff0578761465fcbfcb0976fdcc7e22a3dd5373b812ed2158ae5f9eec2853066ab8ce45382b9aae7094c65411
data/README.md CHANGED
@@ -1,29 +1,196 @@
1
- # Stripe::Cli
1
+ # Stripe::CLI
2
2
 
3
- TODO: Write a gem description
3
+ stripe-cli is a command line interface to [Stripe](https://stripe.com).
4
+
5
+ Uses [AwesomePrint](https://github.com/michaeldv/awesome_print) to provide very readable output on your command line.
6
+
7
+ ![example output](./output.png)
8
+
9
+ Note that all JSON-style epoch timestamps have been converted to **real life** DateTime stamps, your welcome!
4
10
 
5
11
  ## Installation
6
12
 
7
- Add this line to your application's Gemfile:
13
+ $ gem install stripe-cli
8
14
 
9
- gem 'stripe-cli'
15
+ Actually, the gem version is extremely stale right now. I hope to be able to update it soon. Until then, there are a couple of <strike>hacks</strike> options available.
10
16
 
11
- And then execute:
17
+ 1) clone the repo and build the gem locally yourself
12
18
 
13
- $ bundle
19
+ $ git clone https://github.com/stripe-contrib/stripe-cli.git
20
+ $ cd ./stripe-cli
21
+ $ gem build stripe-cli.gemspec
22
+ $ gem install stripe-cli
14
23
 
15
- Or install it yourself as:
24
+ > because RubyGems looks **first** at the **current directory** before moving on to [rubygems.org](https://rubygems.org), that last step will install the local gem you just built.
16
25
 
17
- $ gem install stripe-cli
26
+
27
+ or
28
+
29
+ 2) bundler can be used to automate this same procedure
30
+
31
+ > in a Gemfile, write:
32
+
33
+ gem 'stripe-cli', :git => 'git@github.com:stripe-contrib/stripe-cli.git'
34
+
35
+
36
+ ## Configuration
37
+
38
+ For authentication, pass your secret key using the `-k` or `--key` option
39
+
40
+ $ stripe events list -k XXXXXXXXXXXXXXXXXXXXXX
41
+
42
+ To use a specific api version, pass in the `-v` or `--version` option
43
+
44
+ $ stripe balance_transactions list -v "2013-08-13"
45
+
46
+ You may also store default configurations in a `~/.stripecli` file that conforms to the following example
47
+
48
+ ![example config file](./example.png)
49
+
50
+ You may also overide the default environment setting in your config file by passing in the `-e` or `--env` option
51
+
52
+ $ stripe customers find cust_123 --env=live
18
53
 
19
54
  ## Usage
20
55
 
21
- TODO: Write usage instructions here
56
+ $ stripe
57
+
58
+ Commands:
59
+ stripe balance # show currently available and pending balance amounts
60
+ stripe charges # find, list, create, capture, & refund charges
61
+ stripe coupons # find, list, create, & delete coupons
62
+ stripe customers # find, list, create, & delete customers
63
+ stripe events # find & list events
64
+ stripe invoices # find, list, pay, and close invoices
65
+ stripe plans # find, list, create, & delete plans
66
+ stripe recipients # find, list, create & delete recipients
67
+ stripe tokens # find & create tokens for bank accounts & credit cards
68
+ stripe transactions # find & list balance transactions
69
+ stripe transfers # find, list, & create transfers
70
+
71
+
72
+ Any parameters accepted by the [stripe api](https://stripe.com/docs/api) are acceptable options to pass into commands
73
+
74
+ $ stripe charges create [--amount=AMOUNT][--description=DESC][--card_number=NUM][--card_cvc=CVC][--card_exp_month=MM][--card_exp_year=YYYY]
75
+
76
+ or
77
+
78
+ $ stripe charges create [--amount=AMOUNT][--card=TOKEN_ID]
79
+
80
+ or
81
+
82
+ $ stripe charges create [--amount=AMOUNT][--customer=CUST_ID]
83
+
84
+ ## uniform behavior
85
+
86
+ The Stripe API is very consistant. Consistency makes using the api intuitive. This utility strives to maintain Stripe's consistency. Depending on which [C.R.U.D.](http://wikipedia.org/wiki/Create,_read,_update_and_delete) operation you are after, you can pretty much count on a few standard options to be available.
87
+
88
+ ### stripe (subcommand) list ...
89
+
90
+ specify how many results, between 1 and 100, should be returned (default is 10)
91
+
92
+ ... list [--count=COUNT]
93
+
94
+ specify the starting index for this result set, relative to the entire result set (usefull in combination with `--count` for paginating results)
95
+
96
+ ... list [--offset=OFFSET]
97
+
98
+ Passing NO (or partial) arguments, will trigger an interactive menu
99
+
100
+ $ stripe charges create
101
+ Amount in dollars: __
102
+
103
+ or
104
+
105
+ $ stripe charges create [--amount=AMOUNT]
106
+ Name on Card: __
107
+
108
+ ### Charges
109
+
110
+ $ stripe charges list
111
+ $ stripe charge find ch_123
112
+ $ stripe charge refund ch_123
113
+ $ stripe charge capture ch_123
114
+ $ stripe charge create
115
+
116
+ ### Tokens
117
+
118
+ $ stripe token find tok_123
119
+ $ stripe token create TYPE (bank_account or credit_card)
120
+
121
+ ### Customers
122
+
123
+ $ stripe customers list
124
+ $ stripe customer find cust_123
125
+ $ stripe customer delete cust_123
126
+ $ stripe customer create
127
+
128
+ ### Invoices
129
+
130
+ $ stripe invoices list [--customer=CUST_ID]
131
+ $ stripe invoice find inv_123
132
+ $ stripe invoice close inv_123
133
+ $ stripe invoice pay inv_123
134
+ $ stripe invoice upcoming cust_123
135
+
136
+ ### Plans
137
+
138
+ $ stripe plans list
139
+ $ stripe plan find custom_plan_id
140
+ $ stripe plan delete custom_plan_id
141
+ $ stripe plan create
142
+
143
+ ### Coupons
144
+
145
+ $ stripe coupons list
146
+ $ stripe coupon find 25_off
147
+ $ stripe coupon delete 25_off
148
+ $ stripe coupon create
149
+
150
+ ### Events
151
+
152
+ $ stripe events list
153
+ $ stripe event find ev_123
154
+
155
+ ### BalanceTransactions
156
+
157
+ $ stripe transactions list [--type=TYPE][--source=SOURCE_ID]
158
+ $ stripe transaction find trx_123
159
+
160
+ ### Recipients
161
+
162
+ $ stripe recipients list [--verified]
163
+ $ stripe recipient find recip_123
164
+ $ stripe recipient delete recip_123
165
+ $ stripe recipient create
166
+
167
+ ### Transfers
168
+
169
+ $ stripe transfers list [--recipient=RECIPIENT_ID][--status=STATUS]
170
+ $ stripe transfer find trans_id
171
+ $ stripe transfer create
172
+
173
+ #### Easter Egg Alert!
174
+
175
+ You can pass the `--balance` flag into `transfer create` to automatically set transfer `amount` equal to your currently available balance.
176
+
177
+ example:
178
+
179
+ $ stripe transfer create --balance --recipient=self
180
+
181
+ > No, its not magic. The `--balance` flag just triggers a 'preflight' api call to retrieve your current balance and assigns that to the `--amount` option
182
+
183
+ ## Road Map
184
+
185
+ 1. test coverage, test coverage, test coverage!
186
+ 1. `--date` filters for all `list` operations
187
+ 1. `update` command operations
188
+ 1. support for `disputes` & dispute handling
189
+ 1. support creating/updating config file through cli
190
+ 1. plug-able output formating for use in scripts and such
191
+ 1. request a feature you would like via the issue tracker
192
+
22
193
 
23
- ## Contributing
194
+ pull requests welcome
24
195
 
25
- 1. Fork it
26
- 2. Create your feature branch (`git checkout -b my-new-feature`)
27
- 3. Commit your changes (`git commit -am 'Add some feature'`)
28
- 4. Push to the branch (`git push origin my-new-feature`)
29
- 5. Create new Pull Request
196
+ report issues in the issues tracker
data/example.conf ADDED
@@ -0,0 +1,9 @@
1
+ default = test
2
+
3
+ [test]
4
+ key = 9MXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5
+ version = "2013-08-13"
6
+
7
+ [live]
8
+ key = MRXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9
+ version = "2013-02-13"
data/example.png ADDED
Binary file
@@ -4,47 +4,94 @@ module Stripe
4
4
  module CLI
5
5
  class Command < Thor
6
6
  class_option :key, :aliases => :k
7
-
7
+ class_option :env, :aliases => :e
8
+ class_option :version, :aliases => :v
8
9
  protected
9
10
 
10
11
  def api_key
11
- @api_key ||= options[:key] || stored_api_key
12
+ @api_key ||= options[:key] || stored_api_option('key')
13
+ end
14
+
15
+ def api_version
16
+ @api_version ||= options.delete(:version) || stored_api_option('version')
12
17
  end
13
18
 
14
- def stored_api_key
19
+ def environment
20
+ @env ||= options.delete(:env) || config['default']
21
+ end
22
+
23
+ def stored_api_option option
15
24
  if File.exists?(config_file)
16
- ParseConfig.new(config_file)['key']
25
+ if environment
26
+ config[environment][option.to_s]
27
+ else
28
+ config[option.to_s]
29
+ end
17
30
  end
18
31
  end
19
32
 
33
+ def config
34
+ ParseConfig.new(config_file) if File.exists?(config_file)
35
+ end
36
+
20
37
  def config_file
21
38
  File.expand_path('~/.stripecli')
22
39
  end
23
40
 
24
- def inspect(object)
41
+ def list klass, options
42
+ Stripe.api_version = api_version unless api_version.nil?
43
+ output klass.all( options, api_key )
44
+ end
45
+
46
+ def find klass, id
47
+ Stripe.api_version = api_version unless api_version.nil?
48
+ output klass.retrieve( id, api_key )
49
+ end
50
+
51
+ def delete klass, id
52
+ Stripe.api_version = api_version unless api_version.nil?
53
+ output klass.new( id, api_key ).delete
54
+ end
55
+
56
+ def create klass, options
57
+ Stripe.api_version = api_version unless api_version.nil?
58
+ output klass.create( options, api_key )
59
+ end
60
+
61
+ def special klass, method, options
62
+ Stripe.api_version = api_version unless api_version.nil?
63
+ output klass.new( options, api_key ).send( method )
64
+ end
65
+
66
+ private
67
+
68
+ def output objects
69
+ ap inspect( objects ), :indent => -2
70
+ end
71
+
72
+ def inspect object
25
73
  case object
26
74
  when Array
27
75
  object.map {|o| inspect(o) }
28
76
  when Hash
29
77
  object.inject({}) do |hash, (key, value)|
30
- hash[key] = inspect(value)
78
+ hash[key] = inspect( value )
31
79
  hash
32
80
  end
33
81
  when Stripe::ListObject
34
82
  inspect object.data
35
83
  when Stripe::StripeObject
36
84
  inspect object.to_hash
85
+ when Numeric
86
+ if object > 1000000000
87
+ Time.at object
88
+ else
89
+ object
90
+ end
37
91
  else
38
92
  object
39
93
  end
40
94
  end
41
-
42
- def output(objects)
43
- ap(
44
- inspect(objects),
45
- :indent => -2
46
- )
47
- end
48
95
  end
49
96
  end
50
97
  end
@@ -0,0 +1,14 @@
1
+ module Stripe
2
+ module CLI
3
+ module Commands
4
+ class Balance < Command
5
+ desc "current", "show currently available and pending balance figures"
6
+ def current
7
+ output Stripe::Balance.retrieve(api_key)
8
+ end
9
+
10
+ default_command :current
11
+ end
12
+ end
13
+ end
14
+ end
@@ -7,25 +7,26 @@ module Stripe
7
7
  option :customer
8
8
  option :offset
9
9
  def list
10
- output Stripe::Charge.all(options, api_key)
10
+ super Stripe::Charge, options
11
11
  end
12
12
 
13
13
  desc "find ID", "Find a charge"
14
- def find(charge_id)
15
- output Stripe::Charge.retrieve(charge_id, api_key)
14
+ def find charge_id
15
+ super Stripe::Charge, charge_id
16
16
  end
17
17
 
18
18
  desc "refund ID", "Refund a charge"
19
- def refund(charge_id)
20
- output Stripe::Charge.new(charge_id, api_key).refund
19
+ def refund charge_id
20
+ special Stripe::Charge, :refund, charge_id
21
21
  end
22
22
 
23
23
  desc "capture ID", "Capture a charge"
24
- def capture(charge_id)
25
- output Stripe::Charge.new(charge_id, api_key).capture
24
+ def capture charge_id
25
+ special Stripe::Charge, :capture, charge_id
26
26
  end
27
27
 
28
28
  desc "create", "Create a charge"
29
+ option :customer
29
30
  option :card
30
31
  option :card_number
31
32
  option :card_exp_month
@@ -35,35 +36,29 @@ module Stripe
35
36
  option :amount, :type => :numeric
36
37
  option :currency, :default => 'usd'
37
38
  option :description
38
- option :capture, :type => :boolean
39
+ option :capture, :type => :boolean, :default => true
39
40
 
40
41
  def create
41
42
  options[:amount] ||= ask('Amount in dollars:')
42
43
  options[:amount] = (Float(options[:amount]) * 100).to_i
43
44
 
44
- unless options[:card]
45
+ unless options[:card] || options[:customer]
46
+ options[:card_name] ||= ask('Name on Card:')
45
47
  options[:card_number] ||= ask('Card number:')
46
- options[:card_exp_month] ||= ask('Card exp month:')
47
- options[:card_exp_year] ||= ask('Card exp year:')
48
- options[:card_cvc] ||= ask('Card CVC:')
49
- options[:card_name] ||= ask('Card name:')
48
+ options[:card_cvc] ||= ask('CVC code:')
49
+ options[:card_exp_month] ||= ask('expiration month:')
50
+ options[:card_exp_year] ||= ask('expiration year:')
50
51
 
51
52
  options[:card] = {
52
- :number => options[:card_number],
53
- :exp_month => options[:card_exp_month],
54
- :exp_year => options[:card_exp_year],
55
- :cvc => options[:card_cvc],
56
- :name => options[:card_name]
53
+ :number => options.delete(:card_number),
54
+ :exp_month => options.delete(:card_exp_month),
55
+ :exp_year => options.delete(:card_exp_year),
56
+ :cvc => options.delete(:card_cvc),
57
+ :name => options.delete(:card_name)
57
58
  }
58
-
59
- options.delete(:card_number)
60
- options.delete(:card_exp_month)
61
- options.delete(:card_exp_year)
62
- options.delete(:card_cvc)
63
- options.delete(:card_name)
64
59
  end
65
60
 
66
- output Stripe::Charge.create(options, api_key)
61
+ super Stripe::Charge, options
67
62
  end
68
63
  end
69
64
  end
@@ -0,0 +1,57 @@
1
+ require 'chronic'
2
+ module Stripe
3
+ module CLI
4
+ module Commands
5
+ class Coupons < Command
6
+ desc "list", "List coupons"
7
+ option :count
8
+ option :offset
9
+
10
+ def list
11
+ super Stripe::Coupon, options
12
+ end
13
+
14
+ desc "find ID", "Find a coupon"
15
+ def find coupon_id
16
+ super Stripe::Coupon, coupon_id
17
+ end
18
+
19
+ desc "delete ID", "Delete a coupon"
20
+ def delete coupon_id
21
+ super Stripe::Coupon, coupon_id
22
+ end
23
+
24
+ desc "create", "Create a new Coupon"
25
+ option :id
26
+ option :percent_off, :type => :numeric
27
+ option :amount_off, :type => :numeric
28
+ option :duration, :enum => [ :forever, :once, :repeating ]
29
+ option :redeem_by, :type => :numeric, :default => nil
30
+ option :max_redemptions, :type => :numeric
31
+ option :duration_in_months
32
+ option :currency, :default => 'usd'
33
+
34
+ def create
35
+ unless options[:percent_off] || options[:amount_off]
36
+ discount = ask('(e.g. 25% or $10) specify discount:')
37
+ if discount.end_with?( '%' )
38
+ options[:percent_off] = discount.gsub(/[^\d]/,"").to_i
39
+ else
40
+ options[:amount_off] = discount.gsub(/[^\d]/,"").to_i
41
+ end
42
+ end
43
+ options[:id] ||= ask('Coupon ID:')
44
+ options[:duration] ||= ask('(`forever`,`once`, or `repeating`) duration:')
45
+ options[:duration_in_months] ||= ask('for how many months?') if options[:duration] == "repeating"
46
+ options[:redeem_by] ||= ask('expire on:')
47
+ if options[:redeem_by].empty?
48
+ options.delete(:redeem_by)
49
+ else
50
+ options[:redeem_by] = Chronic.parse(options[:redeem_by]).to_i.to_s
51
+ end
52
+ super Stripe::Coupon, options
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -7,17 +7,58 @@ module Stripe
7
7
  option :offset
8
8
 
9
9
  def list
10
- output Stripe::Customer.all(options, api_key)
10
+ super Stripe::Customer, options
11
11
  end
12
12
 
13
13
  desc "find ID", "Find a customer"
14
- def find(customer_id)
15
- output Stripe::Customer.retrieve(customer_id, api_key)
14
+ def find customer_id
15
+ super Stripe::Customer, customer_id
16
16
  end
17
17
 
18
18
  desc "delete ID", "Delete a customer"
19
- def delete(customer_id)
20
- output Stripe::Customer.new(customer_id, api_key).delete
19
+ def delete customer_id
20
+ super Stripe::Customer, customer_id
21
+ end
22
+
23
+ desc "create", "Create a new customer"
24
+ option :description
25
+ option :email
26
+ option :plan
27
+ option :coupon
28
+ option :quantity
29
+ option :trial_end
30
+ option :account_balance
31
+ option :card
32
+ option :card_number
33
+ option :card_exp_month
34
+ option :card_exp_year
35
+ option :card_cvc
36
+ option :card_name
37
+
38
+ def create
39
+ say('All of the following are OPTIONAL parameters...')
40
+ options[:email] ||= ask('Customer\'s Email:')
41
+ options[:description] ||= ask('Provide a description:')
42
+ options[:plan] ||= ask('Assign a plan:')
43
+ options[:coupon] ||= ask('Apply a coupon:')
44
+
45
+ if options[:plan]
46
+ options[:card_name] ||= ask('Name on Card:')
47
+ options[:card_number] ||= ask('Card number:')
48
+ options[:card_cvc] ||= ask('CVC code:')
49
+ options[:card_exp_month] ||= ask('expiration month:')
50
+ options[:card_exp_year] ||= ask('expiration year:')
51
+
52
+ options[:card] = {
53
+ :number => options.delete(:card_number),
54
+ :exp_month => options.delete(:card_exp_month),
55
+ :exp_year => options.delete(:card_exp_year),
56
+ :cvc => options.delete(:card_cvc),
57
+ :name => options.delete(:card_name)
58
+ }
59
+ end unless options[:card]
60
+
61
+ super Stripe::Customer, options
21
62
  end
22
63
  end
23
64
  end
@@ -7,12 +7,12 @@ module Stripe
7
7
  option :offset
8
8
 
9
9
  def list
10
- output Stripe::Event.all(options, api_key)
10
+ super Stripe::Event, options
11
11
  end
12
12
 
13
- desc "find ID", "Find a event`"
14
- def find(event_id)
15
- output Stripe::Event.retrieve(event_id, api_key)
13
+ desc "find ID", "Find a event"
14
+ def find event_id
15
+ super Stripe::Event, event_id
16
16
  end
17
17
  end
18
18
  end
@@ -0,0 +1,36 @@
1
+ module Stripe
2
+ module CLI
3
+ module Commands
4
+ class Invoices < Command
5
+ desc "list", "List invoices"
6
+ option :count
7
+ option :customer
8
+ option :offset
9
+
10
+ def list
11
+ super Stripe::Invoice, options
12
+ end
13
+
14
+ desc "find ID", "Find an invoice"
15
+ def find invoice_id
16
+ super Stripe::Invoice, invoice_id
17
+ end
18
+
19
+ desc "close ID", "close an unpaid invoice"
20
+ def close invoice_id
21
+ special Stripe::Invoice, :close, invoice_id
22
+ end
23
+
24
+ desc "pay ID", "trigger an open invoice to be paid immediately"
25
+ def pay invoice_id
26
+ special Stripe::Invoice, :pay, invoice_id
27
+ end
28
+
29
+ desc "upcoming CUSTOMER", "find the upcoming invoice for CUSTOMER"
30
+ def upcoming customer_id
31
+ special Stripe::Invoice, :upcoming, {:customer => customer_id}
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -7,17 +7,35 @@ module Stripe
7
7
  option :offset
8
8
 
9
9
  def list
10
- output Stripe::Plan.all(options, api_key)
10
+ super Stripe::Plan, options
11
11
  end
12
12
 
13
13
  desc "find ID", "Find a plan"
14
- def find(plan_id)
15
- output Stripe::Plan.retrieve(plan_id, api_key)
14
+ def find plan_id
15
+ super Stripe::Plan, plan_id
16
16
  end
17
17
 
18
18
  desc "delete ID", "Delete a plan"
19
- def delete(plan_id)
20
- output Stripe::Plan.new(plan_id, api_key).delete
19
+ def delete plan_id
20
+ super Stripe::Plan, plan_id
21
+ end
22
+
23
+ desc "create", "Create a new plan"
24
+ option :name
25
+ option :id
26
+ option :amount, :type => :numeric
27
+ option :interval, :default => 'month'
28
+ option :interval_count, :type => :numeric, :default => 1
29
+ option :currency, :default => 'usd'
30
+ option :trial_period_days, :type => :numeric, :default => 0
31
+
32
+ def create
33
+ options[:amount] ||= ask('Amount in dollars:')
34
+ options[:amount] = (Float(options[:amount]) * 100).to_i
35
+ options[:name] ||= ask('Plan name:')
36
+ options[:id] ||= ask('Plan id:')
37
+
38
+ super Stripe::Plan, options
21
39
  end
22
40
  end
23
41
  end
@@ -0,0 +1,67 @@
1
+ module Stripe
2
+ module CLI
3
+ module Commands
4
+ class Recipients < Command
5
+ desc "list", "List recipients"
6
+ option :count
7
+ option :offset
8
+ option :verified => :boolean
9
+
10
+ def list
11
+ super Stripe::Recipient, options
12
+ end
13
+
14
+ desc "find ID", "Find a recipient"
15
+ def find recipient_id
16
+ super Stripe::Recipient, recipient_id
17
+ end
18
+
19
+ desc "delete ID", "delete a recipient"
20
+ def delete recipient_id
21
+ super Stripe::Recipient, recipient_id
22
+ end
23
+
24
+ desc "create", "create a new recipient"
25
+ option :name
26
+ option :type, :enum => %w( individual corporation )
27
+ option :individual, :type => :boolean, :aliases => :i
28
+ option :corporation, :type => :boolean, :aliases => :c
29
+ option :tax_id, :type => :numeric
30
+ option :email
31
+ option :description
32
+ option :bank_account
33
+ option :country
34
+ option :account_number
35
+ option :routing_number
36
+
37
+ def create
38
+ options[:name] ||= ask('Recipient\'s Name:')
39
+ options[:email] ||= ask('Recipient\'s Email:')
40
+ options[:type] ||= if options.delete(:individual) then 'individual'
41
+ elsif options.delete(:corporation) then 'corporation'
42
+ else ask('Corporation? (Y/n)').downcase.start_with?('y') ? 'corporation' : 'individual'
43
+ end
44
+ options[:tax_id] ||= case options[:type]
45
+ when 'individual' then ask('Tax ID (SSN):')
46
+ when 'corporation' then ask('Tax ID (EIN):')
47
+ end
48
+ options[:tax_id].gsub!(/[^\d]/,"")
49
+
50
+ unless options[:bank_account]
51
+ options[:country] ||= 'US'
52
+ options[:account_number] ||= ask('Bank Account Number:')
53
+ options[:routing_number] ||= ask('Bank Routing Number:')
54
+
55
+ options[:bank_account] = {
56
+ :country => options.delete(:country),
57
+ :account_number => options.delete(:account_number),
58
+ :routing_number => options.delete(:routing_number)
59
+ }
60
+ end
61
+
62
+ super Stripe::Recipient, options
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,70 @@
1
+ module Stripe
2
+ module CLI
3
+ module Commands
4
+ class Tokens < Command
5
+
6
+ desc "find ID", "Find a Token"
7
+ def find event_id
8
+ super Stripe::Event, event_id
9
+ end
10
+
11
+ desc "create TYPE", "create a new token of type TYPE(card or account)"
12
+ option :card, :type => :hash
13
+ option :card_name
14
+ option :card_number
15
+ option :card_cvc
16
+ option :card_exp_month
17
+ option :card_exp_year
18
+ option :bank_account, :type => :hash
19
+ option :country
20
+ option :routing_number
21
+ option :account_number
22
+ def create type
23
+ case type
24
+ when 'card', 'credit_card'
25
+ unless options[:card]
26
+ options[:card_name] ||= ask('Name on Card:')
27
+ options[:card_number] ||= ask('Card number:')
28
+ options[:card_cvc] ||= ask('CVC code:')
29
+ options[:card_exp_month] ||= ask('expiration month:')
30
+ options[:card_exp_year] ||= ask('expiration year:')
31
+
32
+ options[:card] = {
33
+ :number => options.delete(:card_number),
34
+ :exp_month => options.delete(:card_exp_month),
35
+ :exp_year => options.delete(:card_exp_year),
36
+ :cvc => options.delete(:card_cvc),
37
+ :name => options.delete(:card_name)
38
+ }
39
+ options.delete(:bank_account)
40
+ options.delete(:country)
41
+ options.delete(:routing_number)
42
+ options.delete(:account_number)
43
+ end
44
+ when 'account', 'bank_account'
45
+ unless options[:bank_account]
46
+ options[:account_number] ||= ask('Account Number:')
47
+ options[:routing_number] ||= ask('Routing Number:')
48
+ options[:country] ||= 'US'
49
+
50
+ options[:bank_account] = {
51
+ :account_number => options.delete(:account_number),
52
+ :routing_number => options.delete(:routing_number),
53
+ :country => options.delete(:country)
54
+ }
55
+ options.delete(:card)
56
+ options.delete(:card_name)
57
+ options.delete(:card_number)
58
+ options.delete(:card_cvc)
59
+ options.delete(:card_exp_month)
60
+ options.delete(:card_exp_year)
61
+ end
62
+ end
63
+
64
+ super Stripe::Token, options
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ module Stripe
2
+ module CLI
3
+ module Commands
4
+ class Transactions < Command
5
+ desc "list [TYPE]", "List transactions, optionaly filter by type: ( charges, refunds, adjustments, application_fees, application_fee_refunds, transfers, transfer_failures )"
6
+ method_options [:count, :offset, :type, :source]
7
+ option :count
8
+ option :offset
9
+ option :type, :enum => %w( charge refund adjustment application_fee application_fee_refund transfer transfer_failure )
10
+ option :source
11
+
12
+ def list type = 'all'
13
+ options[:type] = type.sub(/s$/,'') unless type == 'all'
14
+ super Stripe::BalanceTransaction, options
15
+ end
16
+
17
+ desc "find ID", "Find a transaction"
18
+ def find transaction_id
19
+ super Stripe::BalanceTransaction, transaction_id
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,47 @@
1
+ module Stripe
2
+ module CLI
3
+ module Commands
4
+ class Transfers < Command
5
+ desc "list", "List transfers"
6
+ option :count
7
+ option :offset
8
+ option :recipient
9
+ option :status, :enum => %w( pending paid failed )
10
+
11
+ def list
12
+ super Stripe::Transfer, options
13
+ end
14
+
15
+ desc "find ID", "Find a transfer"
16
+ def find transfer_id
17
+ super Stripe::Transfer, transfer_id
18
+ end
19
+
20
+ desc "create", "create a new outgoing money transfer"
21
+ option :amount
22
+ option :recipient
23
+ option :currency, :default => 'usd'
24
+ option :description
25
+ option :statement_descriptor
26
+ option :balance, :type => :boolean
27
+ def create
28
+ if options.delete(:balance) == true
29
+ options[:amount] = Stripe::Balance.retrieve(api_key).available.first.amount
30
+ else
31
+ options[:amount] ||= ask('Amount in Dollars:')
32
+ options[:amount] = (Float(options[:amount]) * 100).to_i
33
+ end
34
+ options[:recipient] ||= ask('Recipient ID or self:')
35
+ options[:recipient] = create_recipient[:id] if options[:recipient] == ""
36
+ super Stripe::Transfer, options
37
+ end
38
+
39
+ private
40
+
41
+ def create_recipient
42
+ Stripe::CLI::Runner.start [ "recipients", "create" ]
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -3,8 +3,15 @@ module Stripe
3
3
  module Commands
4
4
  autoload :Charges, 'stripe/cli/commands/charges'
5
5
  autoload :Customers, 'stripe/cli/commands/customers'
6
+ autoload :Tokens, 'stripe/cli/commands/tokens'
6
7
  autoload :Plans, 'stripe/cli/commands/plans'
8
+ autoload :Coupons, 'stripe/cli/commands/coupons'
7
9
  autoload :Events, 'stripe/cli/commands/events'
10
+ autoload :Invoices, 'stripe/cli/commands/invoices'
11
+ autoload :Transactions, 'stripe/cli/commands/transactions'
12
+ autoload :Balance, 'stripe/cli/commands/balance'
13
+ autoload :Recipients, 'stripe/cli/commands/recipients'
14
+ autoload :Transfers, 'stripe/cli/commands/transfers'
8
15
  end
9
16
  end
10
17
  end
@@ -1,10 +1,17 @@
1
1
  module Stripe
2
2
  module CLI
3
3
  class Runner < Thor
4
- register Commands::Charges, 'charges', 'charges', '/charges'
5
- register Commands::Customers, 'customers', 'customers', '/customers'
6
- register Commands::Plans, 'plans', 'plans', '/plans'
7
- register Commands::Events, 'events', 'events', '/events'
4
+ register Commands::Charges, 'charges', 'charges', 'find, list, create, capture, & refund charges'
5
+ register Commands::Customers, 'customers', 'customers', 'find, list, create, & delete customers'
6
+ register Commands::Tokens, 'tokens', 'tokens', 'find & create tokens for bank accounts & credit cards'
7
+ register Commands::Plans, 'plans', 'plans', 'find, list, create, & delete plans'
8
+ register Commands::Coupons, 'coupons', 'coupons', 'find, list, create, & delete coupons'
9
+ register Commands::Events, 'events', 'events', 'find & list events'
10
+ register Commands::Invoices, 'invoices', 'invoices', 'find, list, pay, and close invoices'
11
+ register Commands::Transactions, 'transactions', 'transactions', 'find & list balance transactions'
12
+ register Commands::Balance, 'balance', 'balance', 'show currently available and pending balance amounts'
13
+ register Commands::Recipients, 'recipients', 'recipients', 'find, list, create & delete recipients'
14
+ register Commands::Transfers, 'transfers', 'transfers', 'find, list, & create transfers'
8
15
  end
9
16
  end
10
17
  end
@@ -1,5 +1,5 @@
1
1
  module Stripe
2
2
  module CLI
3
- VERSION = "0.0.1"
3
+ VERSION = "1.0.2"
4
4
  end
5
5
  end
data/output.png ADDED
Binary file
@@ -0,0 +1,54 @@
1
+ require 'rspec'
2
+ require_relative '../lib/stripe/cli.rb'
3
+
4
+ Stripe::CLI::Command.class_eval do
5
+ protected
6
+ def api_key
7
+ "stripe-key"
8
+ end
9
+ end
10
+
11
+
12
+ describe Stripe::CLI::Command do
13
+ let(:_id_) { "random-id-string" }
14
+
15
+ describe "#find" do
16
+ it "calls super, passing in `Stripe::Charge` and an `id`" do
17
+ Stripe::Charge.should_receive(:retrieve).with( _id_, "stripe-key" )
18
+
19
+ Stripe::CLI::Runner.start ["charges", "find", _id_]
20
+ end
21
+
22
+ it "calls super, passing in `Stripe::Plan` and an `id`" do
23
+ Stripe::Plan.should_receive(:retrieve).with( _id_, "stripe-key" )
24
+
25
+ Stripe::CLI::Runner.start ["plans", "find", _id_]
26
+ end
27
+
28
+ it "calls super, passing in `Stripe::Invoice` and an `id`" do
29
+ Stripe::Invoice.should_receive(:retrieve).with( _id_, "stripe-key" )
30
+
31
+ Stripe::CLI::Runner.start ["invoices", "find", _id_]
32
+ end
33
+
34
+ it "calls super, passing in `Stripe::Coupon` and an `id`" do
35
+ Stripe::Coupon.should_receive(:retrieve).with( _id_, "stripe-key" )
36
+
37
+ Stripe::CLI::Runner.start ["coupons", "find", _id_]
38
+ end
39
+
40
+ it "calls super, passing in `Stripe::Customer` and an `id`" do
41
+ Stripe::Customer.should_receive(:retrieve).with( _id_, "stripe-key" )
42
+
43
+ Stripe::CLI::Runner.start ["customers", "find", _id_]
44
+ end
45
+
46
+ it "calls super, passing in `Stripe::BalanceTransaction` and an `id`" do
47
+ Stripe::BalanceTransaction.should_receive(:retrieve).with( _id_, "stripe-key" )
48
+
49
+ Stripe::CLI::Runner.start ["transactions", "find", _id_]
50
+ end
51
+
52
+ end
53
+
54
+ end
data/stripe-cli.gemspec CHANGED
@@ -6,9 +6,9 @@ require 'stripe/cli/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "stripe-cli"
8
8
  spec.version = Stripe::CLI::VERSION
9
- spec.authors = ["Alex MacCaw"]
10
- spec.email = ["alex@stripe.com"]
11
- spec.description = %q{Command line interface to Stripe}
9
+ spec.authors = ["Alex MacCaw", "Andy Cohen"]
10
+ spec.email = ["alex@stripe.com", "outlawandy@gmail.com"]
11
+ spec.description = %q{A `GIT style` Command line utility for accessing the Stripe API}
12
12
  spec.summary = %q{Command line interface to Stripe}
13
13
  spec.homepage = "https://stripe.com"
14
14
  spec.license = "MIT"
@@ -22,7 +22,9 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.3"
23
23
  spec.add_development_dependency "rake"
24
24
  spec.add_dependency "thor", "~> 0.18.1"
25
- spec.add_dependency "stripe", "~> 1.8.3"
25
+ spec.add_dependency "stripe", "~> 1.8.6"
26
26
  spec.add_dependency "awesome_print"
27
27
  spec.add_dependency "parseconfig"
28
+ spec.add_dependency "chronic"
29
+ spec.add_development_dependency "rspec"
28
30
  end
metadata CHANGED
@@ -1,20 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 1.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex MacCaw
8
+ - Andy Cohen
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
17
  requirements:
19
18
  - - ~>
20
19
  - !ruby/object:Gem::Version
@@ -22,7 +21,6 @@ dependencies:
22
21
  type: :development
23
22
  prerelease: false
24
23
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
24
  requirements:
27
25
  - - ~>
28
26
  - !ruby/object:Gem::Version
@@ -30,23 +28,20 @@ dependencies:
30
28
  - !ruby/object:Gem::Dependency
31
29
  name: rake
32
30
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
31
  requirements:
35
- - - ! '>='
32
+ - - '>='
36
33
  - !ruby/object:Gem::Version
37
34
  version: '0'
38
35
  type: :development
39
36
  prerelease: false
40
37
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
38
  requirements:
43
- - - ! '>='
39
+ - - '>='
44
40
  - !ruby/object:Gem::Version
45
41
  version: '0'
46
42
  - !ruby/object:Gem::Dependency
47
43
  name: thor
48
44
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
45
  requirements:
51
46
  - - ~>
52
47
  - !ruby/object:Gem::Version
@@ -54,7 +49,6 @@ dependencies:
54
49
  type: :runtime
55
50
  prerelease: false
56
51
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
52
  requirements:
59
53
  - - ~>
60
54
  - !ruby/object:Gem::Version
@@ -62,54 +56,77 @@ dependencies:
62
56
  - !ruby/object:Gem::Dependency
63
57
  name: stripe
64
58
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
59
  requirements:
67
60
  - - ~>
68
61
  - !ruby/object:Gem::Version
69
- version: 1.8.3
62
+ version: 1.8.6
70
63
  type: :runtime
71
64
  prerelease: false
72
65
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
66
  requirements:
75
67
  - - ~>
76
68
  - !ruby/object:Gem::Version
77
- version: 1.8.3
69
+ version: 1.8.6
78
70
  - !ruby/object:Gem::Dependency
79
71
  name: awesome_print
80
72
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
73
  requirements:
83
- - - ! '>='
74
+ - - '>='
84
75
  - !ruby/object:Gem::Version
85
76
  version: '0'
86
77
  type: :runtime
87
78
  prerelease: false
88
79
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
80
  requirements:
91
- - - ! '>='
81
+ - - '>='
92
82
  - !ruby/object:Gem::Version
93
83
  version: '0'
94
84
  - !ruby/object:Gem::Dependency
95
85
  name: parseconfig
96
86
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
87
  requirements:
99
- - - ! '>='
88
+ - - '>='
100
89
  - !ruby/object:Gem::Version
101
90
  version: '0'
102
91
  type: :runtime
103
92
  prerelease: false
104
93
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
94
  requirements:
107
- - - ! '>='
95
+ - - '>='
108
96
  - !ruby/object:Gem::Version
109
97
  version: '0'
110
- description: Command line interface to Stripe
98
+ - !ruby/object:Gem::Dependency
99
+ name: chronic
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: rspec
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :development
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: A `GIT style` Command line utility for accessing the Stripe API
111
127
  email:
112
128
  - alex@stripe.com
129
+ - outlawandy@gmail.com
113
130
  executables:
114
131
  - stripe
115
132
  extensions: []
@@ -121,45 +138,50 @@ files:
121
138
  - README.md
122
139
  - Rakefile
123
140
  - bin/stripe
141
+ - example.conf
142
+ - example.png
124
143
  - lib/stripe/cli.rb
125
144
  - lib/stripe/cli/command.rb
126
145
  - lib/stripe/cli/commands.rb
146
+ - lib/stripe/cli/commands/balance.rb
127
147
  - lib/stripe/cli/commands/charges.rb
148
+ - lib/stripe/cli/commands/coupons.rb
128
149
  - lib/stripe/cli/commands/customers.rb
129
150
  - lib/stripe/cli/commands/events.rb
151
+ - lib/stripe/cli/commands/invoices.rb
130
152
  - lib/stripe/cli/commands/plans.rb
153
+ - lib/stripe/cli/commands/recipients.rb
154
+ - lib/stripe/cli/commands/tokens.rb
155
+ - lib/stripe/cli/commands/transactions.rb
156
+ - lib/stripe/cli/commands/transfers.rb
131
157
  - lib/stripe/cli/runner.rb
132
158
  - lib/stripe/cli/version.rb
159
+ - output.png
160
+ - spec/command_spec.rb
133
161
  - stripe-cli.gemspec
134
162
  homepage: https://stripe.com
135
163
  licenses:
136
164
  - MIT
165
+ metadata: {}
137
166
  post_install_message:
138
167
  rdoc_options: []
139
168
  require_paths:
140
169
  - lib
141
170
  required_ruby_version: !ruby/object:Gem::Requirement
142
- none: false
143
171
  requirements:
144
- - - ! '>='
172
+ - - '>='
145
173
  - !ruby/object:Gem::Version
146
174
  version: '0'
147
- segments:
148
- - 0
149
- hash: 68450767898144623
150
175
  required_rubygems_version: !ruby/object:Gem::Requirement
151
- none: false
152
176
  requirements:
153
- - - ! '>='
177
+ - - '>='
154
178
  - !ruby/object:Gem::Version
155
179
  version: '0'
156
- segments:
157
- - 0
158
- hash: 68450767898144623
159
180
  requirements: []
160
181
  rubyforge_project:
161
- rubygems_version: 1.8.24
182
+ rubygems_version: 2.1.3
162
183
  signing_key:
163
- specification_version: 3
184
+ specification_version: 4
164
185
  summary: Command line interface to Stripe
165
- test_files: []
186
+ test_files:
187
+ - spec/command_spec.rb