Skip to content

Commit

Permalink
Make paypal invoice id unique
Browse files Browse the repository at this point in the history
  • Loading branch information
jhannes committed Aug 11, 2011
1 parent 8ce948d commit 982e0e6
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions app/models/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ def special_ticket?
def paid?
paid_amount && paid_amount > 0
end
def self.find_by_invoice(id)
Registration.find(id.to_i - self.invoice_prefix)

def self.find_by_invoice(invoice_id)
if invoice_id =~ /^2011t?-(\d+)$/
Registration.find($1.to_i)
else
raise "Invalid invoice_id #{invoice_id}"
end
end
def self.invoice_prefix
invoice_start = "2011-" if Rails.env == "production"
invoice_start ||= "2011s-"
invoice_start

def invoice_id
return "2011-#{id}" if Rails.env == "production"
return "2011t-#{id}"
end

def payment_url(payment_notifications_url, return_url)
values = {
:business => PAYMENT_CONFIG[:paypal_email],
Expand All @@ -71,7 +77,7 @@ def payment_url(payment_notifications_url, return_url)
:currency_code => 'NOK',
:notify_url => payment_notifications_url,
:return => return_url,
:invoice => Registration.invoice_prefix + id.to_s,
:invoice => invoice_id,
:amount_1 => price,
:item_name_1 => description,
:item_number_1 => '1',
Expand Down

0 comments on commit 982e0e6

Please sign in to comment.