Class: Stripe::CLI::Commands::Coupons

Inherits:
Stripe::CLI::Command show all
Defined in:
lib/stripe/cli/commands/coupons.rb

Instance Method Summary collapse

Methods inherited from Stripe::CLI::Command

#inspect

Instance Method Details

#createObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/stripe/cli/commands/coupons.rb', line 37

def create
  unless options[:percent_off] || options[:amount_off]
    discount = ask('(e.g. 25% or $10) specify discount:')
    if discount.end_with?( '%' )
      options[:percent_off] = discount.gsub(/[^\d]/,"").to_i
    else
      options[:amount_off]  = discount.gsub(/[^\d]/,"").to_i
    end
  end
  options[:id] ||= ask('Coupon ID:')
  options[:duration]    ||= ask('(`forever`,`once`, or `repeating`) duration:')
  options[:duration_in_months] ||= ask('for how many months?') if options[:duration] == "repeating"
  options[:redeem_by]   ||= ask('expire on:')
  if options[:redeem_by].empty?
    options.delete(:redeem_by)
  else
    options[:redeem_by] = Chronic.parse(options[:redeem_by]).to_i.to_s
  end
  super Stripe::Coupon, options
end

#delete(coupon_id) ⇒ Object



23
24
25
# File 'lib/stripe/cli/commands/coupons.rb', line 23

def delete coupon_id
  super Stripe::Coupon, coupon_id
end

#find(coupon_id) ⇒ Object



18
19
20
# File 'lib/stripe/cli/commands/coupons.rb', line 18

def find coupon_id
  super Stripe::Coupon, coupon_id
end

#listObject



13
14
15
# File 'lib/stripe/cli/commands/coupons.rb', line 13

def list
  super Stripe::Coupon, options
end