Paypal and Rails

According to the PayPal documentation, you are not guaranteed to
received a PDT due to various reasons.
That’s true. The way I understand it, the reason you wouldn’t get a
PDT message is if the redirect to your site too “too long” and the
user closed the browser. I could see that happening somewhat
frequently, esp. if you have to receive the token, go get the data,
parse it, save it to the database, and build the page before the user
gets a response.

To combat this, the PayPal page that the user sees before the redirect
says something to the effect of “Don’t Close This Window Until It Says
Order Complete” and in the PDT docs it talks about the things you
should display, including “Order Complete”.

Actually, I’m not sure why PDT
exists…
At first I couldn’t figure it out either. It’s not guaranteed, it
depends on the user’s patience, it’s slower, and it’s a pain to code
up this AND IPN.

However, the problem it solves is exactly the original question: How
do I show the user what they ordered on the web page they return to.

If that’s what you need, that’s what it gives you. The problem is
that it kind of appears to be an alternative to IPN, but really it’s
not. You can use either, both, or neither. If I used PDT I’d also
enable IPN.

In my last post I left out what I intended to be the how-to part.

These steps are from memory, so check the facts with the PayPal doc.

One last caveat: PDT requires PayPal to use “AutoReturn” to return
the user to your site. If you are selling a subscription and want
PayPal to create the username and password, you can’t use
“AutoReturn”, so those two scenarios are mutually exclusive.

Thanks,
Joe


“For a new software system, the requirements will not be completely
known until after the users have used it.” Humphrey’s Requirements
Uncertainty Principle.

Dave wrote:

Could you point me to the example or directions you used to set this up?
I currently have a paypal account and just need to be able to verify
that a customer has put through a payment in order for them to access
certain content on my site. Any and all help (and step by steps for this
newbie) are greatly appreciated. Thanks in advance.

Sincerely,

Robert D.

Hi Robert - I basically use the example from the leetsoft paypal
library. Here’s some of my controller that processes the paypal ipn
response. It certainly doesn’t handle all cases, but does seem to get
the job done. I look up user records via their sha1 user id that is set
on the paypal submission form I’ve setup. This allows someone to make a
payment from paypal that doesn’t match the email address I have on file
for them.

Heres some of the controller:

def paypal_ipn

notify = Paypal::Notification.new(request.raw_post)

acknowleged = false
if notify.acknowledge
acknowledged = true
end

if acknowledged

logger.info "item_id: #{notify.item_id}" #1000
logger.info "complete?: #{notify.complete?}" #true
logger.info "status: #{notify.status}" #Completed
logger.info "transaction_id: #{notify.transaction_id}" #8fx...
logger.info "type: #{notify.type}" #subscr_signup, subscr_payment, 

subscr_cancel
logger.info “invoice: #{notify.invoice}” #9348
logger.info “notice amt: #{notify.amount}”

logger.info "subscr_id: #{@params[:subscr_id]}" # 

S-5C507750HS1209630
paid_user = User.find(:first, :conditions => [“sha1(‘somesalt’ + id)
= ?”, notify.invoice.split(“_”)[0] ])

if !paid_user.nil?
  case notify.type
    when "subscr_payment"
      if notify.complete?
        logger.info "got a signup for #{paid_user.id}"
        logger.info "amount: #{notify.amount}"
        logger.info "gross: #{notify.gross}"
        logger.info "fee: #{notify.fee}"

        case notify.item_id
          when "basic_monthly"
            if notify.amount == Money.us_dollar(200)
              logger.info "updating member to 1 and subscr_id to 

#{@params[:subscr_id]}"
paid_user.update_attributes(“member” => 1, “subscr_id”
=> @params[:subscr_id], “subscription_type” => “basic_monthly”,
“subscribed_on” => Time.now)
end
else
# we have an error - don’t do anything…
logger.error “unknown item id ‘#{notify.item_id}’”
end
end # end case notify.item_id
when “subscr_cancel”
logger.info “processing a cancellation…”
begin
user = User.find_by_subscr_id(@params[:subscr_id])
user.update_attributes(“member” => 0, “subscr_id” => nil,
“cancelled_on” => Time.now)
rescue
logger.error $!
end
when “web_accept”
logger.info “got web_accept”
if notify.complete?
case notify.item_id
when “basic_yearly”
if notify.amount == Money.us_dollar(1200)
logger.info “processing a yearl subscription for
#{paid_user.id}”
paid_user.update_attributes(“member” => 1,
“subscription_type” => “basic_yearly”, “subscribed_on” => Time.now)
end
else
logger.info “unknown item id ‘#{notify.item_id}’”
end
end
else
logger.info “unknown type ‘#{notify.type}’”
end # end case notify.type
else
logger.info “unable to find user #{notify.invoice.split(‘_’)[0]}”
end
end

render :nothing => true
end

And here’s some of the form that makes a post to paypal:

Good luck -

Dave
http://www.favoriterun.com

Hi Dave, i used paypal helper for form tag… it default form target to
sanbox address how to change the default address(sandbox address) to
orginal address sub :How to change paypal url from sandbox to papal
original url.

i am using paypal lib – paypal (2.0.0)

i paste my code below… plz check it.

<% form_tag Paypal::Notification.ipn_url do %>
      <%= paypal_setup "Credit purchase", (amounts.collect {|a| 

a.amount}.join(“.”) unless amounts.empty?), “[email protected]”,
:notify_url =>url_for(:only_path => false, :action => ‘paypal_ipn’
),:return =>url_for(:only_path => false, :action =>
‘paypal_success’),:cancel_return => url_for(:only_path => false, :action
=> ‘paypal_failure’),:currency_code => ‘JPY’,:custom =>
request.remote_ip, :on0 => user.id.to_s, :on1 => “xxx”%>
<%= image_submit_tag(“/images/btn_submit1.gif”) %>
<%end%>

Default the submit tag went to sandbox site
(https://www.sandbox.paypal.com/cgi-bin/webscr) , how to change the form
tag to pay (https://www.paypal.com/cgi-bin/webscr)