Skip to content

Instantly share code, notes, and snippets.

@jeanpaulsio
Created April 18, 2017 22:51
Show Gist options
  • Save jeanpaulsio/aa8a4e3ed10aec7925987f1142c7ab7b to your computer and use it in GitHub Desktop.
Save jeanpaulsio/aa8a4e3ed10aec7925987f1142c7ab7b to your computer and use it in GitHub Desktop.
class CouponService
def initialize(user)
@customer = StripeWrapper.new.retrieve_customer(user)
end
def stripe_coupon
@customer["discount"]["coupon"] unless @customer["discount"].nil?
rescue
false
end
def stripe_coupon_id
@customer["discount"]["coupon"]["id"]
end
def discount
percent_off || amount_off
end
def percent_off
return if @customer["discount"]["coupon"]["percent_off"].nil?
percent_off = @customer["discount"]["coupon"]["percent_off"]
percent_off = "#{percent_off.to_s} \% Off"
return percent_off
end
def amount_off
return if @customer["discount"]["coupon"]["amount_off"].nil?
amount_off = @customer["discount"]["coupon"]["amount_off"]
amount_off = "$#{(amount_off.to_i / 100).to_s} Off"
return amount_off
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment