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 Dempsey
>
> 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:
>
> <form action="<%= Paypal::Notification.ipn_url %>" method="post">
> <input name="cmd" type="hidden" value="_xclick" />
> <input name="quantity" type="hidden" value="1" />
> <input name="business" type="hidden" value="<%= paypal_payto %>" />
> <input name="amount" type="hidden" value="12.95" />
> <input name="item_number" type="hidden" value="basic_yearly" />
> <input name="item_name" type="hidden" value="Yearly" />
> <input name="no_shipping" type="hidden" value="1" />
> <input name="no_note" type="hidden" value="1" />
> <input type="hidden" name="return"
> value="http://www.yourwebsite.com/payment/thankyou" />
> <input type="hidden" name="cancel_return"
> value="http://www.yourwebsite.com/payment/cancel" />
> <input type="hidden" name="notify_url"
> value="http://www.yourwebsite.com/payment/paypal_ipn" />
> <input type="hidden" name="invoice" value="<%= encode_userid %>" />
>
> <input name="currency_code" type="hidden" value="USD" />
> <input name="charset" type="hidden" value="utf-8" />
> <input type="image"
> src="https://www.paypal.com/en_US/i/btn/x-click-but01.gif" border="0"
> name="submit" alt="Make payments with PayPal - it's fast, free and
> secure!">
> </form>
>
>
> 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)
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---