spree_paypal_rest 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +11 -9
- data/app/controllers/spree/checkout_controller_decorator.rb +15 -6
- data/app/models/spree/gateway/paypal_express.rb +37 -10
- data/app/models/spree/gateway/paypal_payment.rb +3 -3
- data/app/models/spree/payment/processing_decorator.rb +15 -0
- data/app/views/spree/admin/payments/source_views/_paypal_express.html.erb +11 -25
- data/app/views/spree/checkout/payment/_paypal_express.html.erb +2 -1
- data/config/locales/en.yml +15 -0
- data/db/migrate/20161212151705_create_spree_paypal_rest_checkouts.rb +2 -1
- data/lib/generators/spree_paypal_rest/install/install_generator.rb +21 -0
- data/lib/spree_paypal_rest/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27c526b59dbe7e1615d629527778f61edfd4209b
|
4
|
+
data.tar.gz: 03e3fa2fe2797fce9e5a3d5ede579539b5e73d83
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eb54bd0178073a50b539c4f13a103d7550ed947731fde72535d4e3922ddd24ef84a3a72aee397a105fb2350dc1bd5c2e36c85512586a4e908d39e2af87d9b0a
|
7
|
+
data.tar.gz: f885102dd498bca45ac6699b6fb79fc41d5862c48bf011566c9b1d8f3ae85d98c62c5b7903b7cc508cecfa72752bbb0b41231c6ef82876436fd7be593d3ad608
|
data/README.md
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# Spree Paypal REST
|
2
|
+
[](https://badge.fury.io/rb/spree_paypal_rest)
|
3
|
+
[](https://travis-ci.org/hugomarquez/spree_paypal_rest)
|
4
|
+
[](https://coveralls.io/github/hugomarquez/spree_paypal_rest?branch=master)
|
5
|
+
|
6
|
+
|
7
|
+
This is a Paypal REST SDK extension for Spree.
|
2
8
|
|
3
|
-
This is a Paypal REST SDK extension for Spree
|
4
9
|
Behind the scenes, this extension uses [Paypal Ruby SDK](https://github.com/paypal/PayPal-Ruby-SDK).
|
5
10
|
|
6
11
|
### Why?
|
7
12
|
* The Official [Spree Paypal Express](https://github.com/spree-contrib/better_spree_paypal_express) extension for Spree latest update was a year ago.
|
8
13
|
* Braintree is not available in some countries.
|
9
|
-
* Support for latest stable
|
10
|
-
*
|
14
|
+
* Support for Spree latest stable release 3.1
|
11
15
|
|
12
16
|
## Features
|
13
17
|
* Paypal Express Checkout/Payment Experience API integration.
|
@@ -19,7 +23,7 @@ Behind the scenes, this extension uses [Paypal Ruby SDK](https://github.com/payp
|
|
19
23
|
Before installing this extension please follow Spree installation Guide.
|
20
24
|
|
21
25
|
cd my_project
|
22
|
-
echo "gem 'spree_paypal_rest', '0.0
|
26
|
+
echo "gem 'spree_paypal_rest', '1.0.0'" >> Gemfile
|
23
27
|
bundle
|
24
28
|
rails g spree_paypal_rest:install
|
25
29
|
rails server
|
@@ -59,16 +63,15 @@ Then enter the following information for your paypal **Business** Account:
|
|
59
63
|
* [Payments API](https://developer.paypal.com/docs/api/payments/)
|
60
64
|
|
61
65
|
## TO-DO
|
62
|
-
* Refund action in Spree::Gateway::PaypalExpress.
|
63
|
-
* Cancel action in Spree::Gateway::PaypalExpress.
|
64
66
|
* Internationalization.
|
65
|
-
* More testing
|
67
|
+
* More testing.
|
66
68
|
* Follow Spree versioning style.
|
69
|
+
* Add store return and cancel url paths for PaypalPayment#payment_payload
|
67
70
|
|
68
71
|
|
69
72
|
## Contributing
|
70
73
|
|
71
|
-
In the spirit of
|
74
|
+
In the spirit of free software, **everyone** is encouraged to help improve this project.
|
72
75
|
|
73
76
|
Here are some ways *you* can contribute:
|
74
77
|
|
@@ -91,7 +94,6 @@ Starting point:
|
|
91
94
|
* Ensure specs pass by running `bundle exec rspec spec`
|
92
95
|
* Submit your pull request
|
93
96
|
|
94
|
-
[1]: http://www.fsf.org/licensing/essays/free-sw.html
|
95
97
|
[2]: https://github.com/spree/better_spree_paypal_express/issues
|
96
98
|
|
97
99
|
## License
|
@@ -20,14 +20,23 @@ module Spree
|
|
20
20
|
paypal_checkout = Spree::PaypalRestCheckout.new(
|
21
21
|
token: params[:token],
|
22
22
|
payer_id: params[:PayerID],
|
23
|
-
|
23
|
+
payment_id: params[:paymentId],
|
24
24
|
state: params[:state]
|
25
25
|
)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
|
27
|
+
payment = @order.payments.last
|
28
|
+
|
29
|
+
if payment.present?
|
30
|
+
if payment.payment_method.kind_of?(Spree::Gateway::PaypalExpress)
|
31
|
+
payment.update!({source: paypal_checkout})
|
32
|
+
end
|
33
|
+
else
|
34
|
+
@order.payments.create!({
|
35
|
+
source: paypal_checkout,
|
36
|
+
amount: @order.total,
|
37
|
+
payment_method: @order.payments.last.payment_method
|
38
|
+
})
|
39
|
+
end
|
31
40
|
|
32
41
|
until @order.state == "complete"
|
33
42
|
if @order.next!
|
@@ -13,6 +13,7 @@ module Spree
|
|
13
13
|
preference :profile_name, :string
|
14
14
|
preference :logo_url, :string, default: 'https://www.paypalobjects.com/webstatic/en_US/i/btn/png/blue-rect-paypal-60px.png'
|
15
15
|
|
16
|
+
# Force auto_capture
|
16
17
|
alias_method :purchase, :authorize
|
17
18
|
|
18
19
|
def source_required?
|
@@ -33,18 +34,45 @@ module Spree
|
|
33
34
|
end
|
34
35
|
|
35
36
|
def purchase(amount, source, options)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
ActiveMerchant::Billing::Response.new(true, '
|
37
|
+
payment = payment_source_class.find(source.payment_id)
|
38
|
+
executed_payment = payment.execute(payer_id: source.payer_id)
|
39
|
+
source.update(state: payment.state)
|
40
|
+
if executed_payment
|
41
|
+
sale_id = payment.transactions.first.related_resources.first.sale.id
|
42
|
+
source.update(sale_id: sale_id)
|
43
|
+
ActiveMerchant::Billing::Response.new(true, 'Success', payment.to_hash, options)
|
44
|
+
else
|
45
|
+
ActiveMerchant::Billing::Response.new(false, payment.error.message, payment.to_hash, options)
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
46
|
-
def refund(
|
47
|
-
|
49
|
+
def refund(amount, source, options)
|
50
|
+
provider
|
51
|
+
payment = payment_source_class.find(source.payment_id)
|
52
|
+
sale_id = payment.transactions.first.related_resources.first.sale.id
|
53
|
+
sale = PayPal::SDK::REST::Sale.find(sale_id)
|
54
|
+
paypal_refund = sale.refund_request({
|
55
|
+
amount:{
|
56
|
+
total: amount,
|
57
|
+
currency: options[:currency]
|
58
|
+
}
|
59
|
+
})
|
60
|
+
if paypal_refund.success?
|
61
|
+
refund_type = payment.amount == amount.to_f ? 'Full' : 'Partial'
|
62
|
+
source.update(
|
63
|
+
refund_id: paypal_refund.id,
|
64
|
+
refund_type: refund_type,
|
65
|
+
refunded_at: paypal_refund.create_time
|
66
|
+
)
|
67
|
+
ActiveMerchant::Billing::Response.new(true, 'Refund Successful', paypal_refund.to_hash, options)
|
68
|
+
else
|
69
|
+
ActiveMerchant::Billing::Response.new(false, paypal_refund.error.message, paypal_refund.to_hash, options)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def cancel(spree_payment_id)
|
74
|
+
spree_payment = Spree::Payment.find(spree_payment_id)
|
75
|
+
refund(spree_payment.amount, spree_payment.source, {currency: spree_payment.currency})
|
48
76
|
end
|
49
77
|
|
50
78
|
def profile_options
|
@@ -59,6 +87,5 @@ module Spree
|
|
59
87
|
temporary: preferred_temporary
|
60
88
|
}
|
61
89
|
end
|
62
|
-
|
63
90
|
end
|
64
91
|
end
|
@@ -14,9 +14,9 @@ module Spree
|
|
14
14
|
payer:{
|
15
15
|
payment_method: 'paypal',
|
16
16
|
payer_info:{
|
17
|
-
first_name: order.
|
18
|
-
last_name: order.
|
19
|
-
email: order.
|
17
|
+
first_name: order.billing_address.first_name,
|
18
|
+
last_name: order.billing_address.last_name,
|
19
|
+
email: order.email,
|
20
20
|
billing_address: billing_address(order)
|
21
21
|
}
|
22
22
|
},
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Spree
|
2
|
+
Payment::Processing.module_eval do
|
3
|
+
|
4
|
+
def cancel!
|
5
|
+
if payment_method.kind_of?(Spree::Gateway::PaypalExpress)
|
6
|
+
response = payment_method.cancel(id)
|
7
|
+
handle_response(response, :void, :failure)
|
8
|
+
else
|
9
|
+
response = payment_method.cancel(response_code)
|
10
|
+
handle_response(response, :void, :failure)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -1,33 +1,19 @@
|
|
1
1
|
<fieldset>
|
2
|
-
<
|
2
|
+
<h3><%= Spree.t(:paypal_express_checkout) %></h3>
|
3
3
|
|
4
|
-
<table class="
|
4
|
+
<table class="table table-condensed">
|
5
5
|
<tr>
|
6
|
-
<th
|
6
|
+
<th><label><%= Spree.t(:paypal_state) %></label></th>
|
7
|
+
<th><label><%= Spree.t(:token) %></label></th>
|
8
|
+
<th><label><%= Spree.t(:paypal_payer_id) %></label></th>
|
9
|
+
<th><label><%= Spree.t(:paypal_payment_id) %></label></th>
|
7
10
|
</tr>
|
8
11
|
<tr>
|
9
|
-
<td
|
10
|
-
<td>
|
11
|
-
|
12
|
-
|
13
|
-
</tr>
|
14
|
-
<tr>
|
15
|
-
<td><label>Token: </label></td>
|
16
|
-
<td>
|
17
|
-
<%= payment.source.token %>
|
18
|
-
</td>
|
19
|
-
</tr>
|
20
|
-
<tr>
|
21
|
-
<td><label>Payer Id: </label></td>
|
22
|
-
<td>
|
23
|
-
<%= payment.source.payer_id %>
|
24
|
-
</td>
|
25
|
-
</tr>
|
26
|
-
<tr>
|
27
|
-
<td><label>Transaction Id: </label></td>
|
28
|
-
<td>
|
29
|
-
<%= payment.source.transaction_id %>
|
30
|
-
</td>
|
12
|
+
<td><%= payment.source.state %></td>
|
13
|
+
<td><%= payment.source.token %></td>
|
14
|
+
<td><%= payment.source.payer_id %></td>
|
15
|
+
<td><%= payment.source.payment_id %></td>
|
31
16
|
</tr>
|
32
17
|
</table>
|
18
|
+
|
33
19
|
</fieldset>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
en:
|
3
|
+
spree:
|
4
|
+
payment_has_been_cancelled: The payment has been cancelled.
|
5
|
+
complete_checkout: Please complete Paypal Express Checkout before continuing
|
6
|
+
paypal_express_checkout: Paypal Express Checkout
|
7
|
+
paypal_transaction: Transaction
|
8
|
+
paypal_state: Payment Status
|
9
|
+
paypal_token: Token
|
10
|
+
paypal_payer_id: Payer ID
|
11
|
+
paypal_payment_id: Transaction ID
|
12
|
+
paypal_refund_id: Refund ID
|
13
|
+
paypal_refund_type: Refund Type
|
14
|
+
paypal_refunded_at: Refunded At
|
15
|
+
paypal_information: PayPal is an easy and secure payment method that allows you to shop on websites and applications around the world without having to share your credit card details.
|
@@ -3,11 +3,12 @@ class CreateSpreePaypalRestCheckouts < ActiveRecord::Migration
|
|
3
3
|
create_table :spree_paypal_rest_checkouts do |t|
|
4
4
|
t.string :token
|
5
5
|
t.string :payer_id
|
6
|
-
t.string :
|
6
|
+
t.string :payment_id, index: true
|
7
7
|
t.string :refund_id, index: true
|
8
8
|
t.string :web_profile_id
|
9
9
|
t.string :refund_type
|
10
10
|
t.string :state
|
11
|
+
t.string :sale_id, index: true
|
11
12
|
t.datetime :refunded_at
|
12
13
|
t.timestamps null: false
|
13
14
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module SpreePaypalRest
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
class_option :auto_run_migrations, type: :boolean, default: false
|
5
|
+
|
6
|
+
def add_migrations
|
7
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_paypal_rest'
|
8
|
+
end
|
9
|
+
|
10
|
+
def run_migrations
|
11
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask('Would you like to run the migrations now? [Y/n]'))
|
12
|
+
if run_migrations
|
13
|
+
run 'bundle exec rake db:migrate'
|
14
|
+
else
|
15
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_paypal_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hugomarquez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -191,12 +191,15 @@ files:
|
|
191
191
|
- app/models/spree/gateway/paypal_payment.rb
|
192
192
|
- app/models/spree/gateway/paypal_rest_base.rb
|
193
193
|
- app/models/spree/gateway/paypal_web_profile.rb
|
194
|
+
- app/models/spree/payment/processing_decorator.rb
|
194
195
|
- app/models/spree/paypal_rest_checkout.rb
|
195
196
|
- app/views/spree/admin/payments/source_forms/_paypal_express.html.erb
|
196
197
|
- app/views/spree/admin/payments/source_views/_paypal_express.html.erb
|
197
198
|
- app/views/spree/checkout/payment/_paypal_express.html.erb
|
199
|
+
- config/locales/en.yml
|
198
200
|
- config/routes.rb
|
199
201
|
- db/migrate/20161212151705_create_spree_paypal_rest_checkouts.rb
|
202
|
+
- lib/generators/spree_paypal_rest/install/install_generator.rb
|
200
203
|
- lib/spree_paypal_rest.rb
|
201
204
|
- lib/spree_paypal_rest/engine.rb
|
202
205
|
- lib/spree_paypal_rest/version.rb
|