Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@twinge
Created February 5, 2011 02:20
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 twinge/812136 to your computer and use it in GitHub Desktop.
Save twinge/812136 to your computer and use it in GitHub Desktop.
# paypal
def checkout_paypal
if cart_total == 0
alert_error("Your cart is empty. If you have just placed an order, please check your email for the confirmation")
redirect_to :back and return
end
setup_response = express_gateway.setup_purchase(100 * in_current_currency(cart_total),
:ip => request.remote_ip,
:return_url => url_for(:action => 'confirm', :only_path => false),
:cancel_return_url => url_for(:controller => 'marketplace', :only_path => false),
:currency => current_currency
)
redirect_to express_gateway.redirect_url_for(setup_response.token)
end
# paypal
def confirm
redirect_to :action => 'index' unless params[:token]
session[:bill_to] = nil
session[:ship_to] = nil
customer
billing
details_response = express_gateway.details_for(params[:token])
if !details_response.success?
@message = details_response.message
render :action => 'error'
return
end
@address = details_response.address
customer.update_attributes(:street_address => @address['address1'], :zip_code => @address['zip'], :state => @address['state'], :country => @address['country'], :city => @address['city'])
end
# paypal
def error
end
# Paypal
def complete
return false unless create_max_mind
purchase = express_gateway.purchase(100 * in_current_currency(cart_total),
:ip => request.remote_ip,
:payer_id => params[:payer_id],
:token => params[:token],
:currency => current_currency
)
if !purchase.success?
@message = purchase.message
render :action => 'error'
return
else
store_transaction(purchase, 'paypal')
clear_cart
session[:bill_to] = nil
session[:ship_to] = nil
redirect_to user_purchases_path(current_user), :success => "Your order was successfully placed"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment