stripe-cli 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/stripe/cli.rb +13 -0
- data/lib/stripe/cli/command.rb +1 -1
- data/lib/stripe/cli/commands/cards.rb +9 -33
- data/lib/stripe/cli/commands/charges.rb +13 -24
- data/lib/stripe/cli/commands/coupons.rb +2 -2
- data/lib/stripe/cli/commands/customers.rb +19 -15
- data/lib/stripe/cli/commands/events.rb +2 -0
- data/lib/stripe/cli/commands/invoices.rb +1 -1
- data/lib/stripe/cli/commands/plans.rb +8 -8
- data/lib/stripe/cli/commands/recipients.rb +46 -22
- data/lib/stripe/cli/commands/refunds.rb +4 -13
- data/lib/stripe/cli/commands/subscriptions.rb +15 -31
- data/lib/stripe/cli/commands/tokens.rb +14 -30
- data/lib/stripe/cli/commands/transfers.rb +1 -1
- data/lib/stripe/cli/version.rb +1 -1
- data/lib/stripe/utils.rb +63 -0
- data/spec/command_spec.rb +1 -0
- data/spec/commands/charges_spec.rb +11 -11
- data/spec/commands/recipient_spec.rb +19 -0
- data/spec/spec_helper.rb +415 -6
- data/stripe-cli.gemspec +1 -1
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7acf8c013d963492b3c5b5c5be0b6d491939d3f3
|
4
|
+
data.tar.gz: aaca783bc677b2505e7e0239bda542135e951cf2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c0d8e42b469f3317c53acf525195af22efcd534fd6c77ede122b9bf42381b7696060748dc75d214d59487215f3682cfc6a41f9b4cc75fd616d640a30b2b1d7
|
7
|
+
data.tar.gz: c49672d4a38e69f465fc86aeb2b7a35b9c2e11e9da1cd381069baf823dbdfe07c3695d17304ce73fdba953d56e8fb363abcef4ac6d8b496625a05c4bfe6be787
|
data/lib/stripe/cli.rb
CHANGED
@@ -10,4 +10,17 @@ module Stripe
|
|
10
10
|
autoload :Runner, 'stripe/cli/runner'
|
11
11
|
autoload :Commands, 'stripe/cli/commands'
|
12
12
|
end
|
13
|
+
|
14
|
+
# `alias_method_chain' style patch to tweek the user-agent header sent with every API request
|
15
|
+
# Doing this adds context to request data that can be viewed using the Stripe Dashboard
|
16
|
+
# Differentiating requests made by application code from those made using the Stripe-CLI gem
|
17
|
+
class<<self
|
18
|
+
def add_stripe_cli_to_user_agent_string api_key
|
19
|
+
user_agent = original_request_headers(api_key)[:user_agent]
|
20
|
+
original_request_headers(api_key).update(:user_agent => user_agent<<"/Stripe-CLI v#{Stripe::CLI::VERSION}")
|
21
|
+
end
|
22
|
+
alias_method :original_request_headers, :request_headers
|
23
|
+
alias_method :request_headers, :add_stripe_cli_to_user_agent_string
|
24
|
+
private :request_headers
|
25
|
+
end
|
13
26
|
end
|
data/lib/stripe/cli/command.rb
CHANGED
@@ -10,7 +10,7 @@ module Stripe
|
|
10
10
|
option :limit, :desc => "a limit on the number of resources returned, between 1 and 100"
|
11
11
|
option :offset, :desc => "the starting index to be used, relative to the entire list"
|
12
12
|
option :count, :desc => "depricated: use limit"
|
13
|
-
option :owner, :required => true, :desc => "id of
|
13
|
+
option :owner, :required => true, :desc => "id of customer or recipient to search within"
|
14
14
|
def list
|
15
15
|
if owner = retrieve_owner(options.delete :owner)
|
16
16
|
super owner.cards, options
|
@@ -18,7 +18,7 @@ module Stripe
|
|
18
18
|
end
|
19
19
|
|
20
20
|
desc "find ID", "find ID card for OWNER (customer or recipient)"
|
21
|
-
option :owner, :required => true, :desc => "id of
|
21
|
+
option :owner, :required => true, :desc => "id of customer or recipient to search within"
|
22
22
|
def find card_id
|
23
23
|
if owner = retrieve_owner(options.delete :owner)
|
24
24
|
super owner.cards, card_id
|
@@ -27,15 +27,14 @@ module Stripe
|
|
27
27
|
|
28
28
|
|
29
29
|
desc "create", "create a new card for OWNER (customer or recipient)"
|
30
|
-
option :token
|
31
|
-
option :card_number
|
32
|
-
option :card_exp_month
|
33
|
-
option :card_exp_year
|
34
|
-
option :card_cvc
|
35
|
-
option :card_name
|
30
|
+
option :card, :aliases => :token, :desc => "credit card Token or ID. May also be created interactively."
|
31
|
+
option :card_number, :aliases => :number
|
32
|
+
option :card_exp_month, :aliases => :exp_month, :desc => "Two digit expiration month of card"
|
33
|
+
option :card_exp_year, :aliases => :exp_year, :desc => "Four digit expiration year of card"
|
34
|
+
option :card_cvc, :aliases => :cvc, :desc => "Three or four digit security code located on the back of card"
|
35
|
+
option :card_name, :aliases => :name, :desc => "Cardholder's full name as displayed on card"
|
36
36
|
option :owner, :required => true, :desc => "id of customer or recipient receiving new card"
|
37
37
|
def create
|
38
|
-
options[:card] = options.delete(:token)
|
39
38
|
options[:card] ||= credit_card( options )
|
40
39
|
if owner = retrieve_owner(options.delete :owner)
|
41
40
|
super owner.cards, options
|
@@ -43,7 +42,7 @@ module Stripe
|
|
43
42
|
end
|
44
43
|
|
45
44
|
desc "delete ID", "delete ID card for OWNER (customer or recipient)"
|
46
|
-
option :owner, :required => true, :desc => "id of
|
45
|
+
option :owner, :required => true, :desc => "id of customer or recipient to search within"
|
47
46
|
def delete card_id
|
48
47
|
if owner = retrieve_owner(options.delete :owner) and
|
49
48
|
card = retrieve_card(owner, card_id)
|
@@ -51,29 +50,6 @@ module Stripe
|
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
private
|
55
|
-
|
56
|
-
def retrieve_owner id
|
57
|
-
begin
|
58
|
-
if id.start_with? "r"
|
59
|
-
Stripe::Recipient.retrieve(id, api_key)
|
60
|
-
else
|
61
|
-
Stripe::Customer.retrieve(id, api_key)
|
62
|
-
end
|
63
|
-
rescue Exception => e
|
64
|
-
ap e.message
|
65
|
-
false
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def retrieve_card owner, id
|
70
|
-
begin
|
71
|
-
owner.cards.retrieve(id)
|
72
|
-
rescue Exception => e
|
73
|
-
ap e.message
|
74
|
-
false
|
75
|
-
end
|
76
|
-
end
|
77
53
|
end
|
78
54
|
end
|
79
55
|
end
|
@@ -10,7 +10,7 @@ module Stripe
|
|
10
10
|
option :limit, :desc => "a limit on the number of resources returned, between 1 and 100"
|
11
11
|
option :offset, :desc => "the starting index to be used, relative to the entire list"
|
12
12
|
option :count, :desc => "depricated: use limit"
|
13
|
-
option :customer
|
13
|
+
option :customer, :desc => "a customer ID to filter results by"
|
14
14
|
def list
|
15
15
|
super Stripe::Charge, options
|
16
16
|
end
|
@@ -22,7 +22,7 @@ module Stripe
|
|
22
22
|
|
23
23
|
desc "refund ID", "Refund a charge"
|
24
24
|
option :amount, :type => :numeric, :desc => "Refund amount in dollars. (Entire charge by default)"
|
25
|
-
option :metadata, :type => :hash
|
25
|
+
option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data"
|
26
26
|
option :refund_application_fee, :type => :boolean, :default => false, :desc => "Whether or not to refund the application fee"
|
27
27
|
def refund charge_id
|
28
28
|
options[:amount] = (Float(options[:amount]) * 100).to_i if options[:amount]
|
@@ -37,18 +37,18 @@ module Stripe
|
|
37
37
|
end
|
38
38
|
|
39
39
|
desc "create", "Create a charge"
|
40
|
-
option :customer, :desc => "The ID of an existing customer"
|
41
|
-
option :card
|
42
|
-
option :card_number
|
43
|
-
option :card_exp_month
|
44
|
-
option :card_exp_year
|
45
|
-
option :card_cvc
|
46
|
-
option :card_name
|
40
|
+
option :customer, :desc => "The ID of an existing customer to charge"
|
41
|
+
option :card, :aliases => :token, :desc => "credit card Token or ID. May also be created interactively."
|
42
|
+
option :card_number, :aliases => :number
|
43
|
+
option :card_exp_month, :aliases => :exp_month, :desc => "Two digit expiration month of card"
|
44
|
+
option :card_exp_year, :aliases => :exp_year, :desc => "Four digit expiration year of card"
|
45
|
+
option :card_cvc, :aliases => :cvc, :desc => "Three or four digit security code located on the back of card"
|
46
|
+
option :card_name, :aliases => :name, :desc => "Cardholder's full name as displayed on card"
|
47
47
|
option :amount, :type => :numeric, :desc => "Charge amount in dollars"
|
48
|
-
option :currency, :default =>
|
49
|
-
option :description
|
50
|
-
option :capture, :type => :boolean, :default => true
|
51
|
-
option :metadata, :type => :hash
|
48
|
+
option :currency, :default => "usd"
|
49
|
+
option :description, :desc => "Arbitrary description of charge"
|
50
|
+
option :capture, :type => :boolean, :default => true, :desc => "Whether or not to immediately capture the charge. Uncaptured charges expire in 7 days"
|
51
|
+
option :metadata, :type => :hash, :desc => "A key/value store of additional user-defined data"
|
52
52
|
option :statement_description, :desc => "Displayed alongside your company name on your customer's card statement (15 character max)"
|
53
53
|
option :receipt_email, :desc => "Email address to send receipt to. Overrides default email settings."
|
54
54
|
def create
|
@@ -60,17 +60,6 @@ module Stripe
|
|
60
60
|
super Stripe::Charge, options
|
61
61
|
end
|
62
62
|
|
63
|
-
private
|
64
|
-
|
65
|
-
def retrieve_charge id
|
66
|
-
begin
|
67
|
-
Stripe::Charge.retrieve(id, api_key)
|
68
|
-
rescue Exception => e
|
69
|
-
ap e.message
|
70
|
-
false
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
63
|
end
|
75
64
|
end
|
76
65
|
end
|
@@ -29,11 +29,11 @@ module Stripe
|
|
29
29
|
option :percent_off, :type => :numeric
|
30
30
|
option :amount_off, :type => :numeric
|
31
31
|
option :duration, :enum => [ :forever, :once, :repeating ]
|
32
|
-
option :redeem_by, :
|
32
|
+
option :redeem_by, :desc => "coupon will no longer be accepted after this date."
|
33
33
|
option :max_redemptions, :type => :numeric
|
34
34
|
option :duration_in_months
|
35
35
|
option :currency, :default => 'usd'
|
36
|
-
option :metadata, :type => :hash
|
36
|
+
option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data"
|
37
37
|
def create
|
38
38
|
unless options[:percent_off] || options[:amount_off]
|
39
39
|
discount = ask('(e.g. 25% or $10) specify discount:')
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'chronic'
|
1
2
|
module Stripe
|
2
3
|
module CLI
|
3
4
|
module Commands
|
@@ -25,20 +26,20 @@ module Stripe
|
|
25
26
|
end
|
26
27
|
|
27
28
|
desc "create", "Create a new customer"
|
28
|
-
option :description
|
29
|
-
option :email
|
30
|
-
option :plan
|
31
|
-
option :coupon
|
32
|
-
option :quantity
|
33
|
-
option :trial_end
|
34
|
-
option :account_balance
|
35
|
-
option :card
|
36
|
-
option :card_number
|
37
|
-
option :card_exp_month
|
38
|
-
option :card_exp_year
|
39
|
-
option :card_cvc
|
40
|
-
option :card_name
|
41
|
-
option :metadata, :type => :hash
|
29
|
+
option :description, :desc => "Arbitrary description to be displayed in Stripe Dashboard."
|
30
|
+
option :email, :desc => "Customer's email address. Will be displayed in Stripe Dashboard."
|
31
|
+
option :plan, :desc => "The ID of a Plan this customer should be subscribed to. Requires a credit card."
|
32
|
+
option :coupon, :desc => "The ID of a Coupon to be applied to all of Customer's recurring charges"
|
33
|
+
option :quantity, :desc => "A multiplier for the plan option. defaults to `1'"
|
34
|
+
option :trial_end, :desc => "apply a trial period until this date. Override plan's trial period."
|
35
|
+
option :account_balance, :desc => "customer's starting account balance in cents. A positive amount will be added to the next invoice while a negitive amount will act as a credit."
|
36
|
+
option :card, :aliases => :token, :desc => "credit card Token or ID. May also be created interactively."
|
37
|
+
option :card_number, :aliases => :number
|
38
|
+
option :card_exp_month, :aliases => :exp_month, :desc => "Two digit expiration month of card"
|
39
|
+
option :card_exp_year, :aliases => :exp_year, :desc => "Four digit expiration year of card"
|
40
|
+
option :card_cvc, :aliases => :cvc, :desc => "Three or four digit security code located on the back of card"
|
41
|
+
option :card_name, :aliases => :name, :desc => "Cardholder's full name as displayed on card"
|
42
|
+
option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data"
|
42
43
|
def create
|
43
44
|
options[:email] ||= ask('Customer\'s Email:')
|
44
45
|
options[:description] ||= ask('Provide a description:')
|
@@ -50,7 +51,10 @@ module Stripe
|
|
50
51
|
end
|
51
52
|
options.delete( :coupon ) if options[:coupon] == ""
|
52
53
|
|
53
|
-
|
54
|
+
if options[:plan]
|
55
|
+
options[:card] ||= credit_card( options )
|
56
|
+
options[:trial_end] = Chronic.parse(options[:trial_end]).to_i.to_s if options[:trial_end]
|
57
|
+
end
|
54
58
|
|
55
59
|
super Stripe::Customer, options
|
56
60
|
end
|
@@ -9,6 +9,8 @@ module Stripe
|
|
9
9
|
option :limit, :desc => "a limit on the number of resources returned, between 1 and 100"
|
10
10
|
option :offset, :desc => "the starting index to be used, relative to the entire list"
|
11
11
|
option :count, :desc => "depricated: use limit"
|
12
|
+
option :object_id, :desc => "only list events pertaining to the object with this ID"
|
13
|
+
option :type, :desc => "only list events of type TYPE"
|
12
14
|
def list
|
13
15
|
super Stripe::Event, options
|
14
16
|
end
|
@@ -9,7 +9,7 @@ module Stripe
|
|
9
9
|
option :limit, :desc => "a limit on the number of resources returned, between 1 and 100"
|
10
10
|
option :offset, :desc => "the starting index to be used, relative to the entire list"
|
11
11
|
option :count, :desc => "depricated: use limit"
|
12
|
-
option :customer
|
12
|
+
option :customer, :desc => "a customer ID to filter results by"
|
13
13
|
def list
|
14
14
|
super Stripe::Invoice, options
|
15
15
|
end
|
@@ -24,14 +24,14 @@ module Stripe
|
|
24
24
|
end
|
25
25
|
|
26
26
|
desc "create", "Create a new plan"
|
27
|
-
option :name
|
28
|
-
option :id
|
29
|
-
option :amount, :type => :numeric
|
30
|
-
option :interval, :default =>
|
31
|
-
option :interval_count, :type => :numeric, :default => 1
|
32
|
-
option :currency, :default =>
|
33
|
-
option :trial_period_days, :type => :numeric, :default => 0
|
34
|
-
option :metadata, :type => :hash
|
27
|
+
option :name, :desc => "Name displayed on invoices and in the Dashboard"
|
28
|
+
option :id, :desc => "Unique name used to identify this plan when subscribing a customer"
|
29
|
+
option :amount, :type => :numeric, :desc => "Amount in dollars"
|
30
|
+
option :interval, :enum => %w( day week month year ), :default => "month", :desc => "Billing frequency"
|
31
|
+
option :interval_count, :type => :numeric, :default => 1, :desc => "The number of intervals between each subscription billing."
|
32
|
+
option :currency, :default => "usd"
|
33
|
+
option :trial_period_days, :type => :numeric, :default => 0, :desc => "Number of days to delay a customer's initial bill"
|
34
|
+
option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data"
|
35
35
|
def create
|
36
36
|
options[:amount] ||= ask('Amount in dollars:')
|
37
37
|
options[:amount] = (Float(options[:amount]) * 100).to_i
|
@@ -2,6 +2,7 @@ module Stripe
|
|
2
2
|
module CLI
|
3
3
|
module Commands
|
4
4
|
class Recipients < Command
|
5
|
+
include Stripe::Utils
|
5
6
|
|
6
7
|
desc "list", "List recipients"
|
7
8
|
option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination."
|
@@ -24,8 +25,8 @@ module Stripe
|
|
24
25
|
super Stripe::Recipient, recipient_id
|
25
26
|
end
|
26
27
|
|
27
|
-
desc "create", "create a new recipient"
|
28
|
-
option :name
|
28
|
+
desc "create", "create a new recipient. Either an Individual or a Corporation."
|
29
|
+
option :name, :desc => "Full legal name of Individual or Corporation"
|
29
30
|
option :type, :enum => %w( individual corporation )
|
30
31
|
option :individual, :type => :boolean, :aliases => :i
|
31
32
|
option :corporation, :type => :boolean, :aliases => :c
|
@@ -36,34 +37,57 @@ module Stripe
|
|
36
37
|
option :country
|
37
38
|
option :account_number
|
38
39
|
option :routing_number
|
39
|
-
option :
|
40
|
+
option :card, :aliases => :token, :desc => "credit card Token or ID. May also be created interactively."
|
41
|
+
option :card_number, :aliases => :number
|
42
|
+
option :card_exp_month, :aliases => :exp_month, :desc => "Two digit expiration month of card"
|
43
|
+
option :card_exp_year, :aliases => :exp_year, :desc => "Four digit expiration year of card"
|
44
|
+
option :card_cvc, :aliases => :cvc, :desc => "Three or four digit security code located on the back of card"
|
45
|
+
option :card_name, :desc => "Cardholder's full name as displayed on card"
|
46
|
+
option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data"
|
40
47
|
def create
|
41
|
-
options[:
|
42
|
-
|
43
|
-
options[:type]
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
48
|
+
options[:type] ||= recipient_type(options)
|
49
|
+
|
50
|
+
case options[:type]
|
51
|
+
when 'individual'
|
52
|
+
options[:name] ||= ask('Recipient\'s full, legal name:')
|
53
|
+
options[:tax_id] ||= ask('Tax ID (SSN):')
|
54
|
+
when 'corporation'
|
55
|
+
options[:name] ||= ask('Full Incorporated Name:')
|
56
|
+
options[:tax_id] ||= ask('Tax ID (EIN):')
|
57
|
+
end unless options[:name] && options[:tax_id]
|
58
|
+
|
51
59
|
options[:tax_id].gsub!(/[^\d]/,"")
|
52
60
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
options[:
|
61
|
+
options[:email] ||= ask('Email Address:')
|
62
|
+
|
63
|
+
unless options[:card] || no?('add a Debit Card? [yN]',:yellow)
|
64
|
+
options[:card_name] ||= options[:name] if yes?('Name on card same as recipient name? [yN]')
|
65
|
+
options[:card] = credit_card( options )
|
66
|
+
end
|
57
67
|
|
58
|
-
|
59
|
-
|
60
|
-
:account_number => options.delete(:account_number),
|
61
|
-
:routing_number => options.delete(:routing_number)
|
62
|
-
}
|
68
|
+
unless options[:bank_account] || no?('add a Bank Account? [yN]',:yellow)
|
69
|
+
options[:bank_account] = bank_account( options )
|
63
70
|
end
|
64
71
|
|
72
|
+
options.delete :country
|
73
|
+
options.delete :account_number
|
74
|
+
options.delete :routing_number
|
75
|
+
options.delete :card_number
|
76
|
+
options.delete :card_exp_month
|
77
|
+
options.delete :card_exp_year
|
78
|
+
options.delete :card_cvc
|
79
|
+
options.delete :card_name
|
80
|
+
|
65
81
|
super Stripe::Recipient, options
|
66
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def recipient_type opt
|
87
|
+
opt.delete(:individual) ? 'individual' :
|
88
|
+
opt.delete(:corporation) ? 'corporation' :
|
89
|
+
yes?('Corporation? [yN]') ? 'corporation' : 'individual'
|
90
|
+
end
|
67
91
|
end
|
68
92
|
end
|
69
93
|
end
|
@@ -2,13 +2,15 @@ module Stripe
|
|
2
2
|
module CLI
|
3
3
|
module Commands
|
4
4
|
class Refunds < Command
|
5
|
+
include Stripe::Utils
|
6
|
+
|
5
7
|
desc "list", "List refunds for CHARGE charge"
|
6
8
|
option :starting_after, :desc => "The ID of the last object in the previous paged result set. For cursor-based pagination."
|
7
9
|
option :ending_before, :desc => "The ID of the first object in the previous paged result set, when paging backwards through the list."
|
8
10
|
option :limit, :desc => "a limit on the number of resources returned, between 1 and 100"
|
9
11
|
option :offset, :desc => "the starting index to be used, relative to the entire list"
|
10
12
|
option :count, :desc => "depricated: use limit"
|
11
|
-
option :charge, :aliases => :c, :required => true, :desc => "Id of charge to search"
|
13
|
+
option :charge, :aliases => :c, :required => true, :desc => "Id of charge to search within"
|
12
14
|
def list
|
13
15
|
if charge = retrieve_charge(options.delete :charge)
|
14
16
|
super charge.refunds, options
|
@@ -25,7 +27,7 @@ module Stripe
|
|
25
27
|
|
26
28
|
desc "create", "apply a new refund to CHARGE charge"
|
27
29
|
option :amount, :type => :numeric, :desc => "Refund amount in dollars. (Entire charge by default)"
|
28
|
-
option :metadata, :type => :hash
|
30
|
+
option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data"
|
29
31
|
option :refund_application_fee, :type => :boolean, :default => false, :desc => "Whether or not to refund the application fee"
|
30
32
|
option :charge, :aliases => :c, :required => true, :desc => "Id of charge to apply refund"
|
31
33
|
def create
|
@@ -35,17 +37,6 @@ module Stripe
|
|
35
37
|
end
|
36
38
|
end
|
37
39
|
|
38
|
-
private
|
39
|
-
|
40
|
-
def retrieve_charge id
|
41
|
-
begin
|
42
|
-
Stripe::Charge.retrieve(id, api_key)
|
43
|
-
rescue Exception => e
|
44
|
-
ap e.message
|
45
|
-
false
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
40
|
end
|
50
41
|
end
|
51
42
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'chronic'
|
1
2
|
module Stripe
|
2
3
|
module CLI
|
3
4
|
module Commands
|
@@ -10,7 +11,7 @@ module Stripe
|
|
10
11
|
option :limit, :desc => "a limit on the number of resources returned, between 1 and 100"
|
11
12
|
option :offset, :desc => "the starting index to be used, relative to the entire list"
|
12
13
|
option :count, :desc => "depricated: use limit"
|
13
|
-
option :customer, :aliases => :c, :required => true, :desc => "
|
14
|
+
option :customer, :aliases => :c, :required => true, :desc => "ID of customer to search within"
|
14
15
|
def list
|
15
16
|
if cust = retrieve_customer(options.delete :customer)
|
16
17
|
super cust.subscriptions, options
|
@@ -18,7 +19,7 @@ module Stripe
|
|
18
19
|
end
|
19
20
|
|
20
21
|
desc "find ID", "find ID subscription for CUSTOMER customer"
|
21
|
-
option :customer, :aliases => :c, :required => true, :desc => "
|
22
|
+
option :customer, :aliases => :c, :required => true, :desc => "ID of customer to search within"
|
22
23
|
def find subscription_id
|
23
24
|
if cust = retrieve_customer(options.delete :customer)
|
24
25
|
super cust.subscriptions, subscription_id
|
@@ -28,21 +29,22 @@ module Stripe
|
|
28
29
|
desc "create", "create a subscription for CUSTOMER customer"
|
29
30
|
option :plan, :desc => "the plan to assign to CUSTOMER customer"
|
30
31
|
option :coupon, :desc => "id of a coupon to apply"
|
31
|
-
option :trial_end, :desc => "apply a trial period until this date"
|
32
|
-
option :card
|
33
|
-
option :card_number
|
34
|
-
option :card_exp_month
|
35
|
-
option :card_exp_year
|
36
|
-
option :card_cvc
|
37
|
-
option :card_name
|
38
|
-
option :metadata, :type => :hash
|
39
|
-
option :customer, :aliases => :c, :required => true, :desc => "
|
32
|
+
option :trial_end, :desc => "apply a trial period until this date. Override plan's trial period."
|
33
|
+
option :card, :aliases => :token, :desc => "credit card Token or ID. May also be created interactively."
|
34
|
+
option :card_number, :aliases => :number
|
35
|
+
option :card_exp_month, :aliases => :exp_month, :desc => "Two digit expiration month of card"
|
36
|
+
option :card_exp_year, :aliases => :exp_year, :desc => "Four digit expiration year of card"
|
37
|
+
option :card_cvc, :aliases => :cvc, :desc => "Three or four digit security code located on the back of card"
|
38
|
+
option :card_name, :aliases => :name, :desc => "Cardholder's full name as displayed on card"
|
39
|
+
option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data"
|
40
|
+
option :customer, :aliases => :c, :required => true, :desc => "ID of customer receiving the new subscription"
|
40
41
|
def create
|
41
42
|
options[:plan] ||= ask('Assign a plan:')
|
43
|
+
options.delete( :plan ) if options[:plan] == ""
|
42
44
|
options[:coupon] ||= ask('Apply a coupon:')
|
43
45
|
options.delete( :coupon ) if options[:coupon] == ""
|
44
46
|
options[:card] ||= credit_card( options ) if yes?("add a new credit card? [yN]",:yellow)
|
45
|
-
options[:trial_end] = options[:trial_end].to_i if options[:trial_end]
|
47
|
+
options[:trial_end] = Chronic.parse(options[:trial_end]).to_i.to_s if options[:trial_end]
|
46
48
|
if cust = retrieve_customer(options.delete :customer)
|
47
49
|
super cust.subscriptions, options
|
48
50
|
end
|
@@ -53,6 +55,7 @@ module Stripe
|
|
53
55
|
option :at_period_end, :type => :boolean, :default => false, :desc => "delay cancellation until end of current period"
|
54
56
|
option :customer, :aliases => :c, :required => true, :desc => "id of customer to search within"
|
55
57
|
def cancel subscription_id
|
58
|
+
options[:at_period_end] ||= yes?("delay until end of current period? [yN]",:yellow)
|
56
59
|
if cust = retrieve_customer(options.delete :customer) and
|
57
60
|
subscription = retrieve_subscription(cust, subscription_id)
|
58
61
|
request subscription, :delete, options
|
@@ -68,25 +71,6 @@ module Stripe
|
|
68
71
|
end
|
69
72
|
end
|
70
73
|
|
71
|
-
private
|
72
|
-
|
73
|
-
def retrieve_customer id
|
74
|
-
begin
|
75
|
-
Stripe::Customer.retrieve(id, api_key)
|
76
|
-
rescue Exception => e
|
77
|
-
ap e.message
|
78
|
-
false
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
def retrieve_subscription cust, id
|
83
|
-
begin
|
84
|
-
cust.subscriptions.retrieve(id)
|
85
|
-
rescue Exception => e
|
86
|
-
ap e.message
|
87
|
-
false
|
88
|
-
end
|
89
|
-
end
|
90
74
|
end
|
91
75
|
end
|
92
76
|
end
|
@@ -10,42 +10,26 @@ module Stripe
|
|
10
10
|
end
|
11
11
|
|
12
12
|
desc "create TYPE", "create a new token of type TYPE(card or account)"
|
13
|
-
option :card, :type => :hash
|
14
|
-
option :
|
15
|
-
option :
|
16
|
-
option :
|
17
|
-
option :
|
18
|
-
option :
|
13
|
+
option :card, :type => :hash, :desc => "hash of card parameters which may also be provided individually or added interactively if not provided."
|
14
|
+
option :card_number, :aliases => :number
|
15
|
+
option :card_exp_month, :aliases => :exp_month, :desc => "Two digit expiration month of card"
|
16
|
+
option :card_exp_year, :aliases => :exp_year, :desc => "Four digit expiration year of card"
|
17
|
+
option :card_cvc, :aliases => :cvc, :desc => "Three or four digit security code located on the back of card"
|
18
|
+
option :card_name, :aliases => :name, :desc => "Cardholder's full name as displayed on card"
|
19
19
|
option :bank_account, :type => :hash
|
20
20
|
option :country
|
21
21
|
option :routing_number
|
22
22
|
option :account_number
|
23
23
|
def create type
|
24
24
|
case type
|
25
|
-
when 'card', 'credit_card'
|
26
|
-
options[:card] ||= credit_card( options )
|
27
|
-
options
|
28
|
-
options
|
29
|
-
|
30
|
-
options
|
31
|
-
|
32
|
-
|
33
|
-
options[:account_number] ||= ask('Account Number:')
|
34
|
-
options[:routing_number] ||= ask('Routing Number:')
|
35
|
-
options[:country] ||= 'US'
|
36
|
-
|
37
|
-
options[:bank_account] = {
|
38
|
-
:account_number => options.delete(:account_number),
|
39
|
-
:routing_number => options.delete(:routing_number),
|
40
|
-
:country => options.delete(:country)
|
41
|
-
}
|
42
|
-
options.delete(:card)
|
43
|
-
options.delete(:card_name)
|
44
|
-
options.delete(:card_number)
|
45
|
-
options.delete(:card_cvc)
|
46
|
-
options.delete(:card_exp_month)
|
47
|
-
options.delete(:card_exp_year)
|
48
|
-
end
|
25
|
+
when 'card', 'credit_card', 'credit card'
|
26
|
+
credit_card = options[:card] ||= credit_card( options )
|
27
|
+
options = {}
|
28
|
+
options[:card] = credit_card
|
29
|
+
when 'account', 'bank_account', 'bank account'
|
30
|
+
bank_account = options[:bank_account] ||= bank_account( options )
|
31
|
+
options = {}
|
32
|
+
options[:bank_account] = bank_account
|
49
33
|
end
|
50
34
|
|
51
35
|
super Stripe::Token, options
|
@@ -28,7 +28,7 @@ module Stripe
|
|
28
28
|
option :statement_descriptor
|
29
29
|
option :balance, :type => :boolean
|
30
30
|
option :self, :type => :boolean
|
31
|
-
option :metadata, :type => :hash
|
31
|
+
option :metadata, :type => :hash, :desc => "a key/value store of additional user-defined data"
|
32
32
|
def create
|
33
33
|
if options.delete(:balance) == true
|
34
34
|
options[:amount] = Stripe::Balance.retrieve(api_key).available.first.amount
|
data/lib/stripe/cli/version.rb
CHANGED
data/lib/stripe/utils.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Stripe
|
2
2
|
module Utils
|
3
3
|
|
4
|
+
private
|
5
|
+
|
4
6
|
def credit_card options = {}
|
5
7
|
{
|
6
8
|
:name => options.delete(:card_name) || ask('Name on Card:'),
|
@@ -11,5 +13,66 @@ module Stripe
|
|
11
13
|
}
|
12
14
|
end
|
13
15
|
|
16
|
+
def bank_account options = {}
|
17
|
+
{
|
18
|
+
:account_number => options.delete(:account_number) || ask('Account Number:'),
|
19
|
+
:routing_number => options.delete(:routing_number) || ask('Routing Number:'),
|
20
|
+
:country => options.delete(:country) || 'US'
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def retrieve_customer id
|
25
|
+
begin
|
26
|
+
::Stripe::Customer.retrieve(id, api_key)
|
27
|
+
rescue Exception => e
|
28
|
+
ap e.message
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def retrieve_charge id
|
34
|
+
begin
|
35
|
+
::Stripe::Charge.retrieve(id, api_key)
|
36
|
+
rescue Exception => e
|
37
|
+
ap e.message
|
38
|
+
false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def retrieve_recipient id
|
43
|
+
begin
|
44
|
+
::Stripe::Recipient.retrieve(id, api_key)
|
45
|
+
rescue Exception => e
|
46
|
+
ap e.message
|
47
|
+
false
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def retrieve_subscription cust, id
|
52
|
+
begin
|
53
|
+
cust.subscriptions.retrieve(id)
|
54
|
+
rescue Exception => e
|
55
|
+
ap e.message
|
56
|
+
false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def retrieve_card owner, id
|
61
|
+
begin
|
62
|
+
owner.cards.retrieve(id)
|
63
|
+
rescue Exception => e
|
64
|
+
ap e.message
|
65
|
+
false
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def retrieve_owner id
|
70
|
+
if id.start_with? "r"
|
71
|
+
retrieve_recipient(id)
|
72
|
+
else
|
73
|
+
retrieve_customer(id)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
14
77
|
end
|
15
78
|
end
|
data/spec/command_spec.rb
CHANGED
@@ -6,17 +6,17 @@ describe Stripe::CLI::Commands::Charges do
|
|
6
6
|
|
7
7
|
describe "#refund" do
|
8
8
|
|
9
|
-
it "takes a charge_id and refunds the associated charge entirely" do
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
it "takes a charge_id and an optional [--amount] and partially refunds the associated charge" do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
end
|
9
|
+
# it "takes a charge_id and refunds the associated charge entirely" do
|
10
|
+
# request_hash = Stripe::CLI::Runner.start ["charges", "refund", _id_]
|
11
|
+
# request_hash[:url].should == "https://api.stripe.com/v1/charges/a-charge-id/refund"
|
12
|
+
# request_hash[:payload].should == ""
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# it "takes a charge_id and an optional [--amount] and partially refunds the associated charge" do
|
16
|
+
# request_hash = Stripe::CLI::Runner.start ["charges", "refund", _id_, "--amount=100.99"]
|
17
|
+
# request_hash[:url].should == "https://api.stripe.com/v1/charges/a-charge-id/refund"
|
18
|
+
# request_hash[:payload].should == "amount=10099"
|
19
|
+
# end
|
20
20
|
|
21
21
|
end
|
22
22
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Stripe::CLI::Commands::Recipients do
|
4
|
+
|
5
|
+
describe "#create" do
|
6
|
+
|
7
|
+
it "can determine recipient type from the passed options" do
|
8
|
+
Stripe.should_receive(:execute_request).with do |opts|
|
9
|
+
opts[:headers][:authorization] == 'Bearer stripe-key'
|
10
|
+
end
|
11
|
+
request_hash = Stripe::CLI::Runner.start ["recipients", "create", "--corporation", "--name=John Doe"]
|
12
|
+
expect(request_hash[:url]).to eq("https://api.stripe.com/v1/recipients")
|
13
|
+
expect(request_hash[:payload]).to eq("type=individual&name=John Doe")
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,421 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require_relative '../lib/stripe/cli.rb'
|
3
3
|
|
4
|
-
f = Tempfile.new('config')
|
5
|
-
f.write "key = stripe-key" and f.rewind
|
6
|
-
Stripe::CLI::Command.class_variable_set :@@config, f
|
7
|
-
|
8
4
|
module Stripe
|
9
|
-
|
10
|
-
|
5
|
+
class StripeObject
|
6
|
+
def body
|
7
|
+
@stripe_values[:body]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
module CLI
|
11
|
+
class Command < Thor
|
12
|
+
protected
|
13
|
+
def api_key
|
14
|
+
"stripe-key"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
module Stripe
|
20
|
+
def self.execute_request(body)
|
21
|
+
body = JSON.generate(body) if !(body.kind_of? String)
|
22
|
+
m = StripeObject.new
|
23
|
+
m.instance_variable_set('@stripe_values', { :body => body })
|
24
|
+
m
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_balance(params={})
|
28
|
+
{
|
29
|
+
:pending => [
|
30
|
+
{:amount => 12345, :currency => "usd"}
|
31
|
+
],
|
32
|
+
:available => [
|
33
|
+
{:amount => 6789, :currency => "usd"}
|
34
|
+
],
|
35
|
+
:livemode => false,
|
36
|
+
:object => "balance"
|
37
|
+
}.merge(params)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_balance_transaction(params={})
|
41
|
+
{
|
42
|
+
:amount => 100,
|
43
|
+
:net => 41,
|
44
|
+
:currency => "usd",
|
45
|
+
:type => "charge",
|
46
|
+
:created => 1371945005,
|
47
|
+
:available_on => 1372549805,
|
48
|
+
:status => "pending",
|
49
|
+
:description => "A test balance transaction",
|
50
|
+
:fee => 59,
|
51
|
+
:object => "balance_transaction"
|
52
|
+
}.merge(params)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_balance_transaction_array
|
56
|
+
{
|
57
|
+
:data => [test_balance_transaction, test_balance_transaction, test_balance_transaction],
|
58
|
+
:object => "list",
|
59
|
+
:url => "/v1/balance/history"
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_application_fee(params={})
|
64
|
+
id = params[:id] || 'fee_test_fee'
|
65
|
+
{
|
66
|
+
:refunded => false,
|
67
|
+
:amount => 100,
|
68
|
+
:application => "ca_test_application",
|
69
|
+
:user => "acct_test_user",
|
70
|
+
:charge => "ch_test_charge",
|
71
|
+
:id => id,
|
72
|
+
:livemode => false,
|
73
|
+
:currency => "usd",
|
74
|
+
:object => "application_fee",
|
75
|
+
:refunds => test_application_fee_refund_array(id),
|
76
|
+
:created => 1304114826
|
77
|
+
}.merge(params)
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_application_fee_refund(params = {})
|
81
|
+
{
|
82
|
+
:object => 'fee_refund',
|
83
|
+
:amount => 30,
|
84
|
+
:currency => "usd",
|
85
|
+
:created => 1308595038,
|
86
|
+
:id => "ref_test_app_fee_refund",
|
87
|
+
:fee => "ca_test_application",
|
88
|
+
:metadata => {}
|
89
|
+
}.merge(params)
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_application_fee_array
|
93
|
+
{
|
94
|
+
:data => [test_application_fee, test_application_fee, test_application_fee],
|
95
|
+
:object => 'list',
|
96
|
+
:url => '/v1/application_fees'
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_application_fee_refund_array(fee_id)
|
101
|
+
{
|
102
|
+
:data => [test_application_fee_refund, test_application_fee_refund, test_application_fee_refund],
|
103
|
+
:object => 'list',
|
104
|
+
:url => '/v1/application_fees/' + fee_id + '/refunds'
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_customer(params={})
|
109
|
+
id = params[:id] || 'c_test_customer'
|
110
|
+
{
|
111
|
+
:subscription_history => [],
|
112
|
+
:bills => [],
|
113
|
+
:charges => [],
|
114
|
+
:livemode => false,
|
115
|
+
:object => "customer",
|
116
|
+
:id => id,
|
117
|
+
:default_card => "cc_test_card",
|
118
|
+
:created => 1304114758,
|
119
|
+
:cards => test_card_array(id),
|
120
|
+
:metadata => {},
|
121
|
+
:subscriptions => test_subscription_array(id)
|
122
|
+
}.merge(params)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_customer_array
|
126
|
+
{
|
127
|
+
:data => [test_customer, test_customer, test_customer],
|
128
|
+
:object => 'list',
|
129
|
+
:url => '/v1/customers'
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_charge(params={})
|
134
|
+
id = params[:id] || 'ch_test_charge'
|
135
|
+
{
|
136
|
+
:refunded => false,
|
137
|
+
:paid => true,
|
138
|
+
:amount => 100,
|
139
|
+
:card => {
|
140
|
+
:type => "Visa",
|
141
|
+
:last4 => "4242",
|
142
|
+
:exp_month => 11,
|
143
|
+
:country => "US",
|
144
|
+
:exp_year => 2012,
|
145
|
+
:id => "cc_test_card",
|
146
|
+
:object => "card"
|
147
|
+
},
|
148
|
+
:id => id,
|
149
|
+
:reason => "execute_charge",
|
150
|
+
:livemode => false,
|
151
|
+
:currency => "usd",
|
152
|
+
:object => "charge",
|
153
|
+
:created => 1304114826,
|
154
|
+
:refunds => test_refund_array(id),
|
155
|
+
:metadata => {}
|
156
|
+
}.merge(params)
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_charge_array
|
160
|
+
{
|
161
|
+
:data => [test_charge, test_charge, test_charge],
|
162
|
+
:object => 'list',
|
163
|
+
:url => '/v1/charges'
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
def test_card_array(customer_id)
|
168
|
+
{
|
169
|
+
:data => [test_card, test_card, test_card],
|
170
|
+
:object => 'list',
|
171
|
+
:url => '/v1/customers/' + customer_id + '/cards'
|
172
|
+
}
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_card(params={})
|
176
|
+
{
|
177
|
+
:type => "Visa",
|
178
|
+
:last4 => "4242",
|
179
|
+
:exp_month => 11,
|
180
|
+
:country => "US",
|
181
|
+
:exp_year => 2012,
|
182
|
+
:id => "cc_test_card",
|
183
|
+
:customer => 'c_test_customer',
|
184
|
+
:object => "card"
|
185
|
+
}.merge(params)
|
186
|
+
end
|
187
|
+
|
188
|
+
def test_coupon(params={})
|
189
|
+
{
|
190
|
+
:duration => 'repeating',
|
191
|
+
:duration_in_months => 3,
|
192
|
+
:percent_off => 25,
|
193
|
+
:id => "co_test_coupon",
|
194
|
+
:object => "coupon"
|
195
|
+
}.merge(params)
|
196
|
+
end
|
197
|
+
|
198
|
+
#FIXME nested overrides would be better than hardcoding plan_id
|
199
|
+
def test_subscription(params = {})
|
200
|
+
plan = params.delete(:plan) || 'gold'
|
201
|
+
{
|
202
|
+
:current_period_end => 1308681468,
|
203
|
+
:status => "trialing",
|
204
|
+
:plan => {
|
205
|
+
:interval => "month",
|
206
|
+
:amount => 7500,
|
207
|
+
:trial_period_days => 30,
|
208
|
+
:object => "plan",
|
209
|
+
:identifier => plan
|
210
|
+
},
|
211
|
+
:current_period_start => 1308595038,
|
212
|
+
:start => 1308595038,
|
213
|
+
:object => "subscription",
|
214
|
+
:trial_start => 1308595038,
|
215
|
+
:trial_end => 1308681468,
|
216
|
+
:customer => "c_test_customer",
|
217
|
+
:id => 's_test_subscription'
|
218
|
+
}.merge(params)
|
11
219
|
end
|
220
|
+
|
221
|
+
def test_refund(params = {})
|
222
|
+
{
|
223
|
+
:object => 'refund',
|
224
|
+
:amount => 30,
|
225
|
+
:currency => "usd",
|
226
|
+
:created => 1308595038,
|
227
|
+
:id => "ref_test_refund",
|
228
|
+
:charge => "ch_test_charge",
|
229
|
+
:metadata => {}
|
230
|
+
}.merge(params)
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_subscription_array(customer_id)
|
234
|
+
{
|
235
|
+
:data => [test_subscription, test_subscription, test_subscription],
|
236
|
+
:object => 'list',
|
237
|
+
:url => '/v1/customers/' + customer_id + '/subscriptions'
|
238
|
+
}
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_refund_array(charge_id)
|
242
|
+
{
|
243
|
+
:data => [test_refund, test_refund, test_refund],
|
244
|
+
:object => 'list',
|
245
|
+
:url => '/v1/charges/' + charge_id + '/refunds'
|
246
|
+
}
|
247
|
+
end
|
248
|
+
|
249
|
+
|
250
|
+
def test_invoice
|
251
|
+
{
|
252
|
+
:id => 'in_test_invoice',
|
253
|
+
:object => 'invoice',
|
254
|
+
:livemode => false,
|
255
|
+
:amount_due => 1000,
|
256
|
+
:attempt_count => 0,
|
257
|
+
:attempted => false,
|
258
|
+
:closed => false,
|
259
|
+
:currency => 'usd',
|
260
|
+
:customer => 'c_test_customer',
|
261
|
+
:date => 1349738950,
|
262
|
+
:lines => {
|
263
|
+
"invoiceitems" => [
|
264
|
+
{
|
265
|
+
:id => 'ii_test_invoice_item',
|
266
|
+
:object => '',
|
267
|
+
:livemode => false,
|
268
|
+
:amount => 1000,
|
269
|
+
:currency => 'usd',
|
270
|
+
:customer => 'c_test_customer',
|
271
|
+
:date => 1349738950,
|
272
|
+
:description => "A Test Invoice Item",
|
273
|
+
:invoice => 'in_test_invoice'
|
274
|
+
},
|
275
|
+
],
|
276
|
+
},
|
277
|
+
:paid => false,
|
278
|
+
:period_end => 1349738950,
|
279
|
+
:period_start => 1349738950,
|
280
|
+
:starting_balance => 0,
|
281
|
+
:subtotal => 1000,
|
282
|
+
:total => 1000,
|
283
|
+
:charge => nil,
|
284
|
+
:discount => nil,
|
285
|
+
:ending_balance => nil,
|
286
|
+
:next_payemnt_attempt => 1349825350,
|
287
|
+
}
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_paid_invoice
|
291
|
+
test_invoice.merge({
|
292
|
+
:attempt_count => 1,
|
293
|
+
:attempted => true,
|
294
|
+
:closed => true,
|
295
|
+
:paid => true,
|
296
|
+
:charge => 'ch_test_charge',
|
297
|
+
:ending_balance => 0,
|
298
|
+
:next_payment_attempt => nil,
|
299
|
+
})
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_invoice_customer_array
|
303
|
+
{
|
304
|
+
:data => [test_invoice],
|
305
|
+
:object => 'list',
|
306
|
+
:url => '/v1/invoices?customer=test_customer'
|
307
|
+
}
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_recipient(params={})
|
311
|
+
id = params[:id] || 'rp_test_recipient'
|
312
|
+
{
|
313
|
+
:name => "Stripe User",
|
314
|
+
:type => "individual",
|
315
|
+
:livemode => false,
|
316
|
+
:object => "recipient",
|
317
|
+
:id => "rp_test_recipient",
|
318
|
+
:cards => test_card_array(id),
|
319
|
+
:default_card => "debit_test_card",
|
320
|
+
:active_account => {
|
321
|
+
:last4 => "6789",
|
322
|
+
:bank_name => "STRIPE TEST BANK",
|
323
|
+
:country => "US",
|
324
|
+
:object => "bank_account"
|
325
|
+
},
|
326
|
+
:created => 1304114758,
|
327
|
+
:verified => true,
|
328
|
+
:metadata => {}
|
329
|
+
}.merge(params)
|
330
|
+
end
|
331
|
+
|
332
|
+
def test_recipient_array
|
333
|
+
{
|
334
|
+
:data => [test_recipient, test_recipient, test_recipient],
|
335
|
+
:object => 'list',
|
336
|
+
:url => '/v1/recipients'
|
337
|
+
}
|
338
|
+
end
|
339
|
+
|
340
|
+
def test_transfer(params={})
|
341
|
+
{
|
342
|
+
:status => 'pending',
|
343
|
+
:amount => 100,
|
344
|
+
:account => {
|
345
|
+
:object => 'bank_account',
|
346
|
+
:country => 'US',
|
347
|
+
:bank_name => 'STRIPE TEST BANK',
|
348
|
+
:last4 => '6789'
|
349
|
+
},
|
350
|
+
:recipient => 'test_recipient',
|
351
|
+
:fee => 0,
|
352
|
+
:fee_details => [],
|
353
|
+
:id => "tr_test_transfer",
|
354
|
+
:livemode => false,
|
355
|
+
:currency => "usd",
|
356
|
+
:object => "transfer",
|
357
|
+
:date => 1304114826,
|
358
|
+
:metadata => {}
|
359
|
+
}.merge(params)
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_transfer_array
|
363
|
+
{
|
364
|
+
:data => [test_transfer, test_transfer, test_transfer],
|
365
|
+
:object => 'list',
|
366
|
+
:url => '/v1/transfers'
|
367
|
+
}
|
368
|
+
end
|
369
|
+
|
370
|
+
def test_canceled_transfer
|
371
|
+
test_transfer.merge({
|
372
|
+
:status => 'canceled'
|
373
|
+
})
|
374
|
+
end
|
375
|
+
|
376
|
+
def test_invalid_api_key_error
|
377
|
+
{
|
378
|
+
"error" => {
|
379
|
+
"type" => "invalid_request_error",
|
380
|
+
"message" => "Invalid API Key provided: invalid"
|
381
|
+
}
|
382
|
+
}
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_invalid_exp_year_error
|
386
|
+
{
|
387
|
+
"error" => {
|
388
|
+
"code" => "invalid_expiry_year",
|
389
|
+
"param" => "exp_year",
|
390
|
+
"type" => "card_error",
|
391
|
+
"message" => "Your card's expiration year is invalid"
|
392
|
+
}
|
393
|
+
}
|
394
|
+
end
|
395
|
+
|
396
|
+
def test_missing_id_error
|
397
|
+
{
|
398
|
+
:error => {
|
399
|
+
:param => "id",
|
400
|
+
:type => "invalid_request_error",
|
401
|
+
:message => "Missing id"
|
402
|
+
}
|
403
|
+
}
|
404
|
+
end
|
405
|
+
|
406
|
+
def test_api_error
|
407
|
+
{
|
408
|
+
:error => {
|
409
|
+
:type => "api_error"
|
410
|
+
}
|
411
|
+
}
|
412
|
+
end
|
413
|
+
|
414
|
+
def test_delete_discount_response
|
415
|
+
{
|
416
|
+
:deleted => true,
|
417
|
+
:id => "di_test_coupon"
|
418
|
+
}
|
419
|
+
end
|
420
|
+
|
12
421
|
end
|
data/stripe-cli.gemspec
CHANGED
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
26
26
|
spec.add_development_dependency 'rspec', '~> 2.12', '>= 2.12.0'
|
27
27
|
spec.add_runtime_dependency 'thor', '~> 0.18', '>= 0.18.1'
|
28
|
-
spec.add_runtime_dependency 'stripe', '~> 1.
|
28
|
+
spec.add_runtime_dependency 'stripe', '~> 1.12', '>= 1.12.0'
|
29
29
|
spec.add_runtime_dependency 'awesome_print', '~> 1.2', '>= 1.2.0'
|
30
30
|
spec.add_runtime_dependency 'parseconfig', '~> 1.0', '>= 1.0.4'
|
31
31
|
spec.add_runtime_dependency 'chronic', '~> 0.10', '>= 0.10.2'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stripe-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex MacCaw
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-09-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -71,20 +71,20 @@ dependencies:
|
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: '1.
|
74
|
+
version: '1.12'
|
75
75
|
- - ">="
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version: 1.
|
77
|
+
version: 1.12.0
|
78
78
|
type: :runtime
|
79
79
|
prerelease: false
|
80
80
|
version_requirements: !ruby/object:Gem::Requirement
|
81
81
|
requirements:
|
82
82
|
- - "~>"
|
83
83
|
- !ruby/object:Gem::Version
|
84
|
-
version: '1.
|
84
|
+
version: '1.12'
|
85
85
|
- - ">="
|
86
86
|
- !ruby/object:Gem::Version
|
87
|
-
version: 1.
|
87
|
+
version: 1.12.0
|
88
88
|
- !ruby/object:Gem::Dependency
|
89
89
|
name: awesome_print
|
90
90
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- lib/stripe/utils.rb
|
187
187
|
- spec/command_spec.rb
|
188
188
|
- spec/commands/charges_spec.rb
|
189
|
+
- spec/commands/recipient_spec.rb
|
189
190
|
- spec/spec_helper.rb
|
190
191
|
- stripe-cli.gemspec
|
191
192
|
homepage: https://stripe.com
|
@@ -208,11 +209,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
208
209
|
version: '0'
|
209
210
|
requirements: []
|
210
211
|
rubyforge_project:
|
211
|
-
rubygems_version: 2.
|
212
|
+
rubygems_version: 2.4.1
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
215
|
summary: Command line interface to Stripe
|
215
216
|
test_files:
|
216
217
|
- spec/command_spec.rb
|
217
218
|
- spec/commands/charges_spec.rb
|
219
|
+
- spec/commands/recipient_spec.rb
|
218
220
|
- spec/spec_helper.rb
|