Skip to content

Instantly share code, notes, and snippets.

@jeanpaulsio
Created April 18, 2017 22:25
Show Gist options
  • Save jeanpaulsio/cb964b07ed97073528b029d36608bd12 to your computer and use it in GitHub Desktop.
Save jeanpaulsio/cb964b07ed97073528b029d36608bd12 to your computer and use it in GitHub Desktop.
app/models/user.rb
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