spree_paypal_express_mutalis 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +10 -0
- data/.rspec +1 -0
- data/.travis.yml +16 -0
- data/CONTRIBUTING.md +81 -0
- data/Gemfile +8 -0
- data/LICENSE.md +26 -0
- data/README.md +86 -0
- data/Rakefile +23 -0
- data/app/assets/javascripts/admin/spree_paypal_express.js +25 -0
- data/app/assets/javascripts/store/spree_paypal_express.js +19 -0
- data/app/assets/stylesheets/admin/spree_paypal_express.css +3 -0
- data/app/assets/stylesheets/store/spree_paypal_express.css +3 -0
- data/app/controllers/spree/admin/payments_controller_decorator.rb +19 -0
- data/app/controllers/spree/admin/paypal_payments_controller.rb +15 -0
- data/app/controllers/spree/paypal_controller.rb +144 -0
- data/app/models/spree/gateway/pay_pal_express.rb +100 -0
- data/app/models/spree/paypal_express_checkout.rb +4 -0
- data/app/views/spree/admin/payments/_paypal_complete.html.erb +20 -0
- data/app/views/spree/admin/payments/paypal_refund.html.erb +31 -0
- data/app/views/spree/admin/payments/source_forms/_paypal.html.erb +6 -0
- data/app/views/spree/admin/payments/source_views/_paypal.html.erb +35 -0
- data/app/views/spree/checkout/payment/_paypal.html.erb +6 -0
- data/config/locales/en.yml +16 -0
- data/config/routes.rb +18 -0
- data/db/migrate/20130723042610_create_spree_paypal_express_checkouts.rb +8 -0
- data/db/migrate/20130808030836_add_transaction_id_to_spree_paypal_express_checkouts.rb +6 -0
- data/db/migrate/20130809013846_add_state_to_spree_paypal_express_checkouts.rb +5 -0
- data/db/migrate/20130809014319_add_refunded_fields_to_spree_paypal_express_checkouts.rb +8 -0
- data/lib/generators/spree_paypal_express/install/install_generator.rb +31 -0
- data/lib/spree_paypal_express.rb +3 -0
- data/lib/spree_paypal_express/engine.rb +26 -0
- data/lib/spree_paypal_express/factories.rb +6 -0
- data/lib/spree_paypal_express/version.rb +3 -0
- data/script/rails +7 -0
- data/spec/features/paypal_spec.rb +244 -0
- data/spec/models/pay_pal_express_spec.rb +50 -0
- data/spec/spec_helper.rb +45 -0
- data/spree_paypal_express.gemspec +39 -0
- metadata +253 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDE3OGU1MzJiZmIwZDQ5MmQzZmNiNDlhODVlM2YyZjQzMjNlMDAyNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTA3MGM1N2YxNTEzMGYyNmY4MTI0ZGQ3OGNmMjg5MmJmNzU0NjcxNQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YzJhMTlhMzQ2NTdkNTM0NTc4ZGQwOTI2NmI1OTI5ZjQ3Y2ZiOGQ2YjBhNmE0
|
10
|
+
YTcxMmI3MDY4YmIxMDhkYzlmZTBlZTcxNjFiM2Q2MGUyNTViZmEwMWQ0Yjhh
|
11
|
+
ODBkYzdiNWYxMGFhMzNhNWZhZWU5MzQ0ZjE1Nzc5ZWNlYWY4M2M=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTIwMWE5YmFlMWU5YWI1MzlkNzgyMDUyMjAxY2JhY2YyZDI4MWQ3ZjY2ODI0
|
14
|
+
M2YxOWE2OWUxYmNhNjZhZGNhMGU0ZDQyMTg1YTk5NWQzZmZjZDhhMzJhY2Iy
|
15
|
+
OTA0OGU0NjAxZTM2OWI3Y2FlNWI5Y2RiYTc3ODUxMmM4MWFkNzI=
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_script:
|
3
|
+
- sh -e /etc/init.d/xvfb start
|
4
|
+
- export DISPLAY=:99.0
|
5
|
+
- bundle exec rake test_app
|
6
|
+
script:
|
7
|
+
- bundle exec rspec spec
|
8
|
+
notifications:
|
9
|
+
email:
|
10
|
+
- ryan@spreecommerce.com
|
11
|
+
rvm:
|
12
|
+
- 1.9.3
|
13
|
+
- 2.0.0
|
14
|
+
branches:
|
15
|
+
only:
|
16
|
+
- master
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
Spree Paypal Express is an open source project and we encourage contributions. Please see the
|
2
|
+
[contributors guidelines](http://spreecommerce.com/documentation/contributing_to_spree.html)
|
3
|
+
before contributing.
|
4
|
+
|
5
|
+
## Filing an issue
|
6
|
+
|
7
|
+
When filing an issue on this extension, please first do these things:
|
8
|
+
|
9
|
+
* Verify you can reproduce this issue in a brand new application.
|
10
|
+
* Include the `httplog` in that application's Gemfile.
|
11
|
+
* Run through the steps to reproduce the issue again.
|
12
|
+
* Create a Gist which contains the complete output from the server during the course of these transactions.
|
13
|
+
|
14
|
+
This information will help us replicate what's going wrong on the PayPal side of things.
|
15
|
+
|
16
|
+
In the issue itself please provide:
|
17
|
+
|
18
|
+
* A comprehensive list of steps to reproduce the issue.
|
19
|
+
* What you're *expecting* to happen compared with what's *actually* happening.
|
20
|
+
* The version of Spree *and* the version of Rails.
|
21
|
+
* A list of all extensions.
|
22
|
+
* Any relevant stack traces ("Full trace" preferred)
|
23
|
+
* Your Gemfile
|
24
|
+
|
25
|
+
In 99% of cases, this information is enough to determine the cause and solution
|
26
|
+
to the problem that is being described.
|
27
|
+
|
28
|
+
Please remember to format code using triple backticks (\`) so that it is neatly
|
29
|
+
formatted when the issue is posted.
|
30
|
+
|
31
|
+
Any issue that is open for 14 days without actionable information or activity
|
32
|
+
will be marked as "stalled" and then closed. Stalled issues can be re-opened if
|
33
|
+
the information requested is provided.
|
34
|
+
|
35
|
+
## Pull requests
|
36
|
+
|
37
|
+
We gladly accept pull requests to fix bugs and, in some circumstances, add new
|
38
|
+
features to this extension.
|
39
|
+
|
40
|
+
Here's a quick guide:
|
41
|
+
|
42
|
+
1. Fork the repo.
|
43
|
+
|
44
|
+
2. Run the tests. We only take pull requests with passing tests, and it's great
|
45
|
+
to know that you have a clean slate:
|
46
|
+
|
47
|
+
$ bash build.sh
|
48
|
+
|
49
|
+
3. Create new branch then make changes and add tests for your changes. Only
|
50
|
+
refactoring and documentation changes require no new tests. If you are adding
|
51
|
+
functionality or fixing a bug, we need tests!
|
52
|
+
|
53
|
+
4. Push to your fork and submit a pull request. If the changes will apply cleanly
|
54
|
+
to the latest stable branches and master branch, you will only need to submit one
|
55
|
+
pull request.
|
56
|
+
|
57
|
+
At this point you're waiting on us. We like to at least comment on, if not
|
58
|
+
accept, pull requests within three business days (and, typically, one business
|
59
|
+
day). We may suggest some changes or improvements or alternatives.
|
60
|
+
|
61
|
+
Some things that will increase the chance that your pull request is accepted,
|
62
|
+
taken straight from the Ruby on Rails guide:
|
63
|
+
|
64
|
+
* Use Rails idioms and helpers
|
65
|
+
* Include tests that fail without your code, and pass with it
|
66
|
+
* Update the documentation, the surrounding one, examples elsewhere, guides,
|
67
|
+
whatever is affected by your contribution
|
68
|
+
|
69
|
+
Syntax:
|
70
|
+
|
71
|
+
* Two spaces, no tabs.
|
72
|
+
* No trailing whitespace. Blank lines should not have any space.
|
73
|
+
* Prefer &&/|| over and/or.
|
74
|
+
* `MyClass.my_method(my_arg)` not `my_method( my_arg )` or `my_method my_arg`.
|
75
|
+
* `a = b` and not `a=b`.
|
76
|
+
* `a_method { |block| ... }` and not `a_method { | block | ... }`
|
77
|
+
* Follow the conventions you see used in the source already.
|
78
|
+
* -> symbol over lambda
|
79
|
+
* Ruby 1.9 hash syntax over Ruby 1.8 hash syntax
|
80
|
+
|
81
|
+
And in case we didn't emphasize it enough: we love tests!
|
data/Gemfile
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2013 Spree Commerce and contributors.
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without modification,
|
5
|
+
are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice,
|
8
|
+
this list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
* Neither the name Spree nor the names of its contributors may be used to
|
13
|
+
endorse or promote products derived from this software without specific
|
14
|
+
prior written permission.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
17
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
18
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
19
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
20
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
21
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
22
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
23
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
24
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
25
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
26
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# Spree PayPal Express
|
2
|
+
|
3
|
+
This is a "re-do" of the official [spree_paypal_express][4] extension. The old extension is extremely hard to maintain and complex.
|
4
|
+
|
5
|
+
Behind-the-scenes, this extension uses [PayPal's Merchant Ruby SDK](https://github.com/paypal/merchant-sdk-ruby).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
1. Add this extension to your Gemfile with this line:
|
10
|
+
|
11
|
+
gem 'spree_paypal_express', :github => "radar/better_spree_paypal_express", :branch => "2-0-stable"
|
12
|
+
|
13
|
+
2. Install the gem using Bundler:
|
14
|
+
|
15
|
+
bundle install
|
16
|
+
|
17
|
+
3. Copy & run migrations
|
18
|
+
|
19
|
+
bundle exec rails g spree_paypal_express:install
|
20
|
+
|
21
|
+
### Sandbox Setup
|
22
|
+
|
23
|
+
#### PayPal
|
24
|
+
|
25
|
+
Go to [PayPal's Developer Website](https://developer.paypal.com/), sign in with your PayPal account, click "Applications" then "Sandbox Accounts" and create a new "Business" account. Once the account is created, click on the triangle next to its email address, then "Profile". The "API Credentials" tab will provide your API credentials (probably). If this tab is blank, try refreshing the page.
|
26
|
+
|
27
|
+
You will also need a "Personal" account to test the transactions on your site. Create this in the same way, finding the account information under "Profile" as well. You may need to set a password in order to be able to log in to PayPal's sandbox for this user.
|
28
|
+
|
29
|
+
#### Spree Setup
|
30
|
+
|
31
|
+
In Spree, go to the admin backend, click "Configuration" and then "Payment Methods" and create a new payment method. Select "Spree::Gateway::PayPalExpress" as the provider, and click "Create". Enter the email address, password and signature from the "API Credentials" tab for the **Business** account on PayPal.
|
32
|
+
|
33
|
+
### Production setup
|
34
|
+
|
35
|
+
#### PayPal
|
36
|
+
|
37
|
+
Sign in to PayPal, then click "Profile" and then (under "Account Information" on the left), click "API Access". On this page, select "Option 2" and click "View API Signature". The username, password and signature will be displayed on this screen.
|
38
|
+
|
39
|
+
If you are unable to find it, then follow [PayPal's own documentation](https://developer.paypal.com/webapps/developer/docs/classic/api/apiCredentials/).
|
40
|
+
|
41
|
+
#### Spree Setup
|
42
|
+
|
43
|
+
Same as sandbox setup, but change "Server" from "sandbox" to "live".
|
44
|
+
|
45
|
+
## Caveats
|
46
|
+
|
47
|
+
*Caveat venditor*
|
48
|
+
|
49
|
+
Paypal will refuse any order with a zero cost item.
|
50
|
+
Any such item will be skipped and not displayed.
|
51
|
+
|
52
|
+
PayPal will also refuse any order where item total (before taxes and shipping costs) is zero.
|
53
|
+
In this case the PayPal checkout page will simply display "Current order".
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
In the spirit of [free software][1], **everyone** is encouraged to help improve this project.
|
58
|
+
|
59
|
+
Here are some ways *you* can contribute:
|
60
|
+
|
61
|
+
* by using prerelease versions
|
62
|
+
* by reporting [bugs][2]
|
63
|
+
* by suggesting new features
|
64
|
+
* by writing or editing documentation
|
65
|
+
* by writing specifications
|
66
|
+
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
|
67
|
+
* by refactoring code
|
68
|
+
* by resolving [issues][2]
|
69
|
+
* by reviewing patches
|
70
|
+
|
71
|
+
Starting point:
|
72
|
+
|
73
|
+
* Fork the repo
|
74
|
+
* Clone your repo
|
75
|
+
* Run `bundle install`
|
76
|
+
* Run `bundle exec rake test_app` to create the test application in `spec/dummy`
|
77
|
+
* Make your changes
|
78
|
+
* Ensure specs pass by running `bundle exec rspec spec`
|
79
|
+
* Submit your pull request
|
80
|
+
|
81
|
+
Copyright (c) 2013 Spree Commerce and contributors, released under the [New BSD License][3]
|
82
|
+
|
83
|
+
[1]: http://www.fsf.org/licensing/essays/free-sw.html
|
84
|
+
[2]: https://github.com/spree/better_spree_paypal_express/issues
|
85
|
+
[3]: https://github.com/spree/better_spree_paypal_express/tree/master/LICENSE.md
|
86
|
+
[4]: https://github.com/spree/spree_paypal_express
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/packagetask'
|
5
|
+
require 'rubygems/package_task'
|
6
|
+
require 'rspec/core/rake_task'
|
7
|
+
require 'spree/testing_support/extension_rake'
|
8
|
+
|
9
|
+
RSpec::Core::RakeTask.new
|
10
|
+
|
11
|
+
task default: :spec
|
12
|
+
|
13
|
+
spec = eval(File.read('spree_paypal_express.gemspec'))
|
14
|
+
|
15
|
+
Gem::PackageTask.new(spec) do |p|
|
16
|
+
p.gem_spec = spec
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'Generates a dummy app for testing'
|
20
|
+
task :test_app do
|
21
|
+
ENV['LIB_NAME'] = 'spree_paypal_express'
|
22
|
+
Rake::Task['extension:test_app'].invoke
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
//= require admin/spree_backend
|
2
|
+
|
3
|
+
SpreePaypalExpress = {
|
4
|
+
hideSettings: function(paymentMethod) {
|
5
|
+
if (SpreePaypalExpress.paymentMethodID && paymentMethod.val() == SpreePaypalExpress.paymentMethodID) {
|
6
|
+
$('.payment-method-settings').children().hide();
|
7
|
+
$('#payment_amount').attr('disabled', 'disabled');
|
8
|
+
$('button[type="submit"]').attr('disabled', 'disabled');
|
9
|
+
$('#paypal-warning').show();
|
10
|
+
} else if (SpreePaypalExpress.paymentMethodID) {
|
11
|
+
$('.payment-method-settings').children().show();
|
12
|
+
$('button[type=submit]').attr('disabled', '');
|
13
|
+
$('#payment_amount').attr('disabled', '')
|
14
|
+
$('#paypal-warning').hide();
|
15
|
+
}
|
16
|
+
}
|
17
|
+
}
|
18
|
+
|
19
|
+
$(document).ready(function() {
|
20
|
+
checkedPaymentMethod = $('#payment-methods input[type="radio"]:checked');
|
21
|
+
SpreePaypalExpress.hideSettings(checkedPaymentMethod);
|
22
|
+
paymentMethods = $('#payment-methods input[type="radio"]').click(function (e) {
|
23
|
+
SpreePaypalExpress.hideSettings($(e.target));
|
24
|
+
});
|
25
|
+
})
|
@@ -0,0 +1,19 @@
|
|
1
|
+
//= require store/spree_frontend
|
2
|
+
|
3
|
+
SpreePaypalExpress = {
|
4
|
+
hidePaymentSaveAndContinueButton: function(paymentMethod) {
|
5
|
+
if (SpreePaypalExpress.paymentMethodID && paymentMethod.val() == SpreePaypalExpress.paymentMethodID) {
|
6
|
+
$('.continue').hide();
|
7
|
+
} else {
|
8
|
+
$('.continue').show();
|
9
|
+
}
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
$(document).ready(function() {
|
14
|
+
checkedPaymentMethod = $('div[data-hook="checkout_payment_step"] input[type="radio"]:checked');
|
15
|
+
SpreePaypalExpress.hidePaymentSaveAndContinueButton(checkedPaymentMethod);
|
16
|
+
paymentMethods = $('div[data-hook="checkout_payment_step"] input[type="radio"]').click(function (e) {
|
17
|
+
SpreePaypalExpress.hidePaymentSaveAndContinueButton($(e.target));
|
18
|
+
});
|
19
|
+
})
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Spree::Admin::PaymentsController.class_eval do
|
2
|
+
def paypal_refund
|
3
|
+
if request.get?
|
4
|
+
if @payment.source.state == 'refunded'
|
5
|
+
flash[:error] = Spree.t(:already_refunded, :scope => 'paypal')
|
6
|
+
redirect_to admin_order_payment_path(@order, @payment)
|
7
|
+
end
|
8
|
+
elsif request.post?
|
9
|
+
response = @payment.payment_method.refund(@payment, params[:refund_amount])
|
10
|
+
if response.success?
|
11
|
+
flash[:success] = Spree.t(:refund_successful, :scope => 'paypal')
|
12
|
+
redirect_to admin_order_payments_path(@order)
|
13
|
+
else
|
14
|
+
flash.now[:error] = Spree.t(:refund_unsuccessful, :scope => 'paypal') + " (#{response.errors.first.long_message})"
|
15
|
+
render
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
class Admin::PaypalPaymentsController < Spree::Admin::BaseController
|
3
|
+
before_filter :load_order
|
4
|
+
|
5
|
+
def index
|
6
|
+
@payments = @order.payments.includes(:payment_method).where(:spree_payment_methods => { :type => "Spree::Gateway::PayPalExpress" })
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def load_order
|
12
|
+
@order = Spree::Order.where(:number => params[:order_id]).first
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
module Spree
|
2
|
+
class PaypalController < StoreController
|
3
|
+
def express
|
4
|
+
items = current_order.line_items.map do |item|
|
5
|
+
{
|
6
|
+
:Name => item.product.name,
|
7
|
+
:Quantity => item.quantity,
|
8
|
+
:Amount => {
|
9
|
+
:currencyID => current_order.currency,
|
10
|
+
:value => item.price
|
11
|
+
},
|
12
|
+
:ItemCategory => "Physical"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
tax_adjustments = current_order.adjustments.tax
|
17
|
+
shipping_adjustments = current_order.adjustments.shipping
|
18
|
+
|
19
|
+
current_order.adjustments.eligible.each do |adjustment|
|
20
|
+
next if (tax_adjustments + shipping_adjustments).include?(adjustment)
|
21
|
+
items << {
|
22
|
+
:Name => adjustment.label,
|
23
|
+
:Quantity => 1,
|
24
|
+
:Amount => {
|
25
|
+
:currencyID => current_order.currency,
|
26
|
+
:value => adjustment.amount
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
# Because PayPal doesn't accept $0 items at all.
|
32
|
+
# See #10
|
33
|
+
# https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_ECCustomizing
|
34
|
+
# "It can be a positive or negative value but not zero."
|
35
|
+
items.reject! do |item|
|
36
|
+
item[:Amount][:value].zero?
|
37
|
+
end
|
38
|
+
|
39
|
+
pp_request = provider.build_set_express_checkout({
|
40
|
+
:SetExpressCheckoutRequestDetails => {
|
41
|
+
:ReturnURL => confirm_paypal_url(:payment_method_id => params[:payment_method_id]),
|
42
|
+
:CancelURL => cancel_paypal_url,
|
43
|
+
:PaymentDetails => [payment_details(items)]
|
44
|
+
}})
|
45
|
+
|
46
|
+
begin
|
47
|
+
pp_response = provider.set_express_checkout(pp_request)
|
48
|
+
if pp_response.success?
|
49
|
+
redirect_to provider.express_checkout_url(pp_response)
|
50
|
+
else
|
51
|
+
flash[:error] = "PayPal failed. #{pp_response.errors.map(&:long_message).join(" ")}"
|
52
|
+
redirect_to checkout_state_path(:payment)
|
53
|
+
end
|
54
|
+
rescue SocketError
|
55
|
+
flash[:error] = "Could not connect to PayPal."
|
56
|
+
redirect_to checkout_state_path(:payment)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def confirm
|
61
|
+
order = current_order
|
62
|
+
order.payments.create!({
|
63
|
+
:source => Spree::PaypalExpressCheckout.create({
|
64
|
+
:token => params[:token],
|
65
|
+
:payer_id => params[:PayerID]
|
66
|
+
} ),
|
67
|
+
:amount => order.total,
|
68
|
+
:payment_method => payment_method
|
69
|
+
} )
|
70
|
+
order.next
|
71
|
+
if order.complete?
|
72
|
+
flash.notice = Spree.t(:order_processed_successfully)
|
73
|
+
redirect_to order_path(order, :token => order.token)
|
74
|
+
else
|
75
|
+
redirect_to checkout_state_path(order.state)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def cancel
|
80
|
+
flash[:notice] = "Don't want to use PayPal? No problems."
|
81
|
+
redirect_to checkout_state_path(current_order.state)
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def payment_method
|
87
|
+
Spree::PaymentMethod.find(params[:payment_method_id])
|
88
|
+
end
|
89
|
+
|
90
|
+
def provider
|
91
|
+
payment_method.provider
|
92
|
+
end
|
93
|
+
|
94
|
+
def payment_details items
|
95
|
+
item_sum = items.sum { |i| i[:Quantity] * i[:Amount][:value] }
|
96
|
+
if item_sum.zero?
|
97
|
+
# Paypal does not support no items or a zero dollar ItemTotal
|
98
|
+
# This results in the order summary being simply "Current purchase"
|
99
|
+
{
|
100
|
+
:OrderTotal => {
|
101
|
+
:currencyID => current_order.currency,
|
102
|
+
:value => current_order.total
|
103
|
+
}
|
104
|
+
}
|
105
|
+
else
|
106
|
+
{
|
107
|
+
:OrderTotal => {
|
108
|
+
:currencyID => current_order.currency,
|
109
|
+
:value => current_order.total
|
110
|
+
},
|
111
|
+
:ItemTotal => {
|
112
|
+
:currencyID => current_order.currency,
|
113
|
+
:value => item_sum
|
114
|
+
},
|
115
|
+
:ShippingTotal => {
|
116
|
+
:currencyID => current_order.currency,
|
117
|
+
:value => current_order.ship_total
|
118
|
+
},
|
119
|
+
:TaxTotal => {
|
120
|
+
:currencyID => current_order.currency,
|
121
|
+
:value => current_order.tax_total
|
122
|
+
},
|
123
|
+
:ShipToAddress => address_options,
|
124
|
+
:PaymentDetailsItem => items,
|
125
|
+
:ShippingMethod => "Shipping Method Name Goes Here",
|
126
|
+
:PaymentAction => "Sale"
|
127
|
+
}
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def address_options
|
132
|
+
{
|
133
|
+
:Name => current_order.bill_address.try(:full_name),
|
134
|
+
:Street1 => current_order.bill_address.address1,
|
135
|
+
:Street2 => current_order.bill_address.address2,
|
136
|
+
:CityName => current_order.bill_address.city,
|
137
|
+
# :phone => current_order.bill_address.phone,
|
138
|
+
:StateOrProvince => current_order.bill_address.state_text,
|
139
|
+
:Country => current_order.bill_address.country.iso,
|
140
|
+
:PostalCode => current_order.bill_address.zipcode
|
141
|
+
}
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|