-
-
Save richardsondx/11be6cef6a97632343b9 to your computer and use it in GitHub Desktop.
Paypa Express Payment in Rails 3.2
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
#Initializer | |
ActiveMerchant::Billing::Base.mode = :test | |
::GATEWAY = ActiveMerchant::Billing::PaypalExpressGateway.new( | |
:login => "rico_1340337222_biz_api1.gmail.com", | |
:password => "I_PUT_MY_PASS_HERE", | |
:signature => "I_PUT_MY_SIGNATURE_HERE", | |
:allow_guest_checkout => true | |
) |
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
This transaction is invalid. Please return to the recipient's website to complete your transaction using their regular checkout flow. | |
Return to merchant | |
At this time, we are unable to process your request. Please return to and try another option. | |
--- | |
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
<%= link_to image_tag('http://img36.imageshack.us/img36/249/buttonpaypal.png'), action: 'checkout', controller: 'orders'%> |
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
class Order < ActiveRecord::Base | |
attr_accessible :token | |
def confirm | |
redirect_to :action => root_path unless params[:token] | |
details_response = ::GATEWAY.details_for(params[:token]) | |
if !details_response.success? | |
@message = details_response.message | |
render :action => 'error' | |
return | |
end | |
@address = details_response.address | |
end | |
def new | |
@order = Order.new(:express_token => params[:token]) | |
end | |
def complete | |
purchase = ::GATEWAY.purchase(5000, | |
:ip => request.remote_ip, | |
:payer_id => params[:payer_id], | |
:token => params[:token] | |
) | |
if !purchase.success? | |
@message = purchase.message | |
render :action => 'error' | |
return | |
end | |
end | |
end |
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
class OrdersController < ApplicationController | |
include ActiveMerchant::Billing | |
def checkout | |
setup_response = ::GATEWAY.setup_purchase(2000, | |
:ip => request.remote_ip, | |
:return_url => url_for('confirm'), | |
:cancel_return_url => url_for(root_path) | |
) | |
redirect_to ::GATEWAY.redirect_url_for(setup_response.token) | |
end | |
end |
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
resources :orders do | |
# Im not sure why 'get :checkout' by itself doesn't work. | |
get :checkout, :on => :new | |
get :confirm | |
get :complete | |
end | |
get "pages/index" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment