public
Created

  • Download Gist
gistfile1.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
# 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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.