Skip to content

Commit

Permalink
Merge pull request #227 from recurly/delete_coupon_redemption_from_ac…
Browse files Browse the repository at this point in the history
…count_with_one_or_more_redemptions

updates redemption method for account to get specific redemption base…
  • Loading branch information
bhelx committed Jan 12, 2016
2 parents 0255dae + 4ea57ca commit 9f229f0
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/recurly/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class Account < Resource

has_many :redemptions

def redemption
redemptions.first
def redemption coupon_code
redemptions.detect { |r| r.coupon_code == coupon_code }
end

define_attribute_methods %w(
Expand Down
5 changes: 1 addition & 4 deletions lib/recurly/redemption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ class Redemption < Resource
total_discounted_in_cents
currency
state
coupon_code
subscription_uuid
created_at
)

def destroy_uri
uri + "s/#{uuid}"
end

def save
return false if persisted?
copy_from coupon.redeem account, currency
Expand Down
6 changes: 1 addition & 5 deletions lib/recurly/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -917,16 +917,12 @@ def uri
# race_condition.destroy # raises Recurly::Resource::NotFound
def destroy
return false unless persisted?
@response = API.delete destroy_uri
@response = API.delete uri
@destroyed = true
rescue API::NotFound => e
raise NotFound, e.description
end

def destroy_uri
uri
end

def signable_attributes
Hash[xml_keys.map { |key| [key, self[key]] }]
end
Expand Down

0 comments on commit 9f229f0

Please sign in to comment.