paypal 0.5.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/README +19 -27
  2. data/Rakefile +1 -1
  3. data/lib/helper.rb +11 -5
  4. metadata +2 -2
data/README CHANGED
@@ -41,43 +41,35 @@ sandbox account to use while the application is running in development mode.
41
41
 
42
42
  == Example rails controller
43
43
 
44
- class BackendController < ApplicationController
45
- def paypal_ipn
46
- notify = Paypal::Notification.new(request.raw_post)
47
-
48
- order = Order.find(notify.item_id)
49
-
50
- if notify.acknowledge
51
- begin
52
-
53
- if notify.complete? and order.total == notify.amount
54
- order.status = 'success'
55
-
56
- shop.ship(order)
57
- else
58
- logger.error("Failed to verify Paypal's notification, please investigate")
59
- end
60
-
61
- rescue => e
62
- order.status = 'failed'
63
- raise
64
- ensure
44
+ class BackendController < ApplicationController
45
+
46
+ # Simplification, please write better code then this...
47
+ def paypal_ipn
48
+ notify = Paypal::Notification.new(request.raw_post)
49
+
50
+ if notify.acknowledge
51
+ order = Order.find(notify.item_id)
52
+ order.success = (notify.complete? and order.total == notify.amount) ? 'success' : 'failure'
65
53
  order.save
66
54
  end
67
- end
68
-
69
- render :nothing => true
70
- end
71
- end
72
55
 
56
+ render :nothing => true
57
+ end
58
+ end
73
59
 
74
60
  == Example paypal forward page
75
61
 
76
62
  <%= paypal_form_tag %>
77
- <%= paypal_setup "Item 500", Money.us_dollar(50000), "bob@bigbusiness.com" %>
63
+ <%= paypal_setup "Item 500", Money.us_dollar(50000), "bob@bigbusiness.com", :notify_url => url_for(:path_only => false, :action => 'paypal_ipn') %>
78
64
 
79
65
  Please press here to pay $500US using paypal. <br/>
80
66
  <%= submit_tag "Go to paypal >>" %>
81
67
 
82
68
  <% end_form_tag %>
83
69
 
70
+ == Changelog
71
+
72
+ 2005-07-22 -- 0.9.1
73
+ * support for cancel_url as well as notify_url. This means you can now set the IPN callback address from the paypal_setup method and
74
+ you don't have to do that in the paypal admin interface!
75
+ * Removed the actual form tag from the paypal_setup generated code to conform better with docs
data/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'rake/rdoctask'
5
5
  require 'rake/gempackagetask'
6
6
  require 'rake/contrib/rubyforgepublisher'
7
7
 
8
- PKG_VERSION = "0.5.1"
8
+ PKG_VERSION = "0.9.0"
9
9
  PKG_NAME = "paypal"
10
10
  PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
11
11
 
@@ -34,8 +34,12 @@ module Paypal
34
34
  #
35
35
  # The last parameter is a options hash. You can override several things:
36
36
  #
37
- # * <tt>:return_url</tt> -- default is nil. If provided paypal will redirect a user back to your application after a
37
+ # * <tt>:notify_url</tt> -- default is nil. Supply an url which paypal will send its IPN notification to once a
38
+ # purchase is made, canceled or any other status changes occure.
39
+ # * <tt>:return_url</tt> -- default is nil. If provided paypal will redirect a user back to this url after a
38
40
  # successful purchase. Useful for a kind of thankyou page.
41
+ # * <tt>:cancel_url</tt> -- default is nil. If provided paypal will redirect a user back to this url when
42
+ # the user cancels the purchase.
39
43
  # * <tt>:item_name</tt> -- default is 'Store purchase'. This is the name of the purchase which will be displayed
40
44
  # on the paypal page.
41
45
  # * <tt>:no_shipping</tt> -- default is '1'. By default we tell paypal that no shipping is required. Usually
@@ -46,8 +50,9 @@ module Paypal
46
50
  # Examples:
47
51
  #
48
52
  # <%= paypal_setup @order.id, Money.us_dollar(50000), "bob@bigbusiness.com" %>
49
- # <%= paypal_setup @order.id, 50.00, "bob@bigbusiness.com", :currency => 'USD' %>
50
- # <%= paypal_setup @order.id, Money.ca_dollar(50000), "bob@bigbusiness.com", :item_name => 'Snowdevil shop purchase', :return_url => url_for(:only_path => false, :action => 'thankyou') %>
53
+ # <%= paypal_setup @order.id, '50.00', "bob@bigbusiness.com", :currency => 'USD' %>
54
+ # <%= paypal_setup @order.id, '50.00', "bob@bigbusiness.com", :currency => 'USD', :notify_url => url_for(:only_path => false, :action => 'paypal_ipn') %>
55
+ # <%= paypal_setup @order.id, Money.ca_dollar(50000), "bob@bigbusiness.com", :item_name => 'Snowdevil shop purchase', :return_url => paypal_return_url, :cancel_url => paypal_cancel_url, :notify_url => paypal_ipn_url %>
51
56
  #
52
57
  def paypal_setup(item_number, amount, business, options = {})
53
58
 
@@ -65,9 +70,8 @@ module Paypal
65
70
 
66
71
  # Build the form
67
72
  returning button = [] do
68
- button << form_tag(Paypal::Notification.ipn_url)
69
-
70
73
  button << tag(:input, :type => 'hidden', :name => 'cmd', :value => "_xclick")
74
+ button << tag(:input, :type => 'hidden', :name => 'undefined_quantity', :value => 1)
71
75
  button << tag(:input, :type => 'hidden', :name => 'business', :value => business)
72
76
  button << tag(:input, :type => 'hidden', :name => 'amount', :value => amount)
73
77
  button << tag(:input, :type => 'hidden', :name => 'item_number', :value => item_number)
@@ -75,6 +79,8 @@ module Paypal
75
79
  button << tag(:input, :type => 'hidden', :name => 'no_shipping', :value => params[:no_shipping])
76
80
  button << tag(:input, :type => 'hidden', :name => 'no_note', :value => params[:no_note])
77
81
  button << tag(:input, :type => 'hidden', :name => 'return', :value => params[:return_url]) if params[:return_url]
82
+ button << tag(:input, :type => 'hidden', :name => 'notify_url', :value => params[:notify_url]) if params[:notify_url]
83
+ button << tag(:input, :type => 'hidden', :name => 'cancel_return', :value => params[:cancel_url]) if params[:cancel_url]
78
84
 
79
85
  # if amount was a object of type money or something compatible we will use its currency,
80
86
  # otherwise get the currency from the options. default is USD
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
3
3
  specification_version: 1
4
4
  name: paypal
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.1
7
- date: 2005-06-25
6
+ version: 0.9.0
7
+ date: 2005-07-22
8
8
  summary: Paypal IPN integration for rails apps and similar
9
9
  require_paths:
10
10
  - lib