Permalink
Browse files

update paypal-express gem and changed return_url & cancel_url usage

  • Loading branch information...
1 parent cc4ef81 commit 101b2496638971f65d491654952ee6527d05fe61 @nov committed May 23, 2011
Showing with 32 additions and 25 deletions.
  1. +3 −0 Gemfile
  2. +12 −10 Gemfile.lock
  3. +7 −11 app/controllers/payments_controller.rb
  4. +10 −4 app/models/payment.rb
View
@@ -1,5 +1,8 @@
source 'http://rubygems.org'
+gem 'rake', '0.8.7'
+gem 'sprockets', '2.0.0.beta.2'
+
gem 'rails', '3.1.0.beta1'
# Bundle edge Rails instead:
View
@@ -32,20 +32,20 @@ GEM
activesupport (3.1.0.beta1)
multi_json (~> 1.0)
ansi (1.2.5)
- arel (2.1.0)
+ arel (2.1.1)
attr_required (0.0.3)
bcrypt-ruby (2.1.4)
builder (3.0.0)
coffee-script (2.2.0)
coffee-script-source
execjs
- coffee-script-source (1.1.0)
+ coffee-script-source (1.1.1)
erubis (2.7.0)
- execjs (0.3.4)
+ execjs (1.0.0)
multi_json (~> 1.0)
hike (1.0.0)
- i18n (0.6.0beta1)
- jquery-rails (1.0.2)
+ i18n (0.6.0)
+ jquery-rails (1.0.7)
railties (~> 3.0)
thor (~> 0.14)
mail (2.3.0)
@@ -54,15 +54,15 @@ GEM
treetop (~> 1.4.8)
mime-types (1.16)
multi_json (1.0.2)
- paypal-express (0.2.7)
+ paypal-express (0.3.0)
activesupport (>= 2.3)
attr_required (>= 0.0.3)
i18n
restclient_with_cert
pg (0.11.0)
polyglot (0.3.1)
- rack (1.3.0.beta)
- rack-cache (1.0.1)
+ rack (1.3.0.beta2)
+ rack-cache (1.0.2)
rack (>= 0.4)
rack-mount (0.7.4)
rack (>= 1.0.0)
@@ -97,13 +97,13 @@ GEM
sqlite3 (1.3.3)
therubyracer-heroku (0.8.1.pre3)
thor (0.14.6)
- tilt (1.3)
+ tilt (1.3.1)
treetop (1.4.9)
polyglot (>= 0.3.1)
turn (0.8.2)
ansi (>= 1.2.2)
tzinfo (0.3.27)
- uglifier (0.5.3)
+ uglifier (0.5.4)
execjs (>= 0.3.0)
multi_json (>= 1.0.2)
@@ -116,7 +116,9 @@ DEPENDENCIES
paypal-express
pg
rails (= 3.1.0.beta1)
+ rake (= 0.8.7)
sass
+ sprockets (= 2.0.0.beta.2)
sqlite3
therubyracer-heroku (= 0.8.1.pre3)
turn
@@ -3,12 +3,15 @@ class PaymentsController < ApplicationController
def show
@payment = Payment.find_by_identifier! params[:id]
- @details = @payment.details(client)
+ @details = @payment.details
end
def create
payment = Payment.create! params[:payment]
- payment.setup!(client)
+ payment.setup!(
+ success_payments_url,
+ cancel_payments_url
+ )
if payment.popup?
redirect_to payment.popup_uri
else
@@ -17,13 +20,13 @@ def create
end
def destroy
- Payment.find_by_identifier!(params[:id]).unsubscribe!(client)
+ Payment.find_by_identifier!(params[:id]).unsubscribe!
redirect_to root_path, notice: 'Recurring Profile Canceled'
end
def success
handle_callback do |payment|
- payment.complete!(client, params[:PayerID])
+ payment.complete!(params[:PayerID])
flash[:notice] = 'Payment Transaction Completed'
payment_url(payment.identifier)
end
@@ -39,13 +42,6 @@ def cancel
private
- def client
- Paypal::Express::Request.new PAYPAL_CONFIG.merge(
- return_url: success_payments_url,
- cancel_url: cancel_payments_url
- )
- end
-
def handle_callback
payment = Payment.find_by_token! params[:token]
@redirect_uri = yield payment
View
@@ -18,7 +18,7 @@ def ux_type
popup? ? :popup : :redirect
end
- def details(client)
+ def details
if recurring?
client.subscription(self.identifier)
else
@@ -27,9 +27,11 @@ def details(client)
end
attr_reader :redirect_uri, :popup_uri
- def setup!(client)
+ def setup!(return_url, cancel_url)
response = client.setup(
payment_request,
+ return_url,
+ cancel_url,
pay_on_paypal: true,
no_shipping: self.digital?
)
@@ -46,7 +48,7 @@ def cancel!
self
end
- def complete!(client, payer_id = nil)
+ def complete!(payer_id = nil)
if self.recurring?
response = client.subscribe!(self.token, recurring_request)
self.identifier = response.recurring.identifier
@@ -60,13 +62,17 @@ def complete!(client, payer_id = nil)
self
end
- def unsubscribe!(client)
+ def unsubscribe!
client.renew!(self.identifier, :Cancel)
self.cancel!
end
private
+ def client
+ Paypal::Express::Request.new PAYPAL_CONFIG
+ end
+
DESCRIPTION = {
item: 'PayPal Express Sample Item',
instant: 'PayPal Express Sample Instant Payment',

0 comments on commit 101b249

Please sign in to comment.