spree_pag_seguro 1.0.0.rc1 → 1.0.0.rc2
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.
- data/app/controllers/spree/pag_seguro_controller.rb +0 -42
- data/app/models/spree/order_decorator.rb +0 -4
- data/app/models/spree/pag_seguro_payment.rb +34 -0
- data/app/models/spree/payment_method/pag_seguro_method.rb +4 -4
- data/app/overrides/replace_payment_info.rb +6 -0
- data/app/views/spree/checkout/payment/_order_details.html.erb +8 -0
- data/app/views/spree/checkout/payment/_pagseguromethod.html.erb +2 -0
- data/db/migrate/20120216223731_create_db:migrate:20120216223950_create_spree_pag_seguro_payments.rb +8 -0
- data/lib/spree_pag_seguro/engine.rb +0 -4
- metadata +22 -24
- data/app/controllers/spree/base_controller_decorator.rb +0 -13
- data/app/controllers/spree/checkout_controller_decorator.rb +0 -38
- data/app/controllers/spree/payment_notifications_controller.rb +0 -79
- data/app/views/spree/checkout/_pag_seguro_checkout.html.erb +0 -3
- data/app/views/spree/checkout/edit.html.erb +0 -28
- data/app/views/spree/pag_seguro_payments/successful.html.erb +0 -1
- data/lib/spree_pag_seguro_configuration.rb +0 -6
@@ -10,28 +10,12 @@ module Spree
|
|
10
10
|
Order.transaction do
|
11
11
|
@order = Spree::Order.find(notification.id)
|
12
12
|
|
13
|
-
#create payment for this order
|
14
|
-
payment = Spree::Payment.new
|
15
|
-
|
16
13
|
# 1. Assume that if payment notification comes, it's exactly for the amount
|
17
14
|
# sent to pagseguro (safe assumption -- cart can't be edited while on pagseguro)
|
18
15
|
# 2. Can't use Order#total, as it's intercepted by spree-multi-currency
|
19
16
|
# which might lead to lots of false "credit owed" payment states
|
20
17
|
# (when they should be "complete")
|
21
|
-
payment.amount = @order.read_attribute(:total)
|
22
|
-
|
23
|
-
payment.payment_method = Spree::Order.pag_seguro_payment_method
|
24
|
-
@order.payments << payment
|
25
|
-
payment.started_processing
|
26
|
-
|
27
18
|
@order.payment.complete
|
28
|
-
|
29
|
-
until @order.state == "complete"
|
30
|
-
if @order.next!
|
31
|
-
@order.update!
|
32
|
-
state_callback(:after)
|
33
|
-
end
|
34
|
-
end
|
35
19
|
end
|
36
20
|
end
|
37
21
|
|
@@ -41,31 +25,5 @@ module Spree
|
|
41
25
|
def callback
|
42
26
|
end
|
43
27
|
|
44
|
-
protected
|
45
|
-
# those methods are copy-pasted from CheckoutController
|
46
|
-
# we cannot inherit from that class unless we want to skip_before_filter
|
47
|
-
# half of calls in SpreeBase module
|
48
|
-
def state_callback(before_or_after = :before)
|
49
|
-
method_name = :"#{before_or_after}_#{@order.state}"
|
50
|
-
send(method_name) if respond_to?(method_name, true)
|
51
|
-
end
|
52
|
-
|
53
|
-
def before_address
|
54
|
-
@order.bill_address ||= Address.new
|
55
|
-
@order.ship_address ||= Address.new
|
56
|
-
end
|
57
|
-
|
58
|
-
def before_delivery
|
59
|
-
@order.shipping_method ||= (@order.rate_hash.first && @order.rate_hash.first[:shipping_method])
|
60
|
-
end
|
61
|
-
|
62
|
-
def before_payment
|
63
|
-
current_order.payments.destroy_all if request.put?
|
64
|
-
end
|
65
|
-
|
66
|
-
#This isn't working here in payment_nofitications_controller since IPN will run on a different session
|
67
|
-
def after_complete
|
68
|
-
session[:order_id] = nil
|
69
|
-
end
|
70
28
|
end
|
71
29
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Spree
|
2
|
+
class PagSeguroPayment < ActiveRecord::Base
|
3
|
+
attr_accessor :order_id
|
4
|
+
has_one :payment, :as => :source
|
5
|
+
|
6
|
+
def process!(payment)
|
7
|
+
order = payment.order
|
8
|
+
|
9
|
+
redirect_url = Rails.env.development? ? nil : "#{root_url}pag_seguro/callback"
|
10
|
+
|
11
|
+
pag_seguro_payment = ::PagSeguro::Payment.new(
|
12
|
+
Order.pag_seguro_payment_method.preferred_email,
|
13
|
+
Order.pag_seguro_payment_method.preferred_token,
|
14
|
+
redirect_url: redirect_url,
|
15
|
+
id: order.id)
|
16
|
+
|
17
|
+
pag_seguro_payment.items = order.line_items.map do |item|
|
18
|
+
::PagSeguro::Item.new(
|
19
|
+
id: item.id,
|
20
|
+
description: item.product.name,
|
21
|
+
amount: format("%.2f", item.price.round(2)),
|
22
|
+
quantity: item.quantity,
|
23
|
+
weight: ( item.product.weight * 1000 ).to_i
|
24
|
+
)
|
25
|
+
end
|
26
|
+
|
27
|
+
pag_seguro_payment.sender = ::PagSeguro::Sender.new(name: order.name, email: order.email, phone_number: order.ship_address.phone)
|
28
|
+
pag_seguro_payment.shipping = ::PagSeguro::Shipping.new(type: ::PagSeguro::Shipping::SEDEX, state: order.ship_address.state.abbr, city: order.ship_address.city, postal_code: order.ship_address.zipcode, street: order.ship_address.address1, complement: order.ship_address.address2)
|
29
|
+
self.code = pag_seguro_payment.code
|
30
|
+
self.date = pag_seguro_payment.date
|
31
|
+
self.save
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -3,6 +3,10 @@ module Spree
|
|
3
3
|
preference :email, :string
|
4
4
|
preference :token, :string
|
5
5
|
|
6
|
+
def payment_source_class
|
7
|
+
PagSeguroPayment
|
8
|
+
end
|
9
|
+
|
6
10
|
def actions
|
7
11
|
%w{capture void}
|
8
12
|
end
|
@@ -28,9 +32,5 @@ module Spree
|
|
28
32
|
payment.void
|
29
33
|
true
|
30
34
|
end
|
31
|
-
|
32
|
-
def source_required?
|
33
|
-
false
|
34
|
-
end
|
35
35
|
end
|
36
36
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% if @order.payment_method.instance_of? Spree::PaymentMethod::PagSeguroMethod %>
|
2
|
+
<% if @order.payment.completed? %>
|
3
|
+
Seu pagamento foi aprovado pelo PagSeguro através da transação de código: <%= @order.payment_notifications.last.transaction_id if @order.payment_notifications.present? %>
|
4
|
+
<% else %>
|
5
|
+
Clique na imagem abaixo para realizar o pagamento através do Pag Seguro.
|
6
|
+
<%= link_to image_tag("pag_seguro_checkout.gif"), PagSeguro::Payment.checkout_payment_url(@order.payment.source.code) %>
|
7
|
+
<% end %>
|
8
|
+
<% end %>
|
@@ -9,10 +9,6 @@ module Spree
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
initializer "spree.pag_seguro.preferences", after: "spree.active_shipping.configuration" do |app|
|
13
|
-
Spree::PagSeguro::Config = Spree::PagSeguroConfiguration.new
|
14
|
-
end
|
15
|
-
|
16
12
|
initializer "spree.resgiter.pag_seguro_method", after: "spree.register.payment_methods" do |app|
|
17
13
|
app.config.spree.payment_methods << Spree::PaymentMethod::PagSeguroMethod
|
18
14
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_pag_seguro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.rc2
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spree_core
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152906320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: 1.0.0.rc1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152906320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: pag_seguro
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152905860 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: 0.1.
|
32
|
+
version: 0.1.9
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152905860
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: capybara
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152905400 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.0.1
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152905400
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: factory_girl
|
49
|
-
requirement: &
|
49
|
+
requirement: &2152905020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152905020
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: ffaker
|
60
|
-
requirement: &
|
60
|
+
requirement: &2152904560 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *2152904560
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-rails
|
71
|
-
requirement: &
|
71
|
+
requirement: &2152904060 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ~>
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '2.7'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *2152904060
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: sqlite3
|
82
|
-
requirement: &
|
82
|
+
requirement: &2152903640 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *2152903640
|
91
91
|
description: Spree extension for integration with PagSeguro payment. Based on spree_pp_website_standart
|
92
92
|
gem
|
93
93
|
email: tomekrs@o2.pl
|
@@ -100,28 +100,26 @@ files:
|
|
100
100
|
- lib/generators/spree_pag_seguro/install/install_generator.rb
|
101
101
|
- lib/spree_pag_seguro/engine.rb
|
102
102
|
- lib/spree_pag_seguro.rb
|
103
|
-
- lib/spree_pag_seguro_configuration.rb
|
104
103
|
- app/assets/images/pag_seguro_checkout.gif
|
105
104
|
- app/assets/javascripts/admin/spree_paypal_website_standard.js
|
106
105
|
- app/assets/javascripts/store/spree_paypal_website_standard.js
|
107
106
|
- app/assets/stylesheets/admin/spree_paypal_website_standard.css
|
108
107
|
- app/assets/stylesheets/store/spree_paypal_website_standard.css
|
109
|
-
- app/controllers/spree/base_controller_decorator.rb
|
110
|
-
- app/controllers/spree/checkout_controller_decorator.rb
|
111
108
|
- app/controllers/spree/pag_seguro_controller.rb
|
112
|
-
- app/controllers/spree/payment_notifications_controller.rb
|
113
109
|
- app/models/spree/order_decorator.rb
|
110
|
+
- app/models/spree/pag_seguro_payment.rb
|
114
111
|
- app/models/spree/payment_method/pag_seguro_method.rb
|
115
112
|
- app/models/spree/payment_notification.rb
|
113
|
+
- app/overrides/replace_payment_info.rb
|
116
114
|
- app/views/spree/admin/orders/_pag_seguro_txns.html.erb
|
117
|
-
- app/views/spree/checkout/
|
118
|
-
- app/views/spree/checkout/
|
115
|
+
- app/views/spree/checkout/payment/_order_details.html.erb
|
116
|
+
- app/views/spree/checkout/payment/_pagseguromethod.html.erb
|
119
117
|
- app/views/spree/pag_seguro/callback.html.haml
|
120
|
-
- app/views/spree/pag_seguro_payments/successful.html.erb
|
121
118
|
- config/locales/en.yml
|
122
119
|
- config/locales/pt-BR.yml
|
123
120
|
- config/routes.rb
|
124
121
|
- db/migrate/20120106043500_create_spree_payment_notifications.rb
|
122
|
+
- db/migrate/20120216223731_create_db:migrate:20120216223950_create_spree_pag_seguro_payments.rb
|
125
123
|
- spec/spec_helper.rb
|
126
124
|
homepage: http://github.com/heavenstudio/spree-pag_seguro
|
127
125
|
licenses: []
|
@@ -1,13 +0,0 @@
|
|
1
|
-
Spree::BaseController.class_eval do
|
2
|
-
before_filter :check_current_order
|
3
|
-
def check_current_order
|
4
|
-
if current_order or session[:order_id]
|
5
|
-
order = current_order
|
6
|
-
if (order.payment_state == "paid") or (order.payment_state == "credit_owed")
|
7
|
-
session[:order_id] = nil
|
8
|
-
order.line_items.destroy_all
|
9
|
-
flash[:notice] = t(:pag_seguro_payment_received)
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
Spree::CheckoutController.class_eval do
|
2
|
-
def edit
|
3
|
-
if ((@order.state == "payment") && @order.valid?)
|
4
|
-
puts "valid, processing"
|
5
|
-
if @order.payable_via_pag_seguro?
|
6
|
-
puts "payable via pag_seguro, adding payment"
|
7
|
-
payment = Spree::Payment.new
|
8
|
-
payment.amount = @order.total
|
9
|
-
payment.payment_method = Spree::Order.pag_seguro_payment_method
|
10
|
-
@order.payments << payment
|
11
|
-
|
12
|
-
redirect_url = Rails.env.development? ? nil : "#{root_url}pag_seguro/callback"
|
13
|
-
|
14
|
-
pag_seguro_payment = PagSeguro::Payment.new(
|
15
|
-
Spree::Order.pag_seguro_payment_method.preferred_email,
|
16
|
-
Spree::Order.pag_seguro_payment_method.preferred_token,
|
17
|
-
redirect_url: redirect_url,
|
18
|
-
id: @order.id)
|
19
|
-
|
20
|
-
pag_seguro_payment.items = @order.line_items.map do |item|
|
21
|
-
PagSeguro::Item.new(
|
22
|
-
id: item.id,
|
23
|
-
description: item.product.name,
|
24
|
-
amount: format("%.2f", item.price.round(2)),
|
25
|
-
quantity: item.quantity,
|
26
|
-
weight: ( item.product.weight * 1000 ).to_i
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
pag_seguro_payment.sender = PagSeguro::Sender.new(name: @order.name, email: @order.email, phone_number: @order.ship_address.phone)
|
31
|
-
pag_seguro_payment.shipping = PagSeguro::Shipping.new(type: PagSeguro::Shipping::SEDEX, state: @order.ship_address.state.abbr, city: @order.ship_address.city, postal_code: @order.ship_address.zipcode, street: @order.ship_address.address1, complement: @order.ship_address.address2)
|
32
|
-
|
33
|
-
@pag_seguro_url = pag_seguro_payment.checkout_payment_url
|
34
|
-
payment.started_processing
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
module Spree
|
2
|
-
class PaymentNotificationsController < BaseController
|
3
|
-
protect_from_forgery :except => [:create]
|
4
|
-
skip_before_filter :restriction_access
|
5
|
-
|
6
|
-
def create
|
7
|
-
@order = Spree::Order.find_by_number(params[:invoice])
|
8
|
-
Spree::PaymentNotification.create!(:params => params,
|
9
|
-
:order_id => @order.id,
|
10
|
-
:status => params[:payment_status],
|
11
|
-
:transaction_id => params[:txn_id])
|
12
|
-
|
13
|
-
logger.info "PagSeguro: processing payment notification for invoice #{params["invoice"]}, amount is #{params["mc_gross"]} #{params["mc_currency"]}"
|
14
|
-
# this logging stuff won't live here for long...
|
15
|
-
|
16
|
-
Order.transaction do
|
17
|
-
# main part of hacks
|
18
|
-
order = @order
|
19
|
-
|
20
|
-
#create payment for this order
|
21
|
-
payment = Spree::Payment.new
|
22
|
-
|
23
|
-
# 1. Assume that if payment notification comes, it's exactly for the amount
|
24
|
-
# sent to paypal (safe assumption -- cart can't be edited while on paypal)
|
25
|
-
# 2. Can't use Order#total, as it's intercepted by spree-multi-currency
|
26
|
-
# which might lead to lots of false "credit owed" payment states
|
27
|
-
# (when they should be "complete")
|
28
|
-
payment.amount = order.read_attribute(:total)
|
29
|
-
logger.info "PagSeguro: set payment.amount to #{payment.amount} based on order's total #{order.read_attribute(:total)}"
|
30
|
-
|
31
|
-
payment.payment_method = Spree::Order.pag_seguro_payment_method
|
32
|
-
order.payments << payment
|
33
|
-
payment.started_processing
|
34
|
-
|
35
|
-
order.payment.complete
|
36
|
-
logger.info("PagSeguro: order #{order.number} (#{order.id}) -- completed payment")
|
37
|
-
|
38
|
-
until @order.state == "complete"
|
39
|
-
if @order.next!
|
40
|
-
@order.update!
|
41
|
-
state_callback(:after)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
logger.info("PagSeguro: Order #{order.number} (#{order.id}) updated successfully")
|
46
|
-
end
|
47
|
-
|
48
|
-
render :nothing => true
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
# those methods are copy-pasted from CheckoutController
|
54
|
-
# we cannot inherit from that class unless we want to skip_before_filter
|
55
|
-
# half of calls in SpreeBase module
|
56
|
-
def state_callback(before_or_after = :before)
|
57
|
-
method_name = :"#{before_or_after}_#{@order.state}"
|
58
|
-
send(method_name) if respond_to?(method_name, true)
|
59
|
-
end
|
60
|
-
|
61
|
-
def before_address
|
62
|
-
@order.bill_address ||= Address.new
|
63
|
-
@order.ship_address ||= Address.new
|
64
|
-
end
|
65
|
-
|
66
|
-
def before_delivery
|
67
|
-
@order.shipping_method ||= (@order.rate_hash.first && @order.rate_hash.first[:shipping_method])
|
68
|
-
end
|
69
|
-
|
70
|
-
def before_payment
|
71
|
-
current_order.payments.destroy_all if request.put?
|
72
|
-
end
|
73
|
-
|
74
|
-
#This isn't working here in payment_nofitications_controller since IPN will run on a different session
|
75
|
-
def after_complete
|
76
|
-
session[:order_id] = nil
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
<% content_for :head do %>
|
2
|
-
<%= javascript_include_tag '/states' %>
|
3
|
-
<% end %>
|
4
|
-
<div id="checkout">
|
5
|
-
<h1><%= t("checkout")%></h1>
|
6
|
-
<%= checkout_progress %>
|
7
|
-
<br clear="left" />
|
8
|
-
<%= render "spree/shared/error_messages", :target => @order %>
|
9
|
-
<%= hook :checkout_summary_box do %>
|
10
|
-
<div id="checkout-summary">
|
11
|
-
<%= render 'summary', :order => @order %>
|
12
|
-
</div>
|
13
|
-
<% end %>
|
14
|
-
|
15
|
-
|
16
|
-
<% if(@order.state == "payment") %>
|
17
|
-
<%= render('spree/checkout/pag_seguro_checkout') if @order.payable_via_pag_seguro? %>
|
18
|
-
<% else %>
|
19
|
-
<%= form_for @order, :url => update_checkout_path(@order.state), :html => { :id => "checkout_form_#{@order.state}" } do |form| %>
|
20
|
-
<%= render @order.state, :form => form %>
|
21
|
-
<input id="post-final" type="submit" style="display:none"/>
|
22
|
-
<% end %>
|
23
|
-
<% end %>
|
24
|
-
</div>
|
25
|
-
|
26
|
-
<div id="payment_step">
|
27
|
-
|
28
|
-
</div>
|
@@ -1 +0,0 @@
|
|
1
|
-
SUCCESS!
|