-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Including the function of Automatic return
- Loading branch information
Marcio Garcia
committed
Dec 12, 2008
1 parent
6b057be
commit dd40925
Showing
20 changed files
with
667 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,92 @@ | ||
require 'fileutils' | ||
|
||
puts "--------------------------------------------------------------------------------" | ||
puts " Welcome to brEshop plugin" | ||
puts "--------------------------------------------------------------------------------" | ||
|
||
puts "Copying 'breshop.yml'..." | ||
breshop_yml_file = File.dirname(__FILE__) + '/../../../config/breshop.yml' | ||
FileUtils.cp File.dirname(__FILE__) + '/install/breshop.yml', breshop_yml_file unless File.exist?(breshop_yml_file) | ||
FileUtils.cp File.dirname(__FILE__) + '/install/breshop.yml', breshop_yml_file unless File.exist?(breshop_yml_file) | ||
|
||
|
||
puts "Copying 'autoret_controller'...." | ||
autoret_controller_file = File.dirname(__FILE__) + '/../../../app/controllers/autoret_controller.rb' | ||
FileUtils.cp File.dirname(__FILE__) + '/install/pagseguro/controllers/autoret_controller.rb', autoret_controller_file unless File.exist?(autoret_controller_file) | ||
|
||
|
||
puts "Copying views..." | ||
rhtml_files = File.dirname(__FILE__) + '/../../../app/views/' | ||
FileUtils.cp_r File.dirname(__FILE__) + '/install/pagseguro/views/autoret/', rhtml_files unless File.directory?(File.dirname(__FILE__) + '/../../../app/views/autoret/') | ||
|
||
|
||
puts "Copying models...." | ||
puts " ... psproduct.rb ..." | ||
model_files = File.dirname(__FILE__) + '/../../../app/models/psproduct.rb' | ||
FileUtils.cp File.dirname(__FILE__) + '/install/pagseguro/models/psproduct.rb', model_files unless File.exist?(model_files) | ||
|
||
puts " ... pstransaction.rb ..." | ||
model_files = File.dirname(__FILE__) + '/../../../app/models/pstransaction.rb' | ||
FileUtils.cp File.dirname(__FILE__) + '/install/pagseguro/models/pstransaction.rb', model_files unless File.exist?(model_files) | ||
|
||
|
||
puts "Copying migrations...." | ||
puts " ... create.pstransactions ..." | ||
FileUtils.mkdir File.dirname(__FILE__) + '/../../../db/migrate/' | ||
|
||
migrate_files = File.dirname(__FILE__) + '/../../../db/migrate/1_create_pstransactions.rb' | ||
FileUtils.cp_r File.dirname(__FILE__) + '/install/pagseguro/db/migrate/1_create_pstransactions.rb', migrate_files unless File.exist?(migrate_files) | ||
|
||
puts " ... create.psproducts ..." | ||
migrate_files = File.dirname(__FILE__) + '/../../../db/migrate/2_create_psproducts.rb' | ||
FileUtils.cp_r File.dirname(__FILE__) + '/install/pagseguro/db/migrate/2_create_psproducts.rb', migrate_files unless File.exist?(migrate_files) | ||
|
||
|
||
puts "Copying fixtures...." | ||
puts " ... psproduct.yml ..." | ||
fixtures_files = File.dirname(__FILE__) + '/../../../test/fixtures/psproducts.yml' | ||
FileUtils.cp File.dirname(__FILE__) + '/install/pagseguro/test/fixtures/psproducts.yml', fixtures_files unless File.exist?(fixtures_files) | ||
|
||
puts " ... pstransaction.yml ..." | ||
fixtures_files = File.dirname(__FILE__) + '/../../../test/fixtures/pstransactions.yml' | ||
FileUtils.cp File.dirname(__FILE__) + '/install/pagseguro/test/fixtures/pstransactions.yml', fixtures_files unless File.exist?(fixtures_files) | ||
|
||
|
||
puts "Copying functional test...." | ||
test_file = File.dirname(__FILE__) + '/../../../test/functional/autoret_controller_test.rb' | ||
FileUtils.cp File.dirname(__FILE__) + '/install/pagseguro/test/functional/autoret_controller_test.rb', test_file unless File.exist?(test_file) | ||
|
||
puts "\n\n\n\n" | ||
puts "brEshop is almost done to be used, if you want to use it to just to integrate " | ||
puts "with PagSeguro shopping cart or use it to calculate the freight it's done!" | ||
puts "" | ||
puts "Open the README.markdown file and take a look how to do that." | ||
puts "" | ||
puts "If you want to use the PagSeguro func: \"Automatic Return\" you are almost there, " | ||
puts "just more one step:" | ||
puts "" | ||
puts "1 - Define a development and test database" | ||
puts "2 - Run on command line: rake db:migrate" | ||
puts "" | ||
puts "These tasks will create two tables responsible to store posts comming from " | ||
puts "PagSeguro: pstransactions and psproducts." | ||
puts "" | ||
puts "With your application running (./script/server), check the page: " | ||
puts "http://localhost:3000/autoret/show it will shows you all records sent from PS." | ||
puts "You can even simulate this communication pointing out your browser to:" | ||
puts "" | ||
puts "http://localhost:3000/autoret?VendedorEmail=emaildovendedor&TransacaoID=123&Referencia=referencia&TipoFrete=FR&ValorFrete=10,00&Anotacao=anotacaooo&DataTransacao=dd/mm/yyyy hh:mm:ss&TipoPagamento=Pagamento via cartão de crédito&StatusTransacao=Em Análise&CliNome=NomeDoCabra&CliEmail=email@uol.com.br&CliEndereco=Endereco do cliente&CliNumero=1741&CliComplemento=AP22&CliBairro=Moema&CliCidade=Sao Paulo&CliEstado=SP&CliCEP=14055490&CliTelefone=00 00000000&NumItens=1&ProdID_1=1&ProdDescricao_1=Nome do Produto 01&ProdValor_1=100,00&ProdQuantidade_1=2&ProdFrete_1=10&ProdExtras_1=0" | ||
puts "" | ||
puts "More info about Automatic Return service can be found in PagSeguro website, in " | ||
puts "functional test suite, and even talking with brEshop developers." | ||
puts "" | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
class AutoretController < ApplicationController | ||
|
||
# ok 1 - token no arquivo de configuracao | ||
# 2 - install para copiar os arquivos apra dentro da aplicacao | ||
# ok 3 - testes | ||
# ok 4 - tela para mostrar os registros e excluir | ||
# ok 5 - post de confirmacao da mensagem | ||
# 6 - mostrar mensagem de texto apos a instalacao para executar o rake db:migrate | ||
|
||
def index | ||
@config = YAML.load_file(File.dirname(__FILE__) + "/../../config/breshop.yml")["pagseguro"] | ||
|
||
@params = Hash.new | ||
@params[:token] = @config['token'] | ||
@params.merge!(request.parameters) | ||
|
||
Pstransaction.transaction do | ||
|
||
tx = Pstransaction.new | ||
tx.transaction_id = request.parameters["TransacaoID"] | ||
tx.seller_email = request.parameters["VendedorEmail"] | ||
tx.ref = request.parameters["Referencia"] | ||
tx.freight_type = request.parameters["TipoFrete"] | ||
tx.freight_value = request.parameters["ValorFrete"] | ||
tx.annotation = request.parameters["Anotacao"] | ||
tx.payment_type = request.parameters["TipoPagamento"] | ||
tx.status = request.parameters["StatusTransacao"] | ||
tx.cli_name = request.parameters["CliNome"] | ||
tx.cli_email = request.parameters["CliEmail"] | ||
tx.cli_address = request.parameters["CliEndereco"] | ||
tx.cli_number = request.parameters["CliNumero"] | ||
tx.cli_complement = request.parameters["CliComplemento"] | ||
tx.cli_district = request.parameters["CliBairro"] | ||
tx.cli_city = request.parameters["CliCidade"] | ||
tx.cli_state = request.parameters["CliEstado"] | ||
tx.cli_zip = request.parameters["CliCEP"] | ||
tx.cli_phone = request.parameters["CliTelefone"] | ||
tx.count_itens = request.parameters["NumItens"] | ||
|
||
1.upto(request.parameters["NumItens"].to_i) do |c| | ||
product = Psproduct.new | ||
product.pstransaction = tx | ||
product.product_id = request.parameters["ProdID_#{c}"] | ||
product.description = request.parameters["ProdDescricao_#{c}"] | ||
product.price = request.parameters["ProdValor_#{c}"] | ||
product.quantity = request.parameters["ProdQuantidade_#{c}"] | ||
product.freight_value = request.parameters["ProdFrete_#{c}"] | ||
product.extra = request.parameters["ProdExtras_#{c}"] | ||
product.save | ||
end | ||
|
||
tx.save | ||
end | ||
|
||
end | ||
|
||
def show | ||
@txs = Pstransaction.find_by_id(params[:id]) unless params[:id].blank? | ||
@txs = Pstransaction.find(:all) if params[:id].blank? | ||
end | ||
|
||
def clean | ||
Pstransaction.delete_all | ||
Psproduct.delete_all | ||
redirect_to :action => 'show' | ||
end | ||
|
||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class CreatePstransactions < ActiveRecord::Migration | ||
def self.up | ||
create_table :pstransactions do |t| | ||
t.string :transaction_id | ||
t.string :seller_email | ||
t.string :ref | ||
t.string :freight_type | ||
t.string :freight_value | ||
t.string :extras | ||
t.string :annotation | ||
t.string :payment_type | ||
t.string :status | ||
t.string :cli_name | ||
t.string :cli_address | ||
t.string :cli_email | ||
t.string :cli_number | ||
t.string :cli_complement | ||
t.string :cli_district | ||
t.string :cli_city | ||
t.string :cli_state | ||
t.string :cli_zip | ||
t.string :cli_phone | ||
t.string :count_itens | ||
t.string :checked | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :pstransactions | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class CreatePsproducts < ActiveRecord::Migration | ||
def self.up | ||
create_table :psproducts do |t| | ||
t.string :pstransaction_id | ||
t.string :product_id | ||
t.string :description | ||
t.string :price | ||
t.string :quantity | ||
t.string :freight_value | ||
t.string :extra | ||
|
||
t.timestamps | ||
end | ||
end | ||
|
||
def self.down | ||
drop_table :psproducts | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# == Schema Information | ||
# Schema version: 20081130150919 | ||
# | ||
# Table name: psproducts | ||
# | ||
# id :integer not null, primary key | ||
# pstransaction_id :string(255) | ||
# product_id :string(255) | ||
# description :string(255) | ||
# price :string(255) | ||
# quantity :string(255) | ||
# freight_value :string(255) | ||
# extra :string(255) | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# | ||
|
||
class Psproduct < ActiveRecord::Base | ||
belongs_to :pstransaction | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# == Schema Information | ||
# Schema version: 20081130150919 | ||
# | ||
# Table name: pstransactions | ||
# | ||
# id :integer not null, primary key | ||
# transaction_id :string(255) | ||
# seller_email :string(255) | ||
# ref :string(255) | ||
# freight_type :string(255) | ||
# freight_value :string(255) | ||
# extras :string(255) | ||
# annotation :string(255) | ||
# payment_type :string(255) | ||
# status :string(255) | ||
# cli_name :string(255) | ||
# cli_address :string(255) | ||
# cli_email :string(255) | ||
# cli_number :string(255) | ||
# cli_complement :string(255) | ||
# cli_district :string(255) | ||
# cli_city :string(255) | ||
# cli_state :string(255) | ||
# cli_zip :string(255) | ||
# cli_phone :string(255) | ||
# count_itens :string(255) | ||
# checked :string(255) | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# | ||
|
||
class Pstransaction < ActiveRecord::Base | ||
has_many :psproducts | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# == Schema Information | ||
# Schema version: 20081130150919 | ||
# | ||
# Table name: psproducts | ||
# | ||
# id :integer not null, primary key | ||
# pstransaction_id :string(255) | ||
# product_id :string(255) | ||
# description :string(255) | ||
# price :string(255) | ||
# quantity :string(255) | ||
# freight_value :string(255) | ||
# extra :string(255) | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# | ||
|
||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
pstransaction_id: "1" | ||
product_id: "1" | ||
description: "1" | ||
price: "1" | ||
quantity: "1" | ||
freight_value: "1" | ||
extra: "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# == Schema Information | ||
# Schema version: 20081130150919 | ||
# | ||
# Table name: pstransactions | ||
# | ||
# id :integer not null, primary key | ||
# transaction_id :string(255) | ||
# seller_email :string(255) | ||
# ref :string(255) | ||
# freight_type :string(255) | ||
# freight_value :string(255) | ||
# extras :string(255) | ||
# annotation :string(255) | ||
# payment_type :string(255) | ||
# status :string(255) | ||
# cli_name :string(255) | ||
# cli_address :string(255) | ||
# cli_email :string(255) | ||
# cli_number :string(255) | ||
# cli_complement :string(255) | ||
# cli_district :string(255) | ||
# cli_city :string(255) | ||
# cli_state :string(255) | ||
# cli_zip :string(255) | ||
# cli_phone :string(255) | ||
# count_itens :string(255) | ||
# checked :string(255) | ||
# created_at :datetime | ||
# updated_at :datetime | ||
# | ||
|
||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
||
one: | ||
transaction_id: "1" | ||
seller_email: "1" | ||
ref: "1" | ||
freight_type: "1" | ||
freight_value: "1" | ||
extras: "1" | ||
annotation: "1" | ||
payment_type: "1" | ||
status: "1" | ||
cli_name: "1" | ||
cli_address: "1" | ||
cli_email: "1" | ||
cli_number: "1" | ||
cli_complement: "1" | ||
cli_district: "1" | ||
cli_city: "1" | ||
cli_state: "1" | ||
cli_zip: "1" | ||
cli_phone: "1" | ||
count_itens: "1" | ||
checked: "1" | ||
|
||
|
Binary file not shown.
Oops, something went wrong.