spree_pagseguro_simple 0.9 → 1.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a073434accf526aa668ce63befde820882e73e3f
4
- data.tar.gz: 6a40831005efa4f254106617d7ee840854ef9b03
3
+ metadata.gz: 2d9ecfb3fd9ce2727574bb6510b5f718b9f97c21
4
+ data.tar.gz: 565d3c092c7eea798344b7d83791e794c34bafd6
5
5
  SHA512:
6
- metadata.gz: 8628353029aed2f0bb318203121e792779611c66bb4c9de879be29e4ef2fa286d8bf12350327c7097cc420ede8c391742348f73d44402173f2f16e06c420257f
7
- data.tar.gz: bd895f517cf71d1e1d3463587bedcda67985a3ea23ce6fb30ae47095ed47595b98f82cf4c72e50220a014a37c2c9ae2b843f798828ecab615bbb1d39aa851ea2
6
+ metadata.gz: de149c0ac7f33d425580c06a787e9a55d7f27a0d27acc1f163ac92d54a83328750a9434cdb5e98da52e0bab083b21bcd6b33359163130f466f2ba45ac821add0
7
+ data.tar.gz: 833f4f9734e6fd329b7cfa98d1a4a10c4861a1c8c6906b745bd771e9863ded5f4d5590623b4d2c8760bba2c6af2712ca99ddf3e42a3e0819129cd2ee98a9a5c0
data/.gitignore CHANGED
@@ -14,3 +14,4 @@ pkg
14
14
  spec/dummy
15
15
  .bundle
16
16
  bin
17
+ *.gem
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
- # Spree PagSeguroSimple (Brazilian Payment Method)
1
+ # Spree PagSeguroSimple
2
2
 
