Skip to content

Instantly share code, notes, and snippets.

@dogweather
Created October 23, 2012 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dogweather/3935679 to your computer and use it in GitHub Desktop.
Save dogweather/3935679 to your computer and use it in GitHub Desktop.
My IPN model.
class Ipn < ActiveRecord::Base
belongs_to :user
serialize :message_data, Hash
#
# Return true if this is a payment.
#
def payment?
return paypal_subscription_payment? || weblaws_payment?
end
#
# Return the dollar amount of the IPN. This makes most sense if
# it's a payment or a subscription.
#
def amount
if paypal_subscription_payment?
return message_data['payment_gross']
elsif weblaws_payment?
return message_data['weblaws_payment_amt']
else
raise 'No amount in this IPN'
end
end
#
# Supporting the Paypal protocol
#
def paypal_subscription_payment?
return message_data['txn_type'] == 'subscr_payment'
end
#
# An alternate way to give a user "payment":
# A weblaws payment consists of an arbitrary amount
# (even zero), and an expiration date.
#
# weblaws_payment - boolean
# weblaws_payment_amt - int
# weblaws_expiration_date - date the payment expires
#
#
# Is this a weblaws_payment?
#
def weblaws_payment?
message_data['weblaws_payment'] == true
end
def expiration_date
message_data['weblaws_expiration_date']
end
def has_expiration_date?
expiration_date != nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment