pagamento_digital 0.1.2beta
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/Gemfile +2 -0
- data/Gemfile.lock +94 -0
- data/README.markdown +267 -0
- data/Rakefile +5 -0
- data/app/views/pagamento_digital/_form.erb +68 -0
- data/lib/pagamento_digital.rb +16 -0
- data/lib/pagamento_digital/action_controller.rb +11 -0
- data/lib/pagamento_digital/base.rb +123 -0
- data/lib/pagamento_digital/cacert.pem +3987 -0
- data/lib/pagamento_digital/developer_controller.rb +29 -0
- data/lib/pagamento_digital/engine.rb +4 -0
- data/lib/pagamento_digital/faker.rb +172 -0
- data/lib/pagamento_digital/generator.rb +12 -0
- data/lib/pagamento_digital/helper.rb +6 -0
- data/lib/pagamento_digital/notification.rb +247 -0
- data/lib/pagamento_digital/order.rb +106 -0
- data/lib/pagamento_digital/railtie.rb +26 -0
- data/lib/pagamento_digital/rake.rb +134 -0
- data/lib/pagamento_digital/routes.rb +4 -0
- data/lib/pagamento_digital/utils.rb +13 -0
- data/lib/pagamento_digital/version.rb +8 -0
- data/lib/tasks/pagamento_digital.rake +6 -0
- data/nbproject/private/config.properties +0 -0
- data/nbproject/private/private.properties +3 -0
- data/nbproject/private/rake-d.txt +0 -0
- data/nbproject/project.properties +9 -0
- data/nbproject/project.xml +15 -0
- data/pagamento_digital.gemspec +26 -0
- data/templates/config.rb +43 -0
- metadata +126 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
module PagamentoDigital
|
2
|
+
class DeveloperController < ::ActionController::Base
|
3
|
+
skip_before_filter :verify_authenticity_token
|
4
|
+
|
5
|
+
ORDERS_FILE = File.join(Rails.root, "tmp", "pagamento_digital-#{Rails.env}.yml")
|
6
|
+
|
7
|
+
def create
|
8
|
+
# create the orders file if doesn't exist
|
9
|
+
FileUtils.touch(ORDERS_FILE) unless File.exist?(ORDERS_FILE)
|
10
|
+
|
11
|
+
# YAML caveat: if file is empty false is returned;
|
12
|
+
# we need to set default to an empty hash in this case
|
13
|
+
orders = YAML.load_file(ORDERS_FILE) || {}
|
14
|
+
|
15
|
+
# add a new order, associating it with the order id
|
16
|
+
orders[params[:id_pedido]] = params.except(:controller, :action, :only_path, :authenticity_token)
|
17
|
+
|
18
|
+
# save the file
|
19
|
+
File.open(ORDERS_FILE, "w+") do |file|
|
20
|
+
file << orders.to_yaml
|
21
|
+
end
|
22
|
+
|
23
|
+
# redirect to the configuration url
|
24
|
+
redirect = PagamentoDigital.config["return_to"].gsub(/\/?(.*)/,"/\\1")
|
25
|
+
|
26
|
+
return redirect_to redirect + "?id_pedido=#{params[:id_pedido]}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module PagamentoDigital
|
3
|
+
module Faker
|
4
|
+
extend self
|
5
|
+
|
6
|
+
NAMES = [
|
7
|
+
"Agatha", "Alana", "Alexandre", "Alice", "Aline", "Alícia", "Amanda", "Ana", "Ana", "André",
|
8
|
+
"Anthony", "Antônio", "Arthur", "Augusto", "Beatriz", "Benjamin", "Benício", "Bernardo",
|
9
|
+
"Bianca", "Brenda", "Breno", "Bruna", "Bruno", "Bryan", "Bárbara", "Caio", "Calebe", "Camila",
|
10
|
+
"Carlos", "Carolina", "Catarina", "Cecília", "Clara", "Clarice", "César", "Daniel", "Danilo",
|
11
|
+
"Davi", "Diego", "Diogo", "Eduarda", "Eduardo", "Elisa", "Eloá", "Emanuel", "Emanuela",
|
12
|
+
"Emily", "Enrico", "Enzo", "Erick", "Esther", "Evelyn", "Felipe", "Felipe", "Fernanda",
|
13
|
+
"Fernando", "Francisco", "Gabriel", "Gabriela", "Giovanna", "Giovanni", "Guilherme",
|
14
|
+
"Gustavo", "Heitor", "Helena", "Heloísa", "Henrique", "Henry", "Hugo", "Igor", "Isaac",
|
15
|
+
"Isabel", "Isabella", "Isadora", "Joana", "Joaquim", "Jonathan", "João", "Juan", "Juliana",
|
16
|
+
"Júlia", "Júlio", "Kamilly", "Kauã", "Kauê", "Kaíque", "Kevin", "Kyara", "Lara", "Larissa",
|
17
|
+
"Laura", "Lavínia", "Laís", "Leonardo", "Letícia", "Levi", "Lorena", "Lorenzo", "Luan",
|
18
|
+
"Luana", "Luca", "Lucas", "Luigi", "Luiz", "Luiza", "Luna", "Lívia", "Maitê", "Manuela",
|
19
|
+
"Marcela", "Marco", "Marcos", "Maria", "Mariana", "Marina", "Matheus", "Melissa", "Miguel",
|
20
|
+
"Milena", "Mirella", "Murilo", "Nathalia", "Nathan", "Nicolas", "Nicole", "Nina", "Olívia",
|
21
|
+
"Otávio", "Paulo", "Pedro", "Pietra", "Rafael", "Rafaela", "Raquel", "Raul", "Rayssa",
|
22
|
+
"Rebeca", "Renan", "Ricardo", "Rodrigo", "Ryan", "Sabrina", "Samuel", "Sarah", "Sophia",
|
23
|
+
"Sophie", "Stefany", "Stella", "Thais", "Thayla", "Theo", "Thomas", "Tiago", "Valentina",
|
24
|
+
"Vicente", "Vinicius", "Vitor", "Vitória", "Yago", "Yan", "Yasmin", "Yuri", "Ísis"
|
25
|
+
]
|
26
|
+
|
27
|
+
SURNAMES = [
|
28
|
+
"Abreu", "Aguiar", "Alencar", "Almeida", "Alves", "Amaral", "Ambrósio", "Amorim", "Amorim Neto",
|
29
|
+
"Andrade", "Andrade Filho", "Antunes", "Aparício", "Araújo", "Assis", "Azevedo", "Baltazar",
|
30
|
+
"Barbosa", "Bardini", "Barni", "Barra", "Barreto", "Barros", "Bastos", "Batista", "Belarmino",
|
31
|
+
"Bento Da Silva", "Bezerra", "Bianchini", "Bittencourt", "Boaventura", "Bonfim", "Borges",
|
32
|
+
"Braga", "Branco", "Brasil", "Brito", "Brunelli", "Cachoeira", "Caetano", "Camargo",
|
33
|
+
"Campos", "Canella", "Cardoso", "Carvalho", "Castilho", "Castro", "Coelho", "Correia", "Costa",
|
34
|
+
"Cândido", "de Sá", "Delfino", "do Vale", "Duarte", "Dutra", "Espindola", "Facchini", "Fagundes",
|
35
|
+
"Farias", "Fernandes", "Ferreira", "Fonseca", "Fortunato", "Franz", "França", "Freitas",
|
36
|
+
"Gomes", "Gonçalves", "Goulart", "Guedes", "Guerra", "Guimarães", "Hungaro", "Justino", "Leal",
|
37
|
+
"Leite", "Lima", "Linhares", "Liz", "Lombardi", "Lopes", "Macedo", "Machado", "Maia", "Manhães",
|
38
|
+
"Marques", "Martins", "Mendes", "Molinari", "Monteiro", "Morais", "Moreira", "Motta", "Neves",
|
39
|
+
"Nunes", "Oliveira", "Pacheco", "Paiva", "Pinheiro", "Pinto", "Ribeiro", "Rocha", "Rodrigues",
|
40
|
+
"Salles", "Santos", "Silva", "Souza", "Teixeira", "Vaz", "Ventura", "Vieira"
|
41
|
+
]
|
42
|
+
|
43
|
+
CITIES = [
|
44
|
+
"Augustinópolis", "Alegre", "Anitápolis", "Aroeiras do Itaim", "Auriflama", "Areia Branca",
|
45
|
+
"Areial", "Avelinópolis", "Açucena", "Álvaro de Carvalho", "Araguaína", "Arroio do Tigre",
|
46
|
+
"Anguera", "Águas Mornas", "Aquiraz", "Belmonte", "Barracão", "Barreira", "Belém de Maria",
|
47
|
+
"Barra do Chapéu", "Bandeira do Sul", "Biquinhas", "Baependi", "Bela Vista de Goiás",
|
48
|
+
"Buriti dos Montes", "Bom Lugar", "Brasil Novo", "Bocaiuva", "Bela Vista do Maranhão",
|
49
|
+
"Bom Sucesso de Itararé", "Caridade", "Capela", "Colombo", "Celso Ramos", "Carmolândia",
|
50
|
+
"Conceição do Castelo", "Camargo", "Carnaíba", "Carambeí", "Cametá", "Conceição de Macabu",
|
51
|
+
"Coronel Martins", "Capela", "Campina Verde", "Curiúva", "Divisópolis", "Darcinópolis",
|
52
|
+
"Divinolândia de Minas", "Dores do Turvo", "Dom Cavati", "Delfim Moreira", "Dobrada",
|
53
|
+
"Dona Emma", "Dionísio", "Delmiro Gouveia", "Dona Inês", "Dom Feliciano", "Datas",
|
54
|
+
"Divisa Alegre", "Dom Eliseu", "Ermo", "Escada", "Embaúba", "Encantado", "Elias Fausto",
|
55
|
+
"Embu", "Espírito Santo", "Encruzilhada", "Engenheiro Paulo de Frontin", "Equador",
|
56
|
+
"Erebango", "Estiva", "Esmeraldas", "Espera Feliz", "Eugênio de Castro", "Formoso", "Faro",
|
57
|
+
"Frutuoso Gomes", "Formoso do Araguaia", "Floreal", "Francisco Alves", "Fartura do Piauí",
|
58
|
+
"Ferreira Gomes", "Florestal", "Fontoura Xavier", "Fernandes Pinheiro", "Francisco Macedo",
|
59
|
+
"Fortaleza dos Valos", "Formigueiro", "Feira Grande", "Granito", "Gália", "General Carneiro",
|
60
|
+
"Graça", "Guarda-Mor", "Glória de Dourados", "Guarantã", "Gurjão", "Guareí",
|
61
|
+
"Governador Eugênio Barros", "Guarani das Missões", "Guaíba", "Glorinha", "Gilbués",
|
62
|
+
"Granja", "Horizontina", "Honório Serpa", "Hortolândia", "Heliópolis", "Horizonte",
|
63
|
+
"Hugo Napoleão", "Holambra", "Heitoraí", "Humaitá", "Humberto de Campos", "Hulha Negra",
|
64
|
+
"Humaitá", "Heliodora", "Herval", "Hidrolândia", "Itajá", "Inimutaba", "Itauçu",
|
65
|
+
"Itaporã do Tocantins", "Ivoti", "Ipaussu", "Itapirapuã", "Itiúba", "Itatinga", "Ipanema",
|
66
|
+
"Itaporanga", "Itamarati", "Itabira", "Imbé", "Iacri", "Japi", "Júlio Borges", "Jaciara",
|
67
|
+
"Jesuânia", "Jenipapo dos Vieiras", "Jucurutu", "Jaguaquara", "Jacobina do Piauí",
|
68
|
+
"Jaguariaíva", "Jaupaci", "Jatobá", "Juranda", "José Bonifácio", "Joaquim Távora",
|
69
|
+
"Jandira", "Kaloré", "Lagoinha", "Lambari d'Oeste", "Luís Alves", "Limoeiro",
|
70
|
+
"Lagoa do Piauí", "Liberato Salzano", "Luzerna", "Luciara", "Lindoeste", "Luislândia",
|
71
|
+
"Lajedinho", "Luzinópolis", "Lapa", "Lagoa Santa", "Luís Gomes", "Maratá", "Muniz Ferreira",
|
72
|
+
"Mato Verde", "Minaçu", "Marabá Paulista", "Monte Alegre", "Maripá", "Matias Cardoso",
|
73
|
+
"Mirandópolis", "Moema", "Monsenhor Tabosa", "Minador do Negrão", "Monte Santo de Minas",
|
74
|
+
"Miracatu", "Morada Nova", "Ninheira", "Nova União", "Niterói", "Nova Aurora", "Nova América",
|
75
|
+
"Nova Era", "Nova Aliança do Ivaí", "Nova Santa Helena", "Natércia", "Nova Tebas", "Natuba",
|
76
|
+
"Novo Hamburgo", "Nova Laranjeiras", "Neves Paulista", "Nova Candelária", "Ouro Velho",
|
77
|
+
"Ouro Verde do Oeste", "Ouro Fino", "Ourilândia do Norte", "Oeiras do Pará",
|
78
|
+
"Onça de Pitangui", "Oiapoque", "Óleo", "Olho d'Água do Piauí", "Olho d'Água do Casado",
|
79
|
+
"Ocauçu", "Ouro Verde", "Oliveira Fortes", "Orobó", "Osvaldo Cruz", "Pacatuba", "Peabiru",
|
80
|
+
"Portel", "Paverama", "Poção de Pedras", "Pirapemas", "Palestina", "Pedrinópolis",
|
81
|
+
"Pirpirituba", "Pantano Grande", "Pitangueiras", "Paulistânia", "Paulistas",
|
82
|
+
"Pedra Bonita", "Planalto da Serra", "Quixeré", "Quarto Centenário", "Quilombo",
|
83
|
+
"Quixaba", "Quatis", "Quixadá", "Quissamã", "Queluzito", "Quixabeira", "Quijingue",
|
84
|
+
"Quitandinha", "Queimada Nova", "Quixeramobim", "Queimadas", "Quinta do Sol", "Rio Preto",
|
85
|
+
"Ronda Alta", "Rio Bananal", "Rio Rufino", "Rondolândia", "Riacho de Santo Antônio",
|
86
|
+
"Rolim de Moura", "Riqueza", "Raposa", "Rio das Antas", "Riacho dos Machados", "Ribeirópolis",
|
87
|
+
"Raul Soares", "Rio Grande da Serra", "Roseira", "São João", "Santa Rita do Sapucaí",
|
88
|
+
"Salto do Jacuí", "Saúde", "Senador Georgino Avelino", "São Sebastião do Oeste", "São Pedro",
|
89
|
+
"Santa Cecília", "São José dos Quatro Marcos", "Sapé", "São Felipe d'Oeste",
|
90
|
+
"São Gonçalo do Amarante", "Siriri", "Sales Oliveira", "Santa Terezinha", "Timbó Grande",
|
91
|
+
"Tamboara", "Taguaí", "Trairão", "Theobroma", "Taperoá", "Torre de Pedra", "Teutônia",
|
92
|
+
"Taquarivaí", "Tanhaçu", "Tenório", "Três Lagoas", "Taperoá", "Terra Santa",
|
93
|
+
"Tangará da Serra", "Urupá", "Uiraúna", "Uchoa", "Uruoca", "União", "Uruguaiana",
|
94
|
+
"Uarini", "Ubaíra", "Una", "Urucará", "Uberaba", "Uru", "Umbuzeiro", "União Paulista",
|
95
|
+
"Umuarama", "Varjota", "Virgolândia", "Viçosa do Ceará", "Vera Cruz", "Vespasiano",
|
96
|
+
"Vista Gaúcha", "Vila Propício", "Vargem", "Vista Serrana", "Várzea Nova",
|
97
|
+
"Visconde do Rio Branco", "Várzea da Roça", "Vicência", "Venâncio Aires", "Vera",
|
98
|
+
"Witmarsum", "Wenceslau Guimarães", "Westfália", "Wenceslau Braz", "Wagner", "Wanderley",
|
99
|
+
"Wenceslau Braz", "Wall Ferraz", "Wanderlândia", "Xapuri", "Xangri-lá", "Xinguara", "Xaxim",
|
100
|
+
"Xambioá", "Xambrê", "Xexéu", "Xavantina", "Xanxerê", "Xique-Xique", "Zortéa", "Zabelê",
|
101
|
+
"Zé Doca", "Zacarias"
|
102
|
+
]
|
103
|
+
|
104
|
+
STATES = [
|
105
|
+
"Acre", "Alagoas", "Amapá", "Amazonas", "Bahia", "Ceará", "Distrito Federal", "Espírito Santo",
|
106
|
+
"Goiás", "Maranhão", "Mato Grosso", "Mato Grosso do Sul", "Minas Gerais", "Pará", "Paraíba",
|
107
|
+
"Paraná", "Pernambuco", "Piauí", "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul",
|
108
|
+
"Rondônia", "Roraima", "Santa Catarina", "São Paulo", "Sergipe", "Tocantins"
|
109
|
+
]
|
110
|
+
|
111
|
+
EMAILS = [
|
112
|
+
"gmail.com", "yahoo.com.br", "hotmail.com", "uol.com.br", "ig.com.br", "bol.com.br"
|
113
|
+
]
|
114
|
+
|
115
|
+
STREET_TYPES = ["Rua", "Avenida", "Estrada", "Alameda"]
|
116
|
+
|
117
|
+
SECONDARY_ADDRESS = ["Apto", "Casa", "Bloco"]
|
118
|
+
|
119
|
+
def street_name
|
120
|
+
"#{STREET_TYPES.sample} #{CITIES.sample}"
|
121
|
+
end
|
122
|
+
|
123
|
+
def secondary_address
|
124
|
+
"#{SECONDARY_ADDRESS.sample} #{rand(1000)}"
|
125
|
+
end
|
126
|
+
|
127
|
+
def phone_number(format = "(##) ####-####")
|
128
|
+
format.gsub(/#/) { (1..9).to_a.sample }
|
129
|
+
end
|
130
|
+
|
131
|
+
def zipcode
|
132
|
+
"#####-###".gsub(/#/) { (0..9).to_a.sample }
|
133
|
+
end
|
134
|
+
|
135
|
+
def email(base = nil)
|
136
|
+
base ||= full_name
|
137
|
+
base = normalize(base.downcase).gsub(/-/, ".")
|
138
|
+
"#{base}@#{EMAILS.sample}"
|
139
|
+
end
|
140
|
+
|
141
|
+
def name
|
142
|
+
NAMES.sample
|
143
|
+
end
|
144
|
+
|
145
|
+
def surname
|
146
|
+
SURNAMES.sample
|
147
|
+
end
|
148
|
+
|
149
|
+
def full_name
|
150
|
+
"#{name} #{surname}"
|
151
|
+
end
|
152
|
+
|
153
|
+
def city
|
154
|
+
CITIES.sample
|
155
|
+
end
|
156
|
+
|
157
|
+
def state
|
158
|
+
STATES.sample
|
159
|
+
end
|
160
|
+
|
161
|
+
private
|
162
|
+
def normalize(str)
|
163
|
+
str = ActiveSupport::Multibyte::Chars.new(str.dup)
|
164
|
+
str = str.normalize(:kd).gsub(/[^\x00-\x7F]/, "").to_s
|
165
|
+
str.gsub!(/[^-\w\d]+/xim, "-")
|
166
|
+
str.gsub!(/-+/xm, "-")
|
167
|
+
str.gsub!(/^-?(.*?)-?$/, '\1')
|
168
|
+
str.downcase!
|
169
|
+
str
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "rails/generators/base"
|
2
|
+
|
3
|
+
module PagamentoDigital
|
4
|
+
class InstallGenerator < ::Rails::Generators::Base
|
5
|
+
namespace "pagseguro:install"
|
6
|
+
source_root File.dirname(__FILE__) + "/../../templates"
|
7
|
+
|
8
|
+
def copy_configuration_file
|
9
|
+
copy_file "config.rb", "config/pagamento_digital.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,247 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module PagamentoDigital
|
5
|
+
class Notification
|
6
|
+
API_URL = "https://www.pagamentodigital.com.br/checkout/verify/"
|
7
|
+
|
8
|
+
# Map all the attributes from PagamentoDigital.
|
9
|
+
#
|
10
|
+
MAPPING = {
|
11
|
+
:tipo_pagamento => "tipo_pagamento",
|
12
|
+
:id_pedido => "id_pedido",
|
13
|
+
:processed_at => "data_transacao",
|
14
|
+
:status => "status",
|
15
|
+
:cod_status => "cod_status",
|
16
|
+
:id_transacao => "id_transacao",
|
17
|
+
:valor_original => 'valor_original',
|
18
|
+
:parcelas => 'parcelas',
|
19
|
+
:valor_loja => 'valor_loja',
|
20
|
+
:valor_total => 'valor_total',
|
21
|
+
:frete => 'frete',
|
22
|
+
:tipo_frete => 'tipo_frete',
|
23
|
+
:informacoes_loja => 'informacoes_loja',
|
24
|
+
:free => 'free',
|
25
|
+
:email_vendedor => 'email_vendedor',
|
26
|
+
}
|
27
|
+
|
28
|
+
|
29
|
+
COD_STATUS ={
|
30
|
+
'0' => :pendente,
|
31
|
+
'1' => :aprovada,
|
32
|
+
'2' => :cancelada
|
33
|
+
}
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
# # Map payment method from PagamentoDigital.
|
39
|
+
# #
|
40
|
+
PAYMENT_METHOD = {
|
41
|
+
"Boleto Bancário" => :boleto,
|
42
|
+
"Visa" => :credicard_visa,
|
43
|
+
"Mastercard" => :credicard_mastercard,
|
44
|
+
"American Express" => :credicard_amex,
|
45
|
+
"Diners" => :credicard_diners,
|
46
|
+
"Aura" => :credicard_aura,
|
47
|
+
"HiperCard" => :credicard_hiper,
|
48
|
+
"Transferência OnLine Banco do Brasil" => :trans_bb,
|
49
|
+
"Transferência OnLine Bradesco" => :trans_bradesco,
|
50
|
+
"Transferência OnLine Itaú" => :trans_itau,
|
51
|
+
"Transferência OnLine Banrisul" => :trans_banrisul,
|
52
|
+
"Transferência OnLine HSBC" => :trans_hsbc,
|
53
|
+
|
54
|
+
}
|
55
|
+
|
56
|
+
# The Rails params hash.
|
57
|
+
#
|
58
|
+
attr_accessor :params
|
59
|
+
|
60
|
+
# Expects the params object from the current request.
|
61
|
+
# PagamentoDigital will send POST with ISO-8859-1 encoded data,
|
62
|
+
# so we need to normalize it to UTF-8.
|
63
|
+
#
|
64
|
+
def initialize(params, token = nil)
|
65
|
+
@token = token
|
66
|
+
@params = PagamentoDigital.developer? ? params : normalize(params)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Normalize the specified hash converting all data to UTF-8.
|
70
|
+
#
|
71
|
+
def normalize(hash)
|
72
|
+
return hash
|
73
|
+
# each_value(hash) do |value|
|
74
|
+
# Utils.to_utf8(value)
|
75
|
+
# end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Denormalize the specified hash converting all data to ISO-8859-1.
|
79
|
+
#
|
80
|
+
def denormalize(hash)
|
81
|
+
return hash
|
82
|
+
# each_value(hash) do |value|
|
83
|
+
# Utils.to_iso8859(value)
|
84
|
+
# end
|
85
|
+
end
|
86
|
+
|
87
|
+
# Return a list of produtos sent by PagamentoDigital.
|
88
|
+
# The values will be normalized
|
89
|
+
# (e.g. currencies will be converted to cents, quantity will be an integer)
|
90
|
+
#
|
91
|
+
def produtos
|
92
|
+
@produtos ||= begin
|
93
|
+
items = []
|
94
|
+
i = 0;
|
95
|
+
loop do
|
96
|
+
i += 1
|
97
|
+
break if params["produto_qtde_#{i}"].blank?
|
98
|
+
items << {
|
99
|
+
:id => params["produto_codigo_#{i}"],
|
100
|
+
:descricao => params["produto_descricao_#{i}"],
|
101
|
+
:qtde => params["produto_qtde_#{i}"].to_i,
|
102
|
+
:preco => to_price(params["produto_valor_#{i}"]),
|
103
|
+
:extra => params["produto_extra_#{i}"]
|
104
|
+
}
|
105
|
+
end
|
106
|
+
|
107
|
+
items
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def cliente
|
112
|
+
@cliente ||= params.inject({}){|ret,args|
|
113
|
+
key,value = args.first,args.second
|
114
|
+
ret[key.gsub('cliente_','')] = value if key =~ /^cliente_.*$/
|
115
|
+
ret
|
116
|
+
}
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
# Return the shipping fee.
|
121
|
+
# Will be converted to a float number.
|
122
|
+
#
|
123
|
+
def frete
|
124
|
+
to_price mapping_for(:frete)
|
125
|
+
end
|
126
|
+
|
127
|
+
# Return the order status.
|
128
|
+
# Will be mapped to the STATUS constant.
|
129
|
+
#
|
130
|
+
def status
|
131
|
+
@status ||= COD_STATUS[mapping_for(:cod_status).to_s]
|
132
|
+
end
|
133
|
+
def aprovada?
|
134
|
+
status == :aprovada
|
135
|
+
end
|
136
|
+
def cancelada?
|
137
|
+
status == :cancelada
|
138
|
+
end
|
139
|
+
def pendente?
|
140
|
+
status == :pendente
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
# Return the payment method.
|
145
|
+
# Will be mapped to the PAYMENT_METHOD constant.
|
146
|
+
#
|
147
|
+
def payment_method
|
148
|
+
@payment_method ||= PAYMENT_METHOD[mapping_for()]
|
149
|
+
end
|
150
|
+
|
151
|
+
# Parse the processing date to a Ruby object.
|
152
|
+
#
|
153
|
+
def processed_at
|
154
|
+
@processed_at ||= begin
|
155
|
+
groups = *mapping_for(:processed_at).match(/(\d{2})\/(\d{2})\/(\d{4}) ([\d:]+)/sm)
|
156
|
+
Time.parse("#{groups[3]}-#{groups[2]}-#{groups[1]} #{groups[4]}")
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
|
161
|
+
def method_missing(method, *args)
|
162
|
+
return mapping_for(method) if MAPPING[method]
|
163
|
+
super
|
164
|
+
end
|
165
|
+
|
166
|
+
def respond_to?(method, include_private = false)
|
167
|
+
return true if MAPPING[method]
|
168
|
+
super
|
169
|
+
end
|
170
|
+
|
171
|
+
# A wrapper to the params hash,
|
172
|
+
# sanitizing the return to symbols.
|
173
|
+
#
|
174
|
+
def mapping_for(name)
|
175
|
+
params[MAPPING[name]]
|
176
|
+
end
|
177
|
+
|
178
|
+
# Cache the validation.
|
179
|
+
# To bypass the cache, just provide an argument that is evaluated as true.
|
180
|
+
#
|
181
|
+
# invoice.valid?
|
182
|
+
# invoice.valid?(:nocache)
|
183
|
+
#
|
184
|
+
def valid?(force=false)
|
185
|
+
@valid = nil if force
|
186
|
+
@valid = validates? if @valid.nil?
|
187
|
+
@valid
|
188
|
+
end
|
189
|
+
|
190
|
+
# Return all useful properties in a single hash.
|
191
|
+
#
|
192
|
+
def to_hash
|
193
|
+
MAPPING.inject({}) do |buffer, (name,value)|
|
194
|
+
buffer.merge(name => __send__(name))
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
private
|
199
|
+
def each_value(hash, &blk) # :nodoc:
|
200
|
+
hash.each do |key, value|
|
201
|
+
if value.kind_of?(Hash)
|
202
|
+
hash[key] = each_value(value, &blk)
|
203
|
+
else
|
204
|
+
hash[key] = blk.call value
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
hash
|
209
|
+
end
|
210
|
+
|
211
|
+
# Convert amount format to float.
|
212
|
+
#
|
213
|
+
def to_price(amount)
|
214
|
+
amount = "0#{amount}" if amount =~ /^\,/
|
215
|
+
amount.to_s.to_f
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
# Check if the provided data is valid by requesting the
|
221
|
+
# confirmation API url. The request will always be valid while running in
|
222
|
+
# developer mode.
|
223
|
+
#
|
224
|
+
def validates?
|
225
|
+
return true if PagamentoDigital.developer?
|
226
|
+
# include the params to validate our request
|
227
|
+
|
228
|
+
request_params = {
|
229
|
+
:transacao => params[:id_transacao],
|
230
|
+
:cod_status => params[:cod_status],
|
231
|
+
:valor_original => params[:valor_original],
|
232
|
+
:valor_loja => params[:valor_loja],
|
233
|
+
:token => @token || PagamentoDigital.config["authenticity_token"]
|
234
|
+
}
|
235
|
+
|
236
|
+
|
237
|
+
#send form by ruby
|
238
|
+
response = Net::HTTP.post_form(URI.parse(API_URL),denormalize(request_params) )
|
239
|
+
|
240
|
+
(response.body =~ /VERIFICADO/) != nil
|
241
|
+
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
|