forked from spree-contrib/better_spree_paypal_express
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to walkthrough PayPal Express Checkout
Please see issues for what else needs doing.
- Loading branch information
Showing
6 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
module Spree | ||
class PaypalController < Spree::StoreController | ||
def express | ||
# TODO: support adjustments | ||
# Check out the old spree_paypal_express for how it does this | ||
# Specifically, look for "credits" in CheckoutController decorator | ||
items = current_order.line_items.map do |item| | ||
{ name: item.variant.name, | ||
description: item.variant.description[0..120], | ||
quantity: item.quantity, | ||
# TODO: For 2.1.0, make this just item.money.cents | ||
amount: item.money.money.cents } | ||
end | ||
|
||
# TODO: For 2.1.0, make this display_item_total.cents | ||
response = provider.setup_purchase(current_order.display_item_total.money.cents, | ||
ip: request.remote_ip, | ||
return_url: confirm_paypal_url(:payment_method_id => params[:payment_method_id]), | ||
cancel_return_url: cancel_paypal_url, | ||
currency: Spree::Config[:currency], | ||
locale: I18n.locale.to_s.sub(/-/, '_'), | ||
brand_name: Spree::Config[:site_name], | ||
address: address_options, | ||
header_image: 'http://teclacolorida.com/assets/images/logos/schoooools.png', | ||
allow_guest_checkout: 'true', #payment with credit card for non PayPal users | ||
items: items | ||
) | ||
|
||
redirect_to provider.redirect_url_for(response.token) | ||
end | ||
|
||
def confirm | ||
details = provider.details_for(params[:token]) | ||
payer_id = details.payer_id | ||
# TODO: For 2.1.0, make this display_item_total.cents | ||
response = provider.purchase(current_order.display_item_total.money.cents, { | ||
ip: request.remote_addr, | ||
token: params[:token], | ||
payer_id: payer_id, | ||
currency: Spree::Config[:currency] | ||
}) | ||
# TODO: Add payment to order | ||
end | ||
|
||
def cancel | ||
binding.pry | ||
|
||
end | ||
|
||
private | ||
|
||
def provider | ||
Spree::PaymentMethod.find(params[:payment_method_id]).provider | ||
end | ||
|
||
def address_options | ||
{ | ||
:name => current_order.bill_address.try(:full_name), | ||
:zip => current_order.bill_address.zipcode, | ||
:address1 => current_order.bill_address.address1, | ||
:address2 => current_order.bill_address.address2, | ||
:city => current_order.bill_address.city, | ||
:phone => current_order.bill_address.phone, | ||
:state => current_order.bill_address.state_text, | ||
:country => current_order.bill_address.country.iso | ||
} | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= link_to(image_tag("https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif"), paypal_express_url(:payment_method_id => payment_method.id), :method => :post) %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
Spree::Core::Engine.routes.draw do | ||
# Add your extension routes here | ||
post '/paypal', :to => "paypal#express", :as => :paypal_express | ||
get '/paypal/confirm', :to => "paypal#confirm", :as => :confirm_paypal | ||
get '/paypal/cancel', :to => "paypal#cancel", :as => :cancel_paypal | ||
|
||
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