spree_pagseguro 2.1.3
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 +7 -0
- data/.gitignore +16 -0
- data/Gemfile +7 -0
- data/LICENSE +26 -0
- data/README.md +40 -0
- data/Rakefile +15 -0
- data/app/assets/javascripts/admin/spree_pagseguro.js +1 -0
- data/app/assets/javascripts/store/spree_pagseguro.js +1 -0
- data/app/assets/stylesheets/admin/spree_pagseguro.css +3 -0
- data/app/assets/stylesheets/store/spree_pagseguro.css +3 -0
- data/app/controllers/spree/checkout_controller_decorator.rb +21 -0
- data/app/controllers/spree/pagseguro_controller.rb +32 -0
- data/app/models/spree/billing_integration/pagseguro/checkout.rb +50 -0
- data/app/models/spree/pagseguro_transaction.rb +26 -0
- data/app/views/spree/admin/payments/source_forms/_checkout.html.erb +8 -0
- data/app/views/spree/admin/payments/source_views/_checkout.html.erb +37 -0
- data/app/views/spree/checkout/payment/_checkout.html.erb +17 -0
- data/config/locales/en.yml +5 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20140108174733_create_spree_pagseguro_transactions.rb +17 -0
- data/lib/active_merchant/billing/pagseguro.rb +49 -0
- data/lib/generators/spree_pagseguro/install/install_generator.rb +31 -0
- data/lib/spree_pagseguro.rb +2 -0
- data/lib/spree_pagseguro/engine.rb +28 -0
- data/lib/spree_pagseguro/factories.rb +6 -0
- data/spec/controllers/checkout_controller_spec.rb +13 -0
- data/spec/models/spree/billing_integration/pagseguro_spec.rb +19 -0
- data/spec/models/spree/pagseguro_transaction_spec.rb +5 -0
- data/spec/spec_helper.rb +82 -0
- data/spree_pagseguro.gemspec +32 -0
- metadata +244 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7397a6ed64a0039f7f23c4ea8b439e732dfce76a
|
4
|
+
data.tar.gz: ce81a9bb8c558736dfdb5b32ed402cbf0ca3f1f2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e69f8c20ef89d90d85e4e130b069f0a019467e8aa0ca94ae7436015f583556ed184e8464169378536b00fc63ed711c344350e1c2088635411ccde6cfde71d81
|
7
|
+
data.tar.gz: fdc2ff6fa08a629999b06e7796c082826f89a3ace5c5367460847960a03e4648181bd05f895e4d73e1127fa3ebd6e43c39cb6de6393f07115c44262b798084a1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Provides basic authentication functionality for testing parts of your engine
|
4
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable'
|
5
|
+
|
6
|
+
gemspec
|
7
|
+
gem 'pag_seguro', github: 'heavenstudio/pag_seguro', branch: 'master'
|
data/LICENSE
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2012-2014 João Netto
|
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,40 @@
|
|
1
|
+
# Spree Pagseguro (Brazilian Gateway)
|
2
|
+
|
3
|
+
Add support for Pagseguro checkout as a payment method.
|
4
|
+
__Only tested on Spree 2.1.3__
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
1. Add the following to your Gemfile
|
9
|
+
|
10
|
+
gem 'spree_pagseguro', github: 'jnettome/spree_pagseguro'
|
11
|
+
|
12
|
+
2. Run `bundle install`
|
13
|
+
|
14
|
+
3. To copy and apply migrations run: `rails g spree_pagseguro:install`
|
15
|
+
|
16
|
+
## Configuring
|
17
|
+
|
18
|
+
1. Add a new Payment Method, using: `BillingIntegration::Pagseguro::Checkout` as the `Provider`
|
19
|
+
|
20
|
+
2. Click `Create`, and enter your Store's Pagseguro Email and Token in the fields provided.
|
21
|
+
|
22
|
+
3. `Save` and enjoy!
|
23
|
+
|
24
|
+
## Running live
|
25
|
+
|
26
|
+
For spree_pagseguro works as expected, we need to use master branch of `heavenstudio/pag_seguro`. Because the last versions wasn't released yet, force on your main spree application Gemfile the following:
|
27
|
+
|
28
|
+
gem 'pag_seguro', github: 'heavenstudio/pag_seguro', branch: 'master'
|
29
|
+
|
30
|
+
|
31
|
+
Testing
|
32
|
+
-------
|
33
|
+
|
34
|
+
To make real tests (pagseguro doesn't provide sandbox), before running tests set environment variables `SPREE_PAGSEGURO_EMAIL` and `SPREE_PAGSEGURO_TOKEN` with valid credentials. To generate a token [see this](https://pagseguro.uol.com.br/integracao/token-de-seguranca.jhtml).
|
35
|
+
Be sure to add the rspec-rails gem to your Gemfile and then create a dummy test app for the specs to run against.
|
36
|
+
|
37
|
+
$ bundle exec rake test app
|
38
|
+
$ bundle exec rspec spec
|
39
|
+
|
40
|
+
Copyright (c) 2012-2014 João Netto, released under the New BSD License
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
require 'spree/testing_support/extension_rake'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new
|
8
|
+
|
9
|
+
task :default => [:spec]
|
10
|
+
|
11
|
+
desc 'Generates a dummy app for testing'
|
12
|
+
task :test_app do
|
13
|
+
ENV['LIB_NAME'] = 'spree_pagseguro'
|
14
|
+
Rake::Task['extension:test_app'].invoke
|
15
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require admin/spree_backend
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require store/spree_frontend
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Spree
|
2
|
+
CheckoutController.class_eval do
|
3
|
+
before_filter :confirm_pagseguro, :only => [:update]
|
4
|
+
|
5
|
+
private
|
6
|
+
# This method hacks order update event to generate a payment transaction
|
7
|
+
# using pagseguro and displays payment button
|
8
|
+
def confirm_pagseguro
|
9
|
+
return unless (params[:state] == "payment") && params[:order][:payments_attributes]
|
10
|
+
|
11
|
+
payment_method = PaymentMethod.find(params[:order][:payments_attributes].first[:payment_method_id])
|
12
|
+
if payment_method.kind_of?(BillingIntegration::Pagseguro::Checkout)
|
13
|
+
pagseguro_checkout_url = payment_method.redirect_url(@order)
|
14
|
+
|
15
|
+
@order.payments.create(:amount => @order.total, :payment_method_id => payment_method.id)
|
16
|
+
redirect_to pagseguro_checkout_url
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Spree
|
2
|
+
class PagseguroController < Spree::StoreController
|
3
|
+
skip_before_action :verify_authenticity_token, only: :notify
|
4
|
+
|
5
|
+
def callback
|
6
|
+
@order = Spree::Order.find_by_number(params[:order])
|
7
|
+
|
8
|
+
pagseguro_transaction = Spree::PagseguroTransaction.find_by_order_id(@order.id.to_s)
|
9
|
+
pagseguro_transaction.update_attribute :status, 'waiting'
|
10
|
+
|
11
|
+
redirect_to spree.order_path(@order)
|
12
|
+
end
|
13
|
+
|
14
|
+
def notify
|
15
|
+
notification = Spree::PagseguroTransaction.update_last_transaction(params)
|
16
|
+
payment_method = Spree::PaymentMethod.where(type: 'Spree::BillingIntegration::Pagseguro::Checkout').first
|
17
|
+
|
18
|
+
@order = Spree::Order.find(notification.id)
|
19
|
+
payment = @order.payments.where(:state => "pending",
|
20
|
+
:payment_method_id => payment_method.id).last
|
21
|
+
|
22
|
+
if notification.approved?
|
23
|
+
payment.complete!
|
24
|
+
else
|
25
|
+
payment.failure!
|
26
|
+
end
|
27
|
+
|
28
|
+
render nothing: true, head: :ok
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Spree
|
2
|
+
class BillingIntegration::Pagseguro::Checkout < BillingIntegration
|
3
|
+
preference :email, :string
|
4
|
+
preference :token, :string
|
5
|
+
|
6
|
+
def provider_class
|
7
|
+
ActiveMerchant::Billing::Pagseguro
|
8
|
+
end
|
9
|
+
|
10
|
+
def redirect_url(order, options = {})
|
11
|
+
options.merge! self.preferences
|
12
|
+
|
13
|
+
options[:customer_name] = [order.bill_address.firstname, order.bill_address.lastname].join(' ')
|
14
|
+
options[:customer_email] = order.email
|
15
|
+
options[:customer_ddd] = order.bill_address.phone.gsub(/\D/,'')[0..1] if order.bill_address.phone
|
16
|
+
options[:customer_phone] = order.bill_address.phone.gsub(/\D/,'') if order.bill_address.phone
|
17
|
+
|
18
|
+
options[:address] = [order.bill_address.address1, order.bill_address.address2].join(' ')
|
19
|
+
options[:city] = order.bill_address.city
|
20
|
+
options[:postal_code] = order.bill_address.zipcode
|
21
|
+
options[:state] = order.bill_address.state.nil? ? order.bill_address.state_name.to_s : order.bill_address.state.abbr
|
22
|
+
options[:country] = order.bill_address.country.name
|
23
|
+
|
24
|
+
options[:total] = order.total
|
25
|
+
options[:item_total] = order.item_total
|
26
|
+
options[:items] = order.line_items
|
27
|
+
|
28
|
+
options[:order_id] = order.number
|
29
|
+
|
30
|
+
options[:email] = (Rails.env.test?) ? ENV['SPREE_PAGSEGURO_EMAIL'] : preferences[:email]
|
31
|
+
options[:token] = (Rails.env.test?) ? ENV['SPREE_PAGSEGURO_TOKEN'] : preferences[:token]
|
32
|
+
|
33
|
+
pagseguro = self.provider.payment_url(options)
|
34
|
+
|
35
|
+
transaction = PagseguroTransaction.create!(
|
36
|
+
email: order.email, amount: order.total, order_id: order.id, code: pagseguro.code,
|
37
|
+
status: 'pending')
|
38
|
+
|
39
|
+
pagseguro.checkout_payment_url
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.notification(email, token, code)
|
43
|
+
ActiveMerchant::Billing::Pagseguro.notification(email, token, code)
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.payment_url(code)
|
47
|
+
ActiveMerchant::Billing::Pagseguro.checkout_payment_url(code)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Spree
|
2
|
+
class PagseguroTransaction < ActiveRecord::Base
|
3
|
+
has_many :payments, :as => :source
|
4
|
+
|
5
|
+
def actions
|
6
|
+
[]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.update_last_transaction(params)
|
10
|
+
method = Spree::PaymentMethod.where(type: 'Spree::BillingIntegration::Pagseguro::Checkout').first
|
11
|
+
|
12
|
+
notification_code = params[:notificationCode]
|
13
|
+
notification = Spree::BillingIntegration::Pagseguro::Checkout.notification(method.preferred_email, method.preferred_token, notification_code)
|
14
|
+
|
15
|
+
pagseguro_transaction = self.find_by_order_id(notification.id)
|
16
|
+
pagseguro_transaction.params = params
|
17
|
+
pagseguro_transaction.transaction_id = notification.transaction_id
|
18
|
+
pagseguro_transaction.customer_id = notification_code # Todo refactor column name
|
19
|
+
pagseguro_transaction.status = 'paid' if notification.approved?
|
20
|
+
pagseguro_transaction.save!
|
21
|
+
|
22
|
+
notification
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<% Spree::PagseguroTransaction.where(order_id: @order.id.to_s).each do |transaction| %>
|
2
|
+
|
3
|
+
<fieldset>
|
4
|
+
<legend><%= t('pagseguro') %></legend>
|
5
|
+
|
6
|
+
<table class="index">
|
7
|
+
<tr>
|
8
|
+
<th colspan="6"><%= t('pagseguro_transaction') %></th>
|
9
|
+
</tr>
|
10
|
+
<tr>
|
11
|
+
<td><label><%= t("email") %>:</label></td>
|
12
|
+
<td>
|
13
|
+
<%= transaction.email %>
|
14
|
+
</td>
|
15
|
+
</tr>
|
16
|
+
<tr>
|
17
|
+
<td><label><%= t("pagseguro_params") %>:</label></td>
|
18
|
+
<td>
|
19
|
+
<%= transaction.params %>
|
20
|
+
</td>
|
21
|
+
</tr>
|
22
|
+
<tr>
|
23
|
+
<td><label><%= t("pagseguro_transaction_id") %>:</label></td>
|
24
|
+
<td>
|
25
|
+
<%= transaction.transaction_id %>
|
26
|
+
</td>
|
27
|
+
</tr>
|
28
|
+
<tr>
|
29
|
+
<td><label><%= t("pagseguro_amount") %>:</label></td>
|
30
|
+
<td>
|
31
|
+
<%= transaction.amount %>
|
32
|
+
</td>
|
33
|
+
</tr>
|
34
|
+
</table>
|
35
|
+
</fieldset>
|
36
|
+
|
37
|
+
<% end %>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<p data-hook="pagseguro_checkout"></p>
|
2
|
+
|
3
|
+
<%
|
4
|
+
payment_method = Spree::PaymentMethod.where(type: 'Spree::BillingIntegration::Pagseguro::Checkout').first
|
5
|
+
if payment_method && payment = @order.payments.find_by(state: 'checkout', payment_method_id: payment_method.id)
|
6
|
+
if payment.completed?
|
7
|
+
%>
|
8
|
+
Seu pagamento foi aprovado pelo PagSeguro através da transação #<%= Spree::PagseguroTransaction.find_by_order_id(@order.id.to_s).transaction_id if Spree::PagseguroTransaction.find_by_order_id(@order.id.to_s) %>
|
9
|
+
<% else %>
|
10
|
+
<%= link_to "Pagar agora com PagSeguro", Spree::BillingIntegration::Pagseguro::Checkout.payment_url(Spree::PagseguroTransaction.find_by_order_id(@order.id.to_s).code) %>
|
11
|
+
<script>
|
12
|
+
$(function() {
|
13
|
+
$("#checkout_form_payment .form-buttons").hide();
|
14
|
+
});
|
15
|
+
</script>
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class CreateSpreePagseguroTransactions < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :spree_pagseguro_transactions do |t|
|
4
|
+
t.string :email
|
5
|
+
t.float :amount
|
6
|
+
t.string :transaction_id
|
7
|
+
t.string :customer_id
|
8
|
+
t.string :order_id
|
9
|
+
t.string :payment_id
|
10
|
+
t.text :params
|
11
|
+
t.string :code
|
12
|
+
t.string :status
|
13
|
+
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'pag_seguro'
|
2
|
+
module ActiveMerchant #:nodoc:
|
3
|
+
module Billing #:nodoc:
|
4
|
+
class Pagseguro < Gateway
|
5
|
+
|
6
|
+
def service_url
|
7
|
+
"https://pagseguro.uol.com.br"
|
8
|
+
end
|
9
|
+
|
10
|
+
def payment_url(options)
|
11
|
+
redirect_url = Rails.env.test? ? nil : "#{Spree::Config.site_url}/pagseguro/callback?order=#{options[:order_id]}"
|
12
|
+
notification_url = Rails.env.test? ? nil : "#{Spree::Config.site_url}/pagseguro/notify"
|
13
|
+
|
14
|
+
payment = ::PagSeguro::Payment.new(options[:email], options[:token],
|
15
|
+
extra_amount: (options[:total] - options[:item_total]).round(2), id: options[:order_id],
|
16
|
+
notification_url: notification_url, redirect_url: redirect_url)
|
17
|
+
|
18
|
+
payment.items = options[:items].map do |item|
|
19
|
+
product = ::PagSeguro::Item.new
|
20
|
+
product.id = item.id
|
21
|
+
product.description = item.variant.name
|
22
|
+
product.amount = item.price.round(2)
|
23
|
+
product.weight = (item.variant.weight * 1000).to_i if item.variant.weight.present?
|
24
|
+
product.quantity = item.quantity
|
25
|
+
product
|
26
|
+
end
|
27
|
+
|
28
|
+
payment.sender = ::PagSeguro::Sender.new(
|
29
|
+
name: options[:customer_name], email: options[:customer_email],
|
30
|
+
phone_ddd: options[:customer_ddd], phone_number: options[:customer_phone])
|
31
|
+
|
32
|
+
payment.shipping = ::PagSeguro::Shipping.new(
|
33
|
+
type: ::PagSeguro::Shipping::UNIDENTIFIED, state: (options[:state] ? options[:state] : nil),
|
34
|
+
city: options[:city], postal_code: options[:postal_code], street: options[:address])
|
35
|
+
|
36
|
+
payment
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.notification(email, token, notification_code)
|
40
|
+
::PagSeguro::Notification.new(email, token, notification_code)
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.checkout_payment_url(code)
|
44
|
+
::PagSeguro::Payment.checkout_payment_url(code)
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SpreePagseguro
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
class_option :auto_run_migrations, :type => :boolean, :default => false
|
6
|
+
|
7
|
+
def add_javascripts
|
8
|
+
append_file 'app/assets/javascripts/store/all.js', "//= require store/spree_pagseguro\n"
|
9
|
+
append_file 'app/assets/javascripts/admin/all.js', "//= require admin/spree_pagseguro\n"
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_stylesheets
|
13
|
+
inject_into_file 'app/assets/stylesheets/store/all.css', " *= require store/spree_pagseguro\n", :before => /\*\//, :verbose => true
|
14
|
+
inject_into_file 'app/assets/stylesheets/admin/all.css', " *= require admin/spree_pagseguro\n", :before => /\*\//, :verbose => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def add_migrations
|
18
|
+
run 'bundle exec rake railties:install:migrations FROM=spree_pagseguro'
|
19
|
+
end
|
20
|
+
|
21
|
+
def run_migrations
|
22
|
+
run_migrations = options[:auto_run_migrations] || ['', 'y', 'Y'].include?(ask 'Would you like to run the migrations now? [Y/n]')
|
23
|
+
if run_migrations
|
24
|
+
run 'bundle exec rake db:migrate'
|
25
|
+
else
|
26
|
+
puts 'Skipping rake db:migrate, don\'t forget to run it!'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SpreePagseguro
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
require 'spree/core'
|
4
|
+
isolate_namespace Spree
|
5
|
+
engine_name 'spree_pagseguro'
|
6
|
+
|
7
|
+
config.autoload_paths += %W(#{config.root}/lib)
|
8
|
+
|
9
|
+
# use rspec for tests
|
10
|
+
config.generators do |g|
|
11
|
+
g.test_framework :rspec
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.activate
|
15
|
+
Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
|
16
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
config.to_prepare &method(:activate).to_proc
|
21
|
+
|
22
|
+
initializer "spree_pagseguro.register.payment_methods", :after => 'spree.register.payment_methods' do |app|
|
23
|
+
app.config.spree.payment_methods += [
|
24
|
+
Spree::BillingIntegration::Pagseguro::Checkout
|
25
|
+
]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::CheckoutController do
|
4
|
+
let(:pagseguro_gateway) { BillingIntegration::Pagseguro::Checkout.new :id => 123 }
|
5
|
+
let(:order) { create(:order_with_line_items, :state => "payment") }
|
6
|
+
|
7
|
+
before do
|
8
|
+
controller.stub(:current_order => order, :check_authorization => true, :current_user => order.user)
|
9
|
+
order.stub(:checkout_allowed? => true, :completed? => false)
|
10
|
+
order.update!
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::BillingIntegration::Pagseguro::Checkout do
|
4
|
+
context "redirect_url" do
|
5
|
+
let(:payment_method) { create(:pagseguro_checkout) }
|
6
|
+
let(:order) { create(:order_with_line_items) }
|
7
|
+
|
8
|
+
# TODO Test with invalid credentials
|
9
|
+
# expect {
|
10
|
+
# payment_method.redirect_url(order)
|
11
|
+
# }.to raise_error(PagSeguro::Errors::Unauthorized, "Credentials provided (e-mail and token) failed to authenticate")
|
12
|
+
|
13
|
+
it "should return checkout url given valid credentials (see README)" do
|
14
|
+
expect { payment_method.redirect_url(order) }.not_to raise_error
|
15
|
+
expect(payment_method.redirect_url(order)).to start_with('https://pagseguro.uol.com.br/v2')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Run Coverage report
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec/dummy'
|
5
|
+
add_group 'Controllers', 'app/controllers'
|
6
|
+
add_group 'Helpers', 'app/helpers'
|
7
|
+
add_group 'Mailers', 'app/mailers'
|
8
|
+
add_group 'Models', 'app/models'
|
9
|
+
add_group 'Views', 'app/views'
|
10
|
+
add_group 'Libraries', 'lib'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Configure Rails Environment
|
14
|
+
ENV['RAILS_ENV'] = 'test'
|
15
|
+
|
16
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
17
|
+
|
18
|
+
require 'rspec/rails'
|
19
|
+
require 'database_cleaner'
|
20
|
+
require 'ffaker'
|
21
|
+
|
22
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
23
|
+
# in spec/support/ and its subdirectories.
|
24
|
+
Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
25
|
+
|
26
|
+
# Requires factories defined in spree_core
|
27
|
+
require 'spree/testing_support/factories'
|
28
|
+
require 'spree/testing_support/controller_requests'
|
29
|
+
require 'spree/testing_support/authorization_helpers'
|
30
|
+
require 'spree/testing_support/url_helpers'
|
31
|
+
|
32
|
+
# Requires factories defined in lib/spree_pagseguro/factories.rb
|
33
|
+
require 'spree_pagseguro/factories'
|
34
|
+
|
35
|
+
RSpec.configure do |config|
|
36
|
+
config.include FactoryGirl::Syntax::Methods
|
37
|
+
|
38
|
+
# == URL Helpers
|
39
|
+
#
|
40
|
+
# Allows access to Spree's routes in specs:
|
41
|
+
#
|
42
|
+
# visit spree.admin_path
|
43
|
+
# current_path.should eql(spree.products_path)
|
44
|
+
config.include Spree::TestingSupport::UrlHelpers
|
45
|
+
|
46
|
+
# == Mock Framework
|
47
|
+
#
|
48
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
49
|
+
#
|
50
|
+
# config.mock_with :mocha
|
51
|
+
# config.mock_with :flexmock
|
52
|
+
# config.mock_with :rr
|
53
|
+
config.mock_with :rspec
|
54
|
+
config.color = true
|
55
|
+
|
56
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
57
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
58
|
+
|
59
|
+
# Capybara javascript drivers require transactional fixtures set to false, and we use DatabaseCleaner
|
60
|
+
# to cleanup after each test instead. Without transactional fixtures set to false the records created
|
61
|
+
# to setup a test will be unavailable to the browser, which runs under a seperate server instance.
|
62
|
+
config.use_transactional_fixtures = false
|
63
|
+
|
64
|
+
# Ensure Suite is set to use transactions for speed.
|
65
|
+
config.before :suite do
|
66
|
+
DatabaseCleaner.strategy = :transaction
|
67
|
+
DatabaseCleaner.clean_with :truncation
|
68
|
+
end
|
69
|
+
|
70
|
+
# Before each spec check if it is a Javascript test and switch between using database transactions or not where necessary.
|
71
|
+
config.before :each do
|
72
|
+
DatabaseCleaner.strategy = example.metadata[:js] ? :truncation : :transaction
|
73
|
+
DatabaseCleaner.start
|
74
|
+
end
|
75
|
+
|
76
|
+
# After each spec clean the database.
|
77
|
+
config.after :each do
|
78
|
+
DatabaseCleaner.clean
|
79
|
+
end
|
80
|
+
|
81
|
+
config.fail_fast = ENV['FAIL_FAST'] || false
|
82
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
Gem::Specification.new do |s|
|
3
|
+
s.platform = Gem::Platform::RUBY
|
4
|
+
s.name = 'spree_pagseguro'
|
5
|
+
s.version = '2.1.3'
|
6
|
+
s.summary = 'Add support for Pagseguro checkout as a payment method.'
|
7
|
+
s.description = s.summary
|
8
|
+
s.required_ruby_version = '>= 2.0.0'
|
9
|
+
|
10
|
+
s.author = 'João Netto'
|
11
|
+
s.email = 'hi@joaonetto.me'
|
12
|
+
s.homepage = 'http://joaonetto.me'
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.require_path = 'lib'
|
17
|
+
s.requirements << 'none'
|
18
|
+
|
19
|
+
s.add_dependency 'spree_core', '~> 2.1.3'
|
20
|
+
s.add_dependency 'pag_seguro'
|
21
|
+
|
22
|
+
s.add_development_dependency 'capybara', '~> 2.1'
|
23
|
+
s.add_development_dependency 'coffee-rails'
|
24
|
+
s.add_development_dependency 'database_cleaner'
|
25
|
+
s.add_development_dependency 'factory_girl', '~> 4.2'
|
26
|
+
s.add_development_dependency 'ffaker'
|
27
|
+
s.add_development_dependency 'rspec-rails', '~> 2.13'
|
28
|
+
s.add_development_dependency 'sass-rails'
|
29
|
+
s.add_development_dependency 'selenium-webdriver'
|
30
|
+
s.add_development_dependency 'simplecov'
|
31
|
+
s.add_development_dependency 'sqlite3'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,244 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spree_pagseguro
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- João Netto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: spree_core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pag_seguro
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: capybara
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coffee-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: database_cleaner
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: factory_girl
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.2'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.2'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: ffaker
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.13'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.13'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: sass-rails
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: selenium-webdriver
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '>='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - '>='
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: sqlite3
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - '>='
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: Add support for Pagseguro checkout as a payment method.
|
182
|
+
email: hi@joaonetto.me
|
183
|
+
executables: []
|
184
|
+
extensions: []
|
185
|
+
extra_rdoc_files: []
|
186
|
+
files:
|
187
|
+
- .gitignore
|
188
|
+
- Gemfile
|
189
|
+
- LICENSE
|
190
|
+
- README.md
|
191
|
+
- Rakefile
|
192
|
+
- app/assets/javascripts/admin/spree_pagseguro.js
|
193
|
+
- app/assets/javascripts/store/spree_pagseguro.js
|
194
|
+
- app/assets/stylesheets/admin/spree_pagseguro.css
|
195
|
+
- app/assets/stylesheets/store/spree_pagseguro.css
|
196
|
+
- app/controllers/spree/checkout_controller_decorator.rb
|
197
|
+
- app/controllers/spree/pagseguro_controller.rb
|
198
|
+
- app/models/spree/billing_integration/pagseguro/checkout.rb
|
199
|
+
- app/models/spree/pagseguro_transaction.rb
|
200
|
+
- app/views/spree/admin/payments/source_forms/_checkout.html.erb
|
201
|
+
- app/views/spree/admin/payments/source_views/_checkout.html.erb
|
202
|
+
- app/views/spree/checkout/payment/_checkout.html.erb
|
203
|
+
- config/locales/en.yml
|
204
|
+
- config/routes.rb
|
205
|
+
- db/migrate/20140108174733_create_spree_pagseguro_transactions.rb
|
206
|
+
- lib/active_merchant/billing/pagseguro.rb
|
207
|
+
- lib/generators/spree_pagseguro/install/install_generator.rb
|
208
|
+
- lib/spree_pagseguro.rb
|
209
|
+
- lib/spree_pagseguro/engine.rb
|
210
|
+
- lib/spree_pagseguro/factories.rb
|
211
|
+
- spec/controllers/checkout_controller_spec.rb
|
212
|
+
- spec/models/spree/billing_integration/pagseguro_spec.rb
|
213
|
+
- spec/models/spree/pagseguro_transaction_spec.rb
|
214
|
+
- spec/spec_helper.rb
|
215
|
+
- spree_pagseguro.gemspec
|
216
|
+
homepage: http://joaonetto.me
|
217
|
+
licenses: []
|
218
|
+
metadata: {}
|
219
|
+
post_install_message:
|
220
|
+
rdoc_options: []
|
221
|
+
require_paths:
|
222
|
+
- lib
|
223
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - '>='
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: 2.0.0
|
228
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
230
|
+
- - '>='
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: '0'
|
233
|
+
requirements:
|
234
|
+
- none
|
235
|
+
rubyforge_project:
|
236
|
+
rubygems_version: 2.2.0
|
237
|
+
signing_key:
|
238
|
+
specification_version: 4
|
239
|
+
summary: Add support for Pagseguro checkout as a payment method.
|
240
|
+
test_files:
|
241
|
+
- spec/controllers/checkout_controller_spec.rb
|
242
|
+
- spec/models/spree/billing_integration/pagseguro_spec.rb
|
243
|
+
- spec/models/spree/pagseguro_transaction_spec.rb
|
244
|
+
- spec/spec_helper.rb
|