Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Redirect Preapproval to Success text

  • Loading branch information...
commit e8e5ed93ae8e891b9e7c75efeb4c43ee42400c95 1 parent de86c8a
@lvxn0va lvxn0va authored
View
9 app/controllers/wepay/ipn_controller.rb
@@ -1,12 +1,7 @@
class Wepay::IpnController < Wepay::ApplicationController
+ include WepayRails::Payments
def update
- conds = {
- :security_token => params[:security_token],
- :checkout_id => params[:checkout_id],
- :preapproval_id => params[:preapproval_id],
- }
-
- record = WepayCheckoutRecord.where(conds).first
+ record = WepayCheckoutRecord.find_by_checkout_id_and_security_token(params[:checkout_id],params[:security_token])
if record.present?
wepay_gateway = WepayRails::Payments::Gateway.new
View
12 app/controllers/wepay/preapproval_controller.rb
@@ -10,7 +10,7 @@ def index
preapproval = wepay_gateway.lookup_preapproval(record.preapproval_id)
#remove unneccesary attributes
- #preapproval.delete_if {|k,v| !record.attributes.include? k.to_s}
+ preapproval.delete_if {|k,v| !record.attributes.include? k.to_s}
record.update_attributes(preapproval)
redirect_to "#{wepay_gateway.configuration[:after_checkout_redirect_uri]}?preapproval_id=#{params[:preapproval_id]}"
@@ -19,6 +19,16 @@ def index
end
end
+ def success
+ response = WepayCheckoutRecord.find(:last)
+ wepay_gateway = WepayRails::Payments::Gateway.new( response.access_token )
+ charge = wepay_gateway.lookup_preapproval(response.preapproval_id)
+
+ response.update_attributes(charge)
+ logger.info params
+ render :text => "PRE-APPROVAL OK from #{response.payer_email} with Pre-approval ID # #{response.preapproval_id}. You can use this Pre-approval Id# to run a charge at a later time."
+ end
+
def new
# create the preapproval - This is TEST info
preapproval_params = {
View
2  lib/api/preapproval_methods.rb
@@ -84,7 +84,7 @@ def preapproval_redirect_uri(security_token)
uri = if @wepay_config[:ipn_callback_uri].present?
@wepay_config[:preapproval_redirect_uri]
else
- "#{@wepay_config[:root_callback_uri]}/wepay/preapproval"
+ "#{@wepay_config[:root_callback_uri]}/wepay/preapproval#success"
end
apply_security_token(uri, security_token)
end

0 comments on commit e8e5ed9

Please sign in to comment.
Something went wrong with that request. Please try again.