Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Add api view to avoid error in Solidus backend #7

Open
wants to merge 16 commits into
base: lmn-2.0.3-v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 34 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
language: ruby
sudo: false
cache: bundler
language: ruby
dist: trusty
cache:
bundler: true
directories:
- travis_phantomjs
before_install:
- mkdir -p "$HOME/bin" && curl -o "$HOME/bin/phantomjs" https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1 && chmod +x "$HOME/bin/phantomjs"
- export PATH="$HOME/bin:$PATH"
env:
- SOLIDUS_BRANCH=v1.0 DB=mysql
- SOLIDUS_BRANCH=v1.0 DB=postgres
- "gem install bundler -v 1.14.6"
- "bundler -v"
- "phantomjs --version"
- "export PATH=$PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64/bin:$PATH"
- "if [ $(phantomjs --version) != '2.1.1' ]; then rm -rf $PWD/travis_phantomjs; mkdir -p $PWD/travis_phantomjs; fi"
- "if [ $(phantomjs --version) != '2.1.1' ]; then wget https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2; fi"
- "if [ $(phantomjs --version) != '2.1.1' ]; then tar -xvf $PWD/travis_phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -C $PWD/travis_phantomjs; fi"
- "phantomjs --version"
rvm:
- 2.3.0
- 2.3.1
env:
matrix:
- SOLIDUS_BRANCH=v2.0 DB=postgres
- SOLIDUS_BRANCH=v2.1 DB=postgres
- SOLIDUS_BRANCH=v2.2 DB=postgres
- SOLIDUS_BRANCH=v2.3 DB=postgres
- SOLIDUS_BRANCH=v2.4 DB=postgres
- SOLIDUS_BRANCH=v2.5 DB=postgres
- SOLIDUS_BRANCH=v2.6 DB=postgres
- SOLIDUS_BRANCH=v2.7 DB=postgres
- SOLIDUS_BRANCH=master DB=postgres
- SOLIDUS_BRANCH=v2.0 DB=mysql
- SOLIDUS_BRANCH=v2.1 DB=mysql
- SOLIDUS_BRANCH=v2.2 DB=mysql
- SOLIDUS_BRANCH=v2.3 DB=mysql
- SOLIDUS_BRANCH=v2.4 DB=mysql
- SOLIDUS_BRANCH=v2.5 DB=mysql
- SOLIDUS_BRANCH=v2.6 DB=mysql
- SOLIDUS_BRANCH=v2.7 DB=mysql
- SOLIDUS_BRANCH=master DB=mysql
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ Here's a quick guide:
1. Fork the repo.

2. Run the tests. We only take pull requests with passing tests, and it's great
to know that you have a clean slate:
to know that you have a clean state:

$ bash build.sh
$ bundle exec rspec

3. Create new branch then make changes and add tests for your changes. Only
refactoring and documentation changes require no new tests. If you are adding
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013-2015 Spree Commerce and contributors.
Copyright (c) 2019 Solidus Commerce and contributors.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
Expand Down
134 changes: 127 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,132 @@
# Warning
# Solidus PayPal Express

