Created
April 18, 2017 22:25
-
-
Save jeanpaulsio/cb964b07ed97073528b029d36608bd12 to your computer and use it in GitHub Desktop.
app/models/user.rb
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
def stripe_coupon | |
customer = Stripe::Customer.retrieve(self.stripe_id) | |
if customer['discount'] == nil | |
false | |
else | |
coupons = customer['discount']['coupon'] | |
end | |
rescue | |
false | |
end | |
def coupon_discount | |
if self.coupon_percent_off | |
self.coupon_percent_off | |
elsif self.coupon_amount_discount | |
self.coupon_amount_discount | |
end | |
end | |
def coupon_percent_off | |
if self.stripe_coupon['percent_off'] != nil | |
self.stripe_coupon['percent_off'].to_s + "%" + " Off" | |
end | |
end | |
def coupon_amount_discount | |
if self.stripe_coupon['amount_off'] != nil | |
"$" + (self.stripe_coupon['amount_off'].to_i / 100).to_s + " Off" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment