Created
October 23, 2012 00:02
-
-
Save dogweather/3935679 to your computer and use it in GitHub Desktop.
My IPN model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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