# This project is no longer mainainted or used by Lostmyname. Please use Braintree instead.
[![Build Status](https://travis-ci.org/adnotam/solidus_paypal_express.svg?branch=master)](https://travis-ci.org/adnotam/solidus_paypal_express)

# License
This is a port of the official [spree_paypal_express][4] extension.

Copyright (c) 2013-2015 Spree Commerce and contributors, released under the [New BSD License][3]
Behind-the-scenes, this extension uses [PayPal's Merchant Ruby SDK](https://github.com/paypal/merchant-sdk-ruby).

## Installation

1. Add this extension to your Gemfile with this line:

gem 'solidus_paypal_express', github: 'adnotam/solidus_paypal_express', branch: 'master'

2. Install the gem using Bundler:

bundle install

3. Copy & run migrations

bundle exec rails g solidus_paypal_express:install

4. Restart your server

If your server was running, restart it so that it can find the assets properly.

### Sandbox Setup

#### PayPal

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.

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.

#### Spree Setup

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.

### Production setup

#### PayPal

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.

If you are unable to find it, then follow [PayPal's own documentation](https://developer.paypal.com/webapps/developer/docs/classic/api/apiCredentials/).

#### Spree Setup

Same as sandbox setup, but change "Server" from "sandbox" to "live".

## Configuration

The PayPal Express Checkout has [no less than 4.5 billion configuration options](https://github.com/paypal/merchant-sdk-ruby/blob/1d65e598d2f9f200f85c6b3338d4293dbed576d8/lib/paypal-sdk/merchant/data_types.rb#L830-L959).

This Spree extension supports *some* of those. If your favourite is not here, then please submit an issue about it, or better still a patch to add it in.

### Solution Type

Determines whether or not a user needs a PayPal account to check out.

```ruby
payment_method.preferred_solution_type = "Mark"
# or
payment_method.preferred_solution_type = "Sole"
```

"Mark" if you do want users to have a paypal account, "Sole" otherwise.

### Landing Page

Determines which page to show users once they're redirected to PayPal.

```ruby
payment_method.preferred_landing_page = "Login"
# or
payment_method.preferred_landing_page = "Billing"
```

"Login" will show the users the login form for PayPal, and "Billing" will show them a form where they can enter their credit card data and possibly sign up for a PayPal account (depending on the Solution Type setting above).

### Logo

Determines what logo, if any, to display at the top left of the PayPal express checkout:

```ruby
payment_method.preferred_logourl = 'http://yoursite.com/images/checkout.jpg'
```

**Must** be an absolute path to the image.

## Caveats

*Caveat venditor*

Paypal will refuse any order with a zero cost item.
Any such item will be skipped and not displayed.

PayPal will also refuse any order where item total (before taxes and shipping costs) is zero.
In this case the PayPal checkout page will simply display "Current order".

## Contributing

In the spirit of [free software][1], **everyone** is encouraged to help improve this project.

Here are some ways *you* can contribute:

* by using prerelease versions
* by reporting [bugs][2]
* by suggesting new features
* by writing or editing documentation
* by writing specifications
* by writing code (*no patch is too small*: fix typos, add comments, clean up inconsistent whitespace)
* by refactoring code
* by resolving [issues][2]
* by reviewing patches

Starting point:

* Fork the repo
* Clone your repo
* Run `bundle install`
* Run `bundle exec rake test_app` to create the test application in `spec/dummy`
* Make your changes
* Ensure specs pass by running `bundle exec rspec spec`
* Submit your pull request

Copyright (c) 2019 Solidus Commerce and contributors, released under the [New BSD License][3]

[1]: http://www.fsf.org/licensing/essays/free-sw.html
[2]: https://github.com/spree/better_spree_paypal_express/issues
[3]: https://github.com/spree/better_spree_paypal_express/tree/master/LICENSE.md
[4]: https://github.com/spree/spree_paypal_express
[2]: https://github.com/adnotam/solidus_paypal_express/issues
[3]: https://github.com/adnotam/solidus_paypal_express/tree/master/LICENSE.md
[4]: https://github.com/spree-contrib/better_spree_paypal_express
3 changes: 1 addition & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ end

desc 'Generates a dummy app for testing'
task :test_app do
ENV['LIB_NAME'] = 'spree_paypal_express'
ENV['LIB_NAME'] = 'solidus_paypal_express'
Rake::Task['extension:test_app'].invoke
end

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//= require spree/backend

SpreePaypalExpress = {
SolidusPaypalExpress = {
hideSettings: function(paymentMethod) {
if (SpreePaypalExpress.paymentMethodID && paymentMethod.val() == SpreePaypalExpress.paymentMethodID) {
if (SolidusPaypalExpress.paymentMethodID && paymentMethod.val() == SolidusPaypalExpress.paymentMethodID) {
$('.payment-method-settings').children().hide();
$('#payment_amount').prop('disabled', 'disabled');
$('button[type="submit"]').prop('disabled', 'disabled');
$('#paypal-warning').show();
} else if (SpreePaypalExpress.paymentMethodID) {
} else if (SolidusPaypalExpress.paymentMethodID) {
$('.payment-method-settings').children().show();
$('button[type=submit]').prop('disabled', '');
$('#payment_amount').prop('disabled', '')
Expand All @@ -18,8 +18,8 @@ SpreePaypalExpress = {

$(document).ready(function() {
checkedPaymentMethod = $('[data-hook="payment_method_field"] input[type="radio"]:checked');
SpreePaypalExpress.hideSettings(checkedPaymentMethod);
SolidusPaypalExpress.hideSettings(checkedPaymentMethod);
paymentMethods = $('[data-hook="payment_method_field"] input[type="radio"]').click(function (e) {
SpreePaypalExpress.hideSettings($(e.target));
SolidusPaypalExpress.hideSettings($(e.target));
});
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//= require spree/frontend

SpreePaypalExpress = {
SolidusPaypalExpress = {
updateSaveAndContinueVisibility: function() {
if (this.isButtonHidden()) {
$(this).trigger('hideSaveAndContinue')
Expand All @@ -10,7 +10,7 @@ SpreePaypalExpress = {
},
isButtonHidden: function () {
paymentMethod = this.checkedPaymentMethod();
return (!$('#use_existing_card_yes:checked').length && SpreePaypalExpress.paymentMethodID && paymentMethod.val() == SpreePaypalExpress.paymentMethodID);
return (!$('#use_existing_card_yes:checked').length && SolidusPaypalExpress.paymentMethodID && paymentMethod.val() == SolidusPaypalExpress.paymentMethodID);
},
checkedPaymentMethod: function() {
return $('div[data-hook="checkout_payment_step"] input[type="radio"][name="order[payments_attributes][][payment_method_id]"]:checked');
Expand All @@ -24,8 +24,8 @@ SpreePaypalExpress = {
}

$(document).ready(function() {
SpreePaypalExpress.updateSaveAndContinueVisibility();
SolidusPaypalExpress.updateSaveAndContinueVisibility();
paymentMethods = $('div[data-hook="checkout_payment_step"] input[type="radio"]').click(function (e) {
SpreePaypalExpress.updateSaveAndContinueVisibility();
SolidusPaypalExpress.updateSaveAndContinueVisibility();
});
})
2 changes: 1 addition & 1 deletion app/controllers/spree/paypal_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def gateway
def payment_details items
# This retrieves the cost of shipping after promotions are applied
# For example, if shippng costs $10, and is free with a promotion, shipment_sum is now $10
shipment_sum = current_order.shipments.map(&:final_amount_without_additional_tax).sum
shipment_sum = current_order.shipments.sum(&:total_before_tax)

# This calculates the item sum based upon what is in the order total, but not for shipping
# or tax. This is the easiest way to determine what the items should cost, as that
Expand Down
7 changes: 6 additions & 1 deletion app/models/spree/gateway/pay_pal_express.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ def gateway
mode: preferred_server.present? ? preferred_server : "sandbox",
username: preferred_login,
password: preferred_password,
signature: preferred_signature)
signature: preferred_signature,

# Deliberately set ca_file to nil so the system's Cert Authority is used,
# instead of the bundled paypal.crt file which is out-of-date due to:
# https://www.paypal.com/va/smarthelp/article/discontinue-use-of-verisign-g5-root-certificates-ts2240
ssl_options: { ca_file: nil })
gateway_class.new
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/spree/admin/payments/source_forms/_paypal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<strong><%= Spree.t('no_payment_via_admin_backend', :scope => 'paypal') %></strong>
</div>
<script>
SpreePaypalExpress.paymentMethodID = "<%= payment_method.id %>"
</script>
SolidusPaypalExpress.paymentMethodID = "<%= payment_method.id %>"
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

json.call(payment_source, :id, :token, :created_at)
5 changes: 2 additions & 3 deletions app/views/spree/checkout/payment/_paypal.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

<%= 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, :id => "paypal_button") %>

<script>
SpreePaypalExpress.paymentMethodID = "<%= payment_method.id %>"
</script>
SolidusPaypalExpress.paymentMethodID = "<%= payment_method.id %>"
</script>
7 changes: 6 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
---
en:
spree:
landing_page: Landing Page
logourl: Logo Url
paypal:
already_refunded: "This payment has been refunded and no further action can be taken on it."
no_payment_via_admin_backend: "You cannot charge PayPal accounts through the admin backend at this time."
Expand All @@ -18,4 +20,7 @@ en:
flash:
cancel: "Don't want to use PayPal? No problems."
connection_failed: "Could not connect to PayPal."
generic_error: "PayPal failed. %{reasons}"
generic_error: "PayPal failed. %{reasons}"
signature: Signature
solution: Solution
use_new_layout: Use new layout
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
module SpreePaypalExpress
module SolidusPaypalExpress
module Generators
class InstallGenerator < Rails::Generators::Base

class_option :auto_run_migrations, type: :boolean, default: false

def add_javascripts
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_paypal_express\n"
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/spree_paypal_express\n"
append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/solidus_paypal_express\n"
append_file 'vendor/assets/javascripts/spree/backend/all.js', "//= require spree/backend/solidus_paypal_express\n"
end

def add_stylesheets
frontend_css_file = "vendor/assets/stylesheets/spree/frontend/all.css"
backend_css_file = "vendor/assets/stylesheets/spree/backend/all.css"

if File.exist?(backend_css_file) && File.exist?(frontend_css_file)
inject_into_file frontend_css_file, " *= require spree/frontend/spree_paypal_express\n", before: /\*\//, verbose: true
inject_into_file backend_css_file, " *= require spree/backend/spree_paypal_express\n", before: /\*\//, verbose: true
inject_into_file frontend_css_file, " *= require spree/frontend/solidus_paypal_express\n", before: /\*\//, verbose: true
inject_into_file backend_css_file, " *= require spree/backend/solidus_paypal_express\n", before: /\*\//, verbose: true
end
end

def add_migrations
run 'bundle exec rake railties:install:migrations FROM=spree_paypal_express'
run 'bundle exec rake railties:install:migrations FROM=solidus_paypal_express'
end

def run_migrations
Expand Down
4 changes: 4 additions & 0 deletions lib/solidus_paypal_express.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'solidus_core'
require 'solidus_paypal_express/version'
require 'solidus_paypal_express/engine'
require 'sass/rails'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module SpreePaypalExpress
module SolidusPaypalExpress
class Engine < Rails::Engine
require 'spree/core'
isolate_namespace Spree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# Define your Spree extensions Factories within this file to enable applications, and other extensions to use and override them.
#
# Example adding this to your spec_helper will load these Factories for use:
# require 'spree_paypal_express/factories'
# require 'solidus_paypal_express/factories'
end
3 changes: 3 additions & 0 deletions lib/solidus_paypal_express/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module SolidusPayPalExpress
VERSION = '2.0.0'
end
4 changes: 0 additions & 4 deletions lib/spree_paypal_express.rb

This file was deleted.

3 changes: 0 additions & 3 deletions lib/spree_paypal_express/version.rb

This file was deleted.

Loading