Created
April 18, 2017 22:51
-
-
Save jeanpaulsio/aa8a4e3ed10aec7925987f1142c7ab7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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