3
3
  [![Code Climate](https://codeclimate.com/github/locomotivapro/spree_pagseguro_simple/badges/gpa.svg)](https://codeclimate.com/github/locomotivapro/spree_pagseguro_simple)
4
+ [![Gem Version](https://badge.fury.io/rb/spree_pagseguro_simple.svg)](http://badge.fury.io/rb/spree_pagseguro_simple)
4
5
 
5
6
  Add support for Pagseguro checkout as a payment method.
6
7
  __Only tested on Spree 3.0__
@@ -23,15 +24,23 @@ This gem approach takes in consideration that a incomplete order with an approve
23
24
 
24
25
  2. Click `Create`, and enter your Store's Pagseguro Email and Token in the fields provided.
25
26
 
26
- 3. `Save` and enjoy!
27
+ 3. By default sandbox env is activated. To allow production env you
28
+ shoud define ENV['PAGSEGURO_ENV'].
29
+
30
+ 4. `Save` and enjoy!
27
31
 
28
32
  4. Is important to go to general settings in spree and configure the store url for redirects and notifications
29
33
 
34
+ ## To-Do
35
+
36
+ - Need to add test coverage to gem
37
+ - Configure enviroment to use payment method preference
38
+ - Work in notification controller action
39
+ - Improve view in order#show
40
+
30
41
  Testing
31
42
  -------
32
43
 
33
- *Need to write lots of tests*
34
-
35
44
  To make real tests register in PagSeguro sandbox and configure the payment method as test.
36
45
 
37
46
  Be sure to add the rspec-rails gem to your Gemfile and then create a dummy test app for the specs to run against.
@@ -44,4 +53,4 @@ Disclaimer
44
53
 
45
54
  This gem is inspired by [João Netto gem](https://github.com/jnettome/spree_pagseguro) but updated to spree 3 and using a new approach to checkout flow.
46
55
 
47
- Copyright (c) 2013-2015 [!Locomotiva.pro](http://locomotiva.pro), released under the New BSD License
56
+ Copyright (c) 2013-2015 [Locomotiva.pro](http://locomotiva.pro), released under the New BSD License
@@ -5,29 +5,38 @@ module Spree
5
5
  def callback
6
6
  @order = Spree::Order.find_by_number(params[:order])
7
7
 
8
- pagseguro_transaction = Spree::PagseguroTransaction.find_by_order_id(@order.number)
8
+ pagseguro_transaction = Spree::PagSeguroTransaction.find_by_order_id(@order.number)
9
9
  pagseguro_transaction.update_attribute :state, 'waiting'
10
10
 
11
+ flash[:notice] = Spree.t(:pagseguro_transaction_success)
11
12
  redirect_to spree.order_path(@order)
12
13
  end
13
14
 
14
15
  def notify
15
- logger.info "[PAGSEGURO] Gateway is calling /notify"
16
- logger.info params
16
+ return unless request.post?
17
+ payment_method = Spree::PaymentMethod.where(type: 'Spree::PaymentMethod::Pagseguro').last
17
18
 
18
- #notification = Spree::PagseguroTransaction.update_last_transaction(params)
19
- #payment_method = Spree::PaymentMethod.where(type: 'Spree::Gateway::PagSeguro').first
19
+ email = payment_method.preferred_email
20
+ token = payment_method.preferred_token
21
+ _notification_code = params[:notificationCode]
20
22
 
23
+ notification = PagSeguro::Notification.new(email, token, _notification_code)
21
24
  @order = Spree::Order.find_by_number(notification.reference)
22
- payment = @order.payments.where(:state => "checkout",
23
- :payment_method_id => payment_method.id).last
24
25
 
25
- if notification.approved?
26
- logger.info "[PAGSEGURO] Order #{@order.number} approved"
27
- payment.complete!
26
+ payment = @order.payments.where(state: "checkout",
27
+ payment_method_id: payment_method.id,
28
+ amount: notification.gross_amount).last
29
+
30
+ if payment
31
+ if notification.approved?
32
+ payment.complete!
33
+ end
34
+
35
+ if notification.cancelled? || notification.returned?
36
+ payment.void!
37
+ end
28
38
  else
29
- logger.info "[PAGSEGURO] Order #{@order.number} failed"
30
- payment.failure!
39
+ raise StandardError
31
40
  end
32
41
 
33
42
  render nothing: true, head: :ok
@@ -2,5 +2,8 @@ module Spree
2
2
  class PagSeguroTransaction < ActiveRecord::Base
3
3
  has_many :payments, :as => :source
4
4
 
5
+ def self.update_last_transaction(params)
6
+ end
7
+
5
8
  end
6
9
  end
@@ -1,7 +1,11 @@
1
1
  <% ps_transaction = SpreePagseguroSimple::Gateway.new(payment) %>
2
2
  <% if ps_transaction.is_not_completed? %>
3
- <p>Clique no botão abaixo e realize o pagamento</p>
4
- <%= link_to image_tag('btn-pagseguro.gif'), ps_transaction.payment_url, target: :_blank %>
3
+ <p><strong>Clique no botão abaixo e realize o pagamento</strong></p>
4
+ <%= link_to image_tag('btn-pagseguro.gif'), ps_transaction.payment_url %>
5
5
  <% else %>
6
- <p>Seu pagamento foi recebido</p>
6
+ <% if payment.completed? %>
7
+ <p class='label label-success'>Pagamento aprovado</p>
8
+ <% else %>
9
+ <p class="text-info">Seu pagamento foi recebido. Assim que o PagSeguro aprovar a transação seu pedido entrará em produção.</p>
10
+ <% end %>
7
11
  <% end %>
@@ -0,0 +1,3 @@
1
+ pt-BR:
2
+ spree:
3
+ pagseguro_transaction_success: Transação registrada com sucesso no PagSeguro. Você receberá em breve atualizações em seu pedido.
@@ -32,7 +32,7 @@ module SpreePagseguroSimple
32
32
  end
33
33
 
34
34
  def set_environment
35
- @env = Rails.env.production? ? :production : :sandbox
35
+ @env = ENV['PAGSEGURO_ENV'] ? :production : :sandbox
36
36
  PagSeguro::Url.environment = @env
37
37
  end
38
38
 
@@ -1,3 +1,3 @@
1
1
  module SpreePagseguroSimple
2
- VERSION = '0.9'
2
+ VERSION = '1.0.alpha'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_pagseguro_simple
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.9'
4
+ version: 1.0.alpha
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Antoniazzi Tierno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-06 00:00:00.000000000 Z
11
+ date: 2016-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: spree_core
@@ -185,9 +185,7 @@ extensions: []
185
185
  extra_rdoc_files: []
186
186
  files:
187
187
  - ".gitignore"
188
- - ".metrics"
189
188
  - ".rspec"
190
- - ".travis.yml"
191
189
  - Gemfile
192
190
  - LICENSE
193
191
  - README.md
@@ -203,6 +201,7 @@ files:
203
201
  - app/views/spree/shared/_pag_seguro_info.html.erb
204
202
  - app/views/spree/shared/_payments_with_pagseguro.html.erb
205
203
  - config/locales/en.yml
204
+ - config/locales/pt-BR.yml
206
205
  - config/routes.rb
207
206
  - db/migrate/20150506164744_create_spree_pag_seguro_transactions.rb
208
207
  - lib/generators/spree_pagseguro_simple/install/install_generator.rb
@@ -225,9 +224,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
224
  version: 2.0.0
226
225
  required_rubygems_version: !ruby/object:Gem::Requirement
227
226
  requirements:
228
- - - ">="
227
+ - - ">"
229
228
  - !ruby/object:Gem::Version
230
- version: '0'
229
+ version: 1.3.1
231
230
  requirements:
232
231
  - none
233
232
  rubyforge_project:
data/.metrics DELETED
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env ruby
2
- MetricFu::Configuration.run do |config|
3
- config.configure_metrics.each do |metric|
4
- metric.enabled = false
5
- end
6
-
7
- config.configure_metric(:rcov) do |rcov|
8
- rcov.enabled = true
9
- end
10
-
11
- config.configure_metric(:cane) do |cane|
12
- cane.enabled = true
13
- cane.abc_max = 15
14
- cane.line_length = 90
15
- cane.no_doc = 'y'
16
- cane.no_readme = 'y'
17
- end
18
-
19
- config.configure_metric(:flay) do |flay|
20
- flay.enabled = true
21
- end
22
-
23
- config.configure_metric(:flog) do |flog|
24
- flog.enabled = true
25
- end
26
-
27
- config.configure_formatter(:html)
28
- end
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- bundler_args: --path vendor/bundle
3
- script: bundle exec rspec
4
- cache: bundler
5
-
6
- rvm:
7
- - 2.0.0
8
- - 1.9.3
9
- - jruby-19mode # JRuby in 1.9 mode