Hello!
I'm trying to integrate PayPal into my (first) Rails app. I've been looking at RailsCast #142, #142 PayPal Notifications - RailsCasts. But I don't get it to work. My app isn't a normal e-commerce site, it's a buy and sell site. Every ad has a 'published' boolean, which I want to set to true if the user completes the payment process. My code looks like this.
Order model:
class Order < ActiveRecord::Base belongs_to :ad
def paypal_url(return_url, notify_url) values = { :business => 'anders_1291665108_biz@my_mail.se', :cmd => '_xclick', :currency_code => "SEK", :upload => 1, :return => return_url, :invoice => id, :amount => 15, :item_name => "Ad", :quantity => 1, :lc => "SE", :notify_url => notify_url } "Digital Wallets, Money Management, and More | PayPal US | PayPal US; + values.to_query end end
My Payment Notifications Controller:
class PaymentNotificationsController < ApplicationController protect_from_forgery :except => [:create]
def create PaymentNotification.create!(:params => params, :ad_id => params[:invoice], :status => params[:payment_status], :transaction_id => params[:txn_id]) render :nothing => true end end
And my Payment Notification model (where I think the problem is):
class PaymentNotification < ActiveRecord::Base belongs_to :ad serialize :params after_create :mark_ad_as_purchased
def mark_ad_as_purchased if status == "Completed" ad.update_attribute(:published => true) end end end
I get an error that says:
NoMethodError in Payment notificationsController#create
You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.update_attribute
Any help or tips would be appreciated!
Thanks Anders