dineromail 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/Rakefile +5 -0
- data/dineromail.gemspec +25 -0
- data/lib/dineromail.rb +20 -0
- data/lib/dineromail/app/helpers/dineromail_helper.rb +46 -0
- data/lib/dineromail/buyer.rb +12 -0
- data/lib/dineromail/configuration.rb +16 -0
- data/lib/dineromail/notification.rb +32 -0
- data/lib/dineromail/status_report.rb +60 -0
- data/lib/dineromail/version.rb +3 -0
- data/spec/dineromail/notification_spec.rb +14 -0
- data/spec/dineromail/status_report_spec.rb +46 -0
- data/spec/spec_helper.rb +7 -0
- metadata +155 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/dineromail.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "dineromail/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "dineromail"
|
7
|
+
s.version = Dineromail::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Nicolas Mosconi", "Shadi Calcagni", "Juan Pablo Gutierrez"]
|
10
|
+
s.email = ["nicolas@soluciones-simplex.com.ar", "shadi@soluciones-simplex.com.ar", "juanpablo@soluciones-simplex.com.ar"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Dineromail library for Rails}
|
13
|
+
s.description = %q{Integration with dineromail plataform for rails proyects}
|
14
|
+
|
15
|
+
s.add_dependency "xml-simple"
|
16
|
+
s.add_dependency "httparty"
|
17
|
+
s.add_dependency "rails", ["~> 3.0"]
|
18
|
+
s.add_development_dependency "bundler"
|
19
|
+
s.add_development_dependency "rspec"
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
data/lib/dineromail.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'dineromail/version'
|
2
|
+
require 'dineromail/notification'
|
3
|
+
require 'dineromail/status_report'
|
4
|
+
require 'dineromail/buyer'
|
5
|
+
require 'dineromail/configuration'
|
6
|
+
require 'dineromail/app/helpers/dineromail_helper'
|
7
|
+
require 'action_controller'
|
8
|
+
|
9
|
+
module Dineromail
|
10
|
+
self.configure do |config|
|
11
|
+
#Default confiuration
|
12
|
+
config.ipn_webservice_url = 'https://argentina.dineromail.com/Vender/Consulta_IPN.asp'
|
13
|
+
config.currency = 1
|
14
|
+
config.pay_methods = '' #Todos
|
15
|
+
config.payment_url = 'https://argentina.dineromail.com/Shop/Shop_Ingreso.asp'
|
16
|
+
config.button_image_url = 'https://argentina.dineromail.com/imagenes/vender/boton/comprar-gris.gif'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
ActionController::Base.helper(DineromailHelper)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module DineromailHelper
|
2
|
+
|
3
|
+
def dineromail_form(item_name,amount,options = {})
|
4
|
+
options = options.symbolize_keys
|
5
|
+
button_image_url = options.delete(:button_image_url) || Dineromail.configuration.button_image_url
|
6
|
+
payment_url = options.delete(:payment_url) || Dineromail.configuration.payment_url
|
7
|
+
form_options = options.delete(:form) || {}
|
8
|
+
form_options[:action] = payment_url
|
9
|
+
content_tag(:form, form_options ) do
|
10
|
+
dineromail_inputs(item_name,amount,options) +
|
11
|
+
content_tag(:input,nil, :type => 'image', :src => button_image_url, :border => '0', :name=> 'submit', :alt=>'Pagar con Dineromail' )
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def dineromail_inputs(item_name,amount,options = {})
|
17
|
+
options = options.symbolize_keys
|
18
|
+
logo_url = options[:logo_url] || Dineromail.configuration.logo_url
|
19
|
+
return_url = options[:return_url] || Dineromail.configuration.return_url
|
20
|
+
error_url = options[:error_url] || Dineromail.configuration.error_url
|
21
|
+
message = options[:message] ? 1 : 0
|
22
|
+
account_number = options[:account_number] || Dineromail.configuration.account_number
|
23
|
+
pay_methods = options[:pay_methods] || Dineromail.configuration.pay_methods
|
24
|
+
currency = options[:currency] || Dineromail.configuration.currency
|
25
|
+
transaction_id = options[:transaction_id]
|
26
|
+
item_number = options[:item_number]
|
27
|
+
|
28
|
+
html = content_tag(:input,nil, :type => 'hidden', :name => 'NombreItem', :value =>item_name)
|
29
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'TipoMoneda', :value =>currency)
|
30
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'PrecioItem', :value =>amount)
|
31
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'E_Comercio', :value =>account_number)
|
32
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'image_url', :value =>logo_url)
|
33
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'DireccionExito', :value => return_url)
|
34
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'DireccionFracaso', :value => error_url)
|
35
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'Mensaje', :value => message)
|
36
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'MediosPago', :value => pay_methods)
|
37
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'NroItem', :value => item_number) if item_number
|
38
|
+
html += content_tag(:input,nil, :type => 'hidden', :name => 'TRX_ID', :value => transaction_id) if transaction_id
|
39
|
+
|
40
|
+
html
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Dineromail
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :payment_url, :ipn_webservice_url, :account_number, :password,
|
4
|
+
:logo_url, :return_url, :error_url, :pay_methods, :currency, :button_image_url
|
5
|
+
end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
self.configuration ||= Configuration.new
|
13
|
+
yield configuration
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'xmlsimple'
|
2
|
+
module Dineromail
|
3
|
+
class Notification
|
4
|
+
|
5
|
+
attr_reader :transaction_id, :tipo
|
6
|
+
|
7
|
+
def initialize(transaction_id, tipo = null)
|
8
|
+
@transaction_id = transaction_id
|
9
|
+
@tipo = tipo
|
10
|
+
end
|
11
|
+
|
12
|
+
def status_report
|
13
|
+
unless @status_report
|
14
|
+
@status_report = StatusReport.new(transaction_id)
|
15
|
+
end
|
16
|
+
@status_report
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.from_xml(notification_xml)
|
20
|
+
notifications = []
|
21
|
+
notificaction_data = XmlSimple.xml_in(notification_xml)
|
22
|
+
operations = notificaction_data['OPERACIONES'].first['OPERACION']
|
23
|
+
operations.each do |operation|
|
24
|
+
tipo = operation['TIPO'].first
|
25
|
+
transaction_id = operation['ID'].first
|
26
|
+
notifications << self.new(transaction_id, tipo)
|
27
|
+
end
|
28
|
+
notifications
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'xmlsimple'
|
2
|
+
require 'dineromail/buyer'
|
3
|
+
module Dineromail
|
4
|
+
class StatusReport
|
5
|
+
attr_accessor :transaction_id, :date, :status, :amount, :net_amount, :pay_method, :pay_medium, :buyer
|
6
|
+
|
7
|
+
PENDING_STATUS = 1
|
8
|
+
ACCREDITED_STATUS = 2
|
9
|
+
CANCELLED_STATUS = 3
|
10
|
+
|
11
|
+
def initialize(transaction_id = nil)
|
12
|
+
if transaction_id
|
13
|
+
obtain_status_report_data_for transaction_id
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def obtain_status_report_data_for(transaction_id)
|
18
|
+
self.transaction_id = transaction_id
|
19
|
+
account_number = Dineromail.configuration.account_number
|
20
|
+
password = Dineromail.configuration.password
|
21
|
+
ipn_url = Dineromail.configuration.ipn_webservice_url
|
22
|
+
request_data = "<REPORTE>
|
23
|
+
<NROCTA>#{account_number}</NROCTA>
|
24
|
+
<DETALLE>
|
25
|
+
<CONSULTA>
|
26
|
+
<CLAVE>#{password}</CLAVE>
|
27
|
+
<TIPO>1</TIPO>
|
28
|
+
<OPERACIONES>
|
29
|
+
<ID>#{transaction_id}</ID>
|
30
|
+
</OPERACIONES>
|
31
|
+
</CONSULTA>
|
32
|
+
<DETALLE>
|
33
|
+
</REPORTE>"
|
34
|
+
response = HTTParty.get ipn_url , :query => {:data => request_data}
|
35
|
+
parse_response response.body
|
36
|
+
end
|
37
|
+
|
38
|
+
def parse_response(response)
|
39
|
+
response_data = XmlSimple.xml_in(response)
|
40
|
+
operation = response_data['DETALLE'].first['OPERACIONES'].first['OPERACION'].first
|
41
|
+
self.transaction_id = operation['ID'].first
|
42
|
+
self.date = operation['FECHA'].first
|
43
|
+
self.status = operation['ESTADO'].first.to_i
|
44
|
+
self.amount = operation['MONTO'].first.to_f
|
45
|
+
self.net_amount = operation['MONTONETO'].first.to_f
|
46
|
+
self.pay_method = operation['METODOPAGO'].first
|
47
|
+
self.pay_medium = operation['MEDIOPAGO'].first
|
48
|
+
buyer_data = operation['COMPRADOR'].first
|
49
|
+
self.buyer = Buyer.new
|
50
|
+
buyer.email = buyer_data['EMAIL'].first
|
51
|
+
buyer.address = buyer_data['DIRECCION'].first
|
52
|
+
buyer.comment = buyer_data['COMENTARIO'].first
|
53
|
+
buyer.name = buyer_data['NOMBRE'].first
|
54
|
+
buyer.phone = buyer_data['TELEFONO'].first
|
55
|
+
buyer.document_type = buyer_data['TIPODOC'].first
|
56
|
+
buyer.document_number = buyer_data['NUMERODOC'].first
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dineromail::Notification do
|
4
|
+
it 'should load the notifications from the notification xml' do
|
5
|
+
notification_xml = '<NOTIFICACION><TIPONOTIFICACION>1</TIPONOTIFICACION><OPERACIONES><OPERACION><TIPO>1</TIPO><ID>31548</ID></OPERACION><OPERACION><TIPO>1</TIPO><ID>XA5547</ID></OPERACION></OPERACIONES></NOTIFICACION>'
|
6
|
+
notifications = Dineromail::Notification.from_xml(notification_xml)
|
7
|
+
notifications.count.should == 2
|
8
|
+
notifications.first.transaction_id.should == '31548'
|
9
|
+
notifications.last.transaction_id.should == 'XA5547'
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dineromail::StatusReport do
|
4
|
+
it 'should load the status report from xml' do
|
5
|
+
xml = '<REPORTE><ESTADOREPORTE></ESTADOREPORTE><DETALLE><OPERACIONES><OPERACION>
|
6
|
+
<ID>1889</ID>
|
7
|
+
<FECHA>17/01/2011</FECHA>
|
8
|
+
<ESTADO>1</ESTADO>
|
9
|
+
<NUMTRANSACCION>67777</NUMTRANSACCION>
|
10
|
+
<COMPRADOR>
|
11
|
+
<EMAIL>comprador@email.com</EMAIL>
|
12
|
+
<DIRECCION>San Martin 10</DIRECCION>
|
13
|
+
<COMENTARIO>comentario</COMENTARIO>
|
14
|
+
<NOMBRE>Juan</NOMBRE>
|
15
|
+
<TELEFONO>4444444</TELEFONO>
|
16
|
+
<TIPODOC>DNI</TIPODOC>
|
17
|
+
<NUMERODOC>222222222</NUMERODOC>
|
18
|
+
</COMPRADOR>
|
19
|
+
<MONTO>60</MONTO>
|
20
|
+
<MONTONETO>50</MONTONETO>
|
21
|
+
<METODOPAGO>TARJETA DE CREDITO</METODOPAGO>
|
22
|
+
<MEDIOPAGO>VISA</MEDIOPAGO>
|
23
|
+
<CUOTAS>1</CUOTAS>
|
24
|
+
<ITEMS><ITEM><DESCRIPCION></DESCRIPCION><MONEDA></MONEDA><PRECIOUNITARIO></PRECIOUNITARIO><CANTIDAD></CANTIDAD></ITEM></ITEMS><VENDEDOR><TIPODOC></TIPODOC><NUMERODOC></NUMERODOC></VENDEDOR></OPERACION></OPERACIONES></DETALLE></REPORTE>'
|
25
|
+
|
26
|
+
status_report = Dineromail::StatusReport.new
|
27
|
+
status_report.parse_response(xml)
|
28
|
+
buyer = status_report.buyer
|
29
|
+
|
30
|
+
|
31
|
+
status_report.transaction_id.should == '1889'
|
32
|
+
status_report.date.should == '17/01/2011'
|
33
|
+
status_report.status.should == Dineromail::StatusReport::PENDING_STATUS
|
34
|
+
status_report.amount.should == 60.0
|
35
|
+
status_report.net_amount.should == 50.0
|
36
|
+
status_report.pay_method.should == 'TARJETA DE CREDITO'
|
37
|
+
status_report.pay_medium.should == 'VISA'
|
38
|
+
buyer.email.should == 'comprador@email.com'
|
39
|
+
buyer.address.should == 'San Martin 10'
|
40
|
+
buyer.comment.should == 'comentario'
|
41
|
+
buyer.name.should == 'Juan'
|
42
|
+
buyer.phone.should == '4444444'
|
43
|
+
buyer.document_type.should == 'DNI'
|
44
|
+
buyer.document_number.should == '222222222'
|
45
|
+
end
|
46
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dineromail
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Nicolas Mosconi
|
14
|
+
- Shadi Calcagni
|
15
|
+
- Juan Pablo Gutierrez
|
16
|
+
autorequire:
|
17
|
+
bindir: bin
|
18
|
+
cert_chain: []
|
19
|
+
|
20
|
+
date: 2011-05-28 00:00:00 -03:00
|
21
|
+
default_executable:
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
name: xml-simple
|
25
|
+
prerelease: false
|
26
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
hash: 3
|
32
|
+
segments:
|
33
|
+
- 0
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: httparty
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
version: "0"
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
- !ruby/object:Gem::Dependency
|
52
|
+
name: rails
|
53
|
+
prerelease: false
|
54
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ~>
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 7
|
60
|
+
segments:
|
61
|
+
- 3
|
62
|
+
- 0
|
63
|
+
version: "3.0"
|
64
|
+
type: :runtime
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: bundler
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rspec
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
type: :development
|
93
|
+
version_requirements: *id005
|
94
|
+
description: Integration with dineromail plataform for rails proyects
|
95
|
+
email:
|
96
|
+
- nicolas@soluciones-simplex.com.ar
|
97
|
+
- shadi@soluciones-simplex.com.ar
|
98
|
+
- juanpablo@soluciones-simplex.com.ar
|
99
|
+
executables: []
|
100
|
+
|
101
|
+
extensions: []
|
102
|
+
|
103
|
+
extra_rdoc_files: []
|
104
|
+
|
105
|
+
files:
|
106
|
+
- .gitignore
|
107
|
+
- Gemfile
|
108
|
+
- Rakefile
|
109
|
+
- dineromail.gemspec
|
110
|
+
- lib/dineromail.rb
|
111
|
+
- lib/dineromail/app/helpers/dineromail_helper.rb
|
112
|
+
- lib/dineromail/buyer.rb
|
113
|
+
- lib/dineromail/configuration.rb
|
114
|
+
- lib/dineromail/notification.rb
|
115
|
+
- lib/dineromail/status_report.rb
|
116
|
+
- lib/dineromail/version.rb
|
117
|
+
- spec/dineromail/notification_spec.rb
|
118
|
+
- spec/dineromail/status_report_spec.rb
|
119
|
+
- spec/spec_helper.rb
|
120
|
+
has_rdoc: true
|
121
|
+
homepage: ""
|
122
|
+
licenses: []
|
123
|
+
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: 3
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
none: false
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
hash: 3
|
144
|
+
segments:
|
145
|
+
- 0
|
146
|
+
version: "0"
|
147
|
+
requirements: []
|
148
|
+
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 1.3.7
|
151
|
+
signing_key:
|
152
|
+
specification_version: 3
|
153
|
+
summary: Dineromail library for Rails
|
154
|
+
test_files: []
|
155
|
+
|