Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billsaysthis/115562 to your computer and use it in GitHub Desktop.
Save billsaysthis/115562 to your computer and use it in GitHub Desktop.
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