lib/recurly/coupon.rb
# Redeem a coupon with a given account or account code.
#
# @return [true]
# @param account_or_code [Account, String]
# @param currency [String]
# @param opts [Hash]
# @example
#   coupon = Coupon.find coupon_code
#   coupon.redeem account_code, 'USD', subscription_uuid: 'ab3b1dbabc3195'
#
#   coupon = Coupon.find coupon_code
#   account = Account.find account_code
#   coupon.redeem account
Redeem a coupon with a given account or account code.
Redeem a coupon with a given account or account code .
def redeem account_or_code, currency = nil, extra_opts={}
      return false unless link? :redeem
      account_code = if account_or_code.is_a? Account
        account_or_code.account_code
      else
        account_or_code
      end
      redemption_options = {
        :account_code => account_code,
        :currency     => currency || Recurly.default_currency
      }.merge(extra_opts)
      redemption = redemptions.new(redemption_options)
      Redemption.from_response follow_link(:redeem,
        :body => redemption.to_xml
      )
    rescue API::UnprocessableEntity => e
      redemption.apply_errors e
      redemption
    end
def redeem account_or_code , currency = nil , extra_opts = { } return false unless link? :redeem account_code = if account_or_code . is_a? Account account_or_code . account_code else account_or_code end redemption_options = { :account_code => account_code , :currency => currency || Recurly . default_currency } . merge ( extra_opts ) redemption = redemptions . new ( redemption_options ) Redemption . from_response follow_link ( :redeem , :body => redemption . to_xml ) rescue API :: UnprocessableEntity => e redemption . apply_errors e redemption end
Redeem a coupon with a given account or account code.
Redeem a coupon with a given account or account code .
None
true
account_or_code
<not_specific>
currency
<not_specific>
extra_opts
<not_specific>
<not_specific>
None
example
coupon = Coupon.find coupon_code coupon.redeem account_code, 'USD', subscription_uuid: 'ab3b1dbabc3195' coupon = Coupon.find coupon_code account = Account.find account_code coupon.redeem account
coupon = Coupon . find coupon_code coupon . redeem account_code ' USD ' subscription_uuid : ' ab3b1dbabc3195 ' coupon = Coupon . find coupon_code account = Account . find account_code coupon . redeem account