Sha256: 878c6914ac17e9f959c5c2a54e1146efe4721b4a621ec42bb38e151ff911fd84

Contents?: true

Size: 832 Bytes

Versions: 20

Compression:

Stored size: 832 Bytes

Contents

module Recurly
  # Redemptions are not top-level resources, but they can be accessed (and
  # created) through {Coupon} instances.
  #
  # @example
  #   coupon = Coupon.find "summer2011"
  #   coupon.redemptions.each { |r| p r }
  #   coupon.redeem Account.find("groupon_lover")
  class Redemption < Resource
    # @return [Coupon]
    belongs_to :coupon
    # @return [Account]
    belongs_to :account, :readonly => false

    define_attribute_methods %w(
      single_use
      total_discounted_in_cents
      currency
      created_at
    )

    def save
      return false if persisted?
      copy_from coupon.redeem account, currency
      true
    rescue Recurly::API::UnprocessableEntity => e
      apply_errors e
      false
    end

    # Redemptions are only writeable through {Coupon} instances.
    embedded!
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
recurly-2.0.14 lib/recurly/redemption.rb
recurly-2.0.13 lib/recurly/redemption.rb
recurly-2.0.12 lib/recurly/redemption.rb
recurly-2.1.5 lib/recurly/redemption.rb
recurly-2.1.4 lib/recurly/redemption.rb
recurly-2.1.3 lib/recurly/redemption.rb
recurly-2.1.2 lib/recurly/redemption.rb
recurly-2.1.1 lib/recurly/redemption.rb
recurly-2.1.0 lib/recurly/redemption.rb
recurly-2.0.11 lib/recurly/redemption.rb
recurly-2.0.10 lib/recurly/redemption.rb
recurly-2.0.9 lib/recurly/redemption.rb
recurly-2.0.8 lib/recurly/redemption.rb
recurly-2.0.6 lib/recurly/redemption.rb
recurly-2.0.5 lib/recurly/redemption.rb
recurly-2.0.4 lib/recurly/redemption.rb
recurly-2.0.3 lib/recurly/redemption.rb
recurly-2.0.2 lib/recurly/redemption.rb
recurly-2.0.1 lib/recurly/redemption.rb
recurly-2.0.0 lib/recurly/redemption.rb