Created
May 21, 2009 16:41
-
-
Save billsaysthis/115562 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
case @mtype | |
when 'Gold' | |
pmt = PN_MBR_GOLD | |
when 'Regular' | |
pmt = PN_MBR_REGULAR | |
when 'Student' | |
pmt = PN_MBR_STUDENT | |
end | |
setup_response = gateway.setup_purchase(pmt, | |
:ip => request.remote_ip, | |
:return_url => url_for(:action => 'confirm', :only_path => false), | |
:cancel_return_url => url_for(:action => 'new', :only_path => false) | |
) | |
redirect_to gateway.redirect_url_for(setup_response.token) | |
end | |
def confirm | |
redirect_to :action => 'new' unless params[:token] | |
details_response = gateway.details_for(params[:token]) | |
unless details_response.success? | |
@message = details_response.message | |
render 'new' | |
return | |
end | |
@address = details_response.address | |
end | |
def complete(pmt) | |
purchase = gateway.purchase(pmt, | |
:ip => request.remote_ip, | |
:payer_id => params[:payer_id], | |
:token => params[:token] | |
) | |
unless purchase.success? | |
@message = purchase.message | |
render :action => 'error' | |
return | |
end | |
# restful_auth stuff... | |
end | |
private | |
def gateway | |
@gateway ||= PaypalExpressGateway.new( | |
:login => Test_Account, | |
:password => Test_API_Password, | |
:signature => 'some_sig_string' | |
) | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment