active_merchant_webpay 0.0.1

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.
Files changed (62) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +4 -0
  3. data/README.rdoc +4 -0
  4. data/Rakefile +2 -0
  5. data/active_merchant_webpay.gemspec +22 -0
  6. data/example/.gitignore +4 -0
  7. data/example/Gemfile +4 -0
  8. data/example/Gemfile.lock +84 -0
  9. data/example/README +256 -0
  10. data/example/Rakefile +7 -0
  11. data/example/app/controllers/application_controller.rb +3 -0
  12. data/example/app/controllers/buy_controller.rb +30 -0
  13. data/example/app/helpers/application_helper.rb +2 -0
  14. data/example/app/helpers/buy_helper.rb +2 -0
  15. data/example/app/views/buy/index.html.erb +14 -0
  16. data/example/app/views/layouts/application.html.erb +14 -0
  17. data/example/config.ru +4 -0
  18. data/example/config/application.rb +27 -0
  19. data/example/config/boot.rb +13 -0
  20. data/example/config/environment.rb +5 -0
  21. data/example/config/environments/development.rb +26 -0
  22. data/example/config/environments/production.rb +49 -0
  23. data/example/config/environments/test.rb +35 -0
  24. data/example/config/initializers/backtrace_silencers.rb +7 -0
  25. data/example/config/initializers/inflections.rb +10 -0
  26. data/example/config/initializers/mime_types.rb +5 -0
  27. data/example/config/initializers/secret_token.rb +7 -0
  28. data/example/config/initializers/session_store.rb +8 -0
  29. data/example/config/locales/en.yml +5 -0
  30. data/example/config/routes.rb +7 -0
  31. data/example/db/seeds.rb +7 -0
  32. data/example/doc/README_FOR_APP +2 -0
  33. data/example/lib/tasks/.gitkeep +0 -0
  34. data/example/public/404.html +26 -0
  35. data/example/public/422.html +26 -0
  36. data/example/public/500.html +26 -0
  37. data/example/public/favicon.ico +0 -0
  38. data/example/public/images/rails.png +0 -0
  39. data/example/public/javascripts/.gitkeep +0 -0
  40. data/example/public/javascripts/application.js +0 -0
  41. data/example/public/robots.txt +5 -0
  42. data/example/public/stylesheets/.gitkeep +0 -0
  43. data/example/script/rails +6 -0
  44. data/example/vendor/plugins/.gitkeep +0 -0
  45. data/example/vendor/webpay/datos/tbk_config.dat +15 -0
  46. data/example/vendor/webpay/datos/tbk_param.txt +71 -0
  47. data/example/vendor/webpay/datos/tbk_trace.dat +15 -0
  48. data/example/vendor/webpay/maestros/privada.pem +15 -0
  49. data/example/vendor/webpay/tbk_bp_pago.cgi +0 -0
  50. data/example/vendor/webpay/tbk_bp_resultado.cgi +0 -0
  51. data/example/vendor/webpay/tbk_check_mac.cgi +0 -0
  52. data/example/vendor/webpay/template/leeme.txt +15 -0
  53. data/example/vendor/webpay/template/reintento.html +1 -0
  54. data/example/vendor/webpay/template/transicion.html +132 -0
  55. data/lib/active_merchant/billing/integrations/webpay.rb +23 -0
  56. data/lib/active_merchant/billing/integrations/webpay/helper.rb +25 -0
  57. data/lib/active_merchant/billing/integrations/webpay/middleware.rb +86 -0
  58. data/lib/active_merchant/billing/integrations/webpay/notification.rb +116 -0
  59. data/lib/active_merchant/billing/integrations/webpay/railtie.rb +13 -0
  60. data/lib/active_merchant/billing/integrations/webpay/version.rb +9 -0
  61. data/lib/active_merchant_webpay.rb +2 -0
  62. metadata +139 -0
@@ -0,0 +1,15 @@
1
+ GLEVEL = 7
2
+
3
+ // niveles soportados LOGINFO 1
4
+ // LOGERROR 2
5
+ // LOGFATAL 4
6
+ //
7
+ // glebel 0 >>> No genera LOG
8
+ //
9
+ // combinatorias glebel 1 >>> LOGINFO
10
+ // glebel 2 >>> LOGERROR
11
+ // glebel 3 >>> LOGINFO + LOGERROR
12
+ // glebel 4 >>> LOGFATAL
13
+ // glebel 5 >>> LOGINFO + LOGFATAL
14
+ // glebel 6 >>> LOGERROR + LOGFATAL
15
+ // glebel 7 >>> LOGINFO + LOGERROR + LOGFATAL
@@ -0,0 +1,15 @@
1
+ -----BEGIN RSA PRIVATE KEY-----
2
+ MIICXQIBAAKBgQDV3xIu3OnC9v7a/asLoy6NOF3n3I0e58Yy1+4mOn1kso4ESExp
3
+ OY5U1K267TEUFPN/BFO5FgZCAC3bClkHJ5tN7z2a5Gu7rXfwO0HJ+cDduOOv0QFX
4
+ ZUjcM923cy5FFbDLcUPUPMq1hXcCH7tKUrKOunKwBEmkqyhp96/90T4afwIBAwKB
5
+ gQCOlLbJ6JvXT1SR/nIHwh8I0D6akwi/RS7Mj/QZfFOYdwlYMDLw0QmN4x58niC4
6
+ DfeqAuJ7ZAQsAB6SBuYExRIyvAIniU4J817NXcFAsNELGvdp9AjBYJYPv0+4pTDI
7
+ hptIpY9zBi+7Bz9v00V89xxoEzcYcTVZJhyQ7MAcODWrewJBAPu4rezz1sDuntjn
8
+ L2gjll2KcDgiE7PuO/x0WyinpksmIP4MHjmPIoCPCyAcZ6hVFtJJR7DlG6XEfp0G
9
+ eEy+gM0CQQDZgbGpgtX/ex1VuLmIY7ay5iCq0iGgeYiYccdSvXIAob164Il58/p6
10
+ CM9Ctqc3stvLVsOplINMORH3iVswLxh7AkEAp9Bz80051fRp5e908Be5k7GgJWwN
11
+ Ip7SqE2SGxpu3MQV/rK+0QoXAF9cwBLvxY4PNtuFIJi9GS2pvgRQMymrMwJBAJEB
12
+ IRusjqpSE457JlrtJHdEFcc2wRWmWxBL2jco9qsWflHrBlFNUaawiix5xM/MkoeP
13
+ LRu4V4gmC/pbkiAfZacCQQDaPiFEkZlOP8ZW9SeXdwcNt1fay2MrnFqMPGPnerri
14
+ X/1p1oAObaX3NYENyGZQ0U2Bzm3tHsc6lozrgi1QVZYR
15
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1,15 @@
1
+ Directorio Template
2
+ ===================
3
+
4
+ Este directorio contiene la p�gina html de reintento denominada
5
+ por ejemplo:
6
+
7
+ reintento.html
8
+
9
+
10
+ Pagina de Reintento
11
+ ===================
12
+
13
+ En este directorio se debe crear una p�gina de reintento. Esta p�gina
14
+ se invoca cuando existe un problema con los pasos de par�metros en
15
+ WebPay.
@@ -0,0 +1 @@
1
+ Pagina de Reintento
@@ -0,0 +1,132 @@
1
+ <HTML>
2
+ <HEAD>
3
+ <TITLE>Web Pay</TITLE>
4
+ <META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5
+ <SCRIPT language="JavaScript">
6
+ version=navigator.appVersion.charAt(0);
7
+
8
+ function my_onLoad() {
9
+ timeout = setTimeout("go()",120000);
10
+ if(version>="3") ss=true;
11
+ else document.formulario.submit();
12
+ }
13
+
14
+ function print_images() {
15
+ var images = "";
16
+ if(version>="3") {
17
+ images="<BR><BR>";
18
+ images+="<IMG SRC=\"images/cblue.jpg\" NAME=a BORDER=1>";
19
+ for(i=1;i<10;i++)
20
+ images+="<IMG SRC=\"images/cblanco.jpg\" NAME=a"+i+" BORDER=1>";
21
+ images+="<BR><BR>";
22
+ } else {
23
+ images="<IMG SRC=\"images/timer.gif\" width=300 height=100>";
24
+ }
25
+ document.write(images);
26
+ }
27
+
28
+ if (version >= "3") {
29
+ ss = false;
30
+ timerID = null;
31
+ timerRunning = false;
32
+ indice = 1;
33
+ mono = new Image(20,20);
34
+ mono.src = "images/cblue.jpg";
35
+ }
36
+ function stopclock(){
37
+ if(timerRunning) clearTimeout(timerID);
38
+ timerRunning = false;
39
+ }
40
+ function startclock() {
41
+ stopclock();
42
+ showtime();
43
+ }
44
+ function showtime() {
45
+ if (ss) {
46
+ document.formulario.submit();
47
+ ss=false;
48
+ }
49
+ if (indice<10) document.images["a"+indice++].src = mono.src ;
50
+ timerID = setTimeout("showtime()",1500);
51
+ timerRunning = true;
52
+ }
53
+ function go(){
54
+ document.open();
55
+ <!--REINTE-->
56
+ document.close();
57
+ return;
58
+ }
59
+
60
+ //TEXTOS EN ESPANOL
61
+ var TEXTO_MENSAJE_ESP = new Array();
62
+ TEXTO_MENSAJE_ESP["MSG_TITULO"] = "PROCESANDO TRANSACCION";
63
+ TEXTO_MENSAJE_ESP["MSG_LOCK"] = "Esta transacci&oacute;n se est&aacute; realizando sobre un sistema seguro Transbank";
64
+ TEXTO_MENSAJE_ESP["MSG_PROCESANDO_TRANSACCION"] = "Su transacci&oacute;n est&aacute; siendo procesada.";
65
+
66
+ //TEXTOS EN INGLES
67
+ var TEXTO_MENSAJE_ENG = new Array();
68
+ TEXTO_MENSAJE_ENG["MSG_TITULO"] = "PROCESSING TRANSACTION";
69
+ TEXTO_MENSAJE_ENG["MSG_LOCK"] = "Your transaction is being executed on a secure server within Transbank S.A.";
70
+ TEXTO_MENSAJE_ENG["MSG_PROCESANDO_TRANSACCION"] = "Your transaction is being processed";
71
+
72
+ //Selecciona lenguaje
73
+ var lenguaje = "ESP";
74
+ //<!--LENGUAJE-->
75
+ if (lenguaje == "ENG") TEXTO_MENSAJE=TEXTO_MENSAJE_ENG;
76
+ else TEXTO_MENSAJE = TEXTO_MENSAJE_ESP;
77
+
78
+ //Funcion para escribir el texto
79
+ function mensaje(msgindex) {
80
+ document.write(TEXTO_MENSAJE[msgindex]);
81
+ }
82
+
83
+ </SCRIPT>
84
+ </HEAD>
85
+ <BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 background="/images/background.gif" onLoad="my_onLoad()">
86
+ <TABLE width="100%" border=0 cellspacing=0 cellpadding=0 height="100%">
87
+ <TR><TD>
88
+ <TABLE width="100%" border=0 cellspacing=0 cellpadding=0>
89
+ <TR bgcolor="#FFFFFF"><TD height=12 align=center>
90
+ <TABLE width=550 border=0 cellspacing=0 cellpadding=0><TR>
91
+ <TD width=71><IMG height\=59 width\=130
92
+ <!--LOGO-->
93
+ </TD>
94
+ <TD width=357 align="center">
95
+ <FONT face="Arial, Helvetica, sans-serif" size=3><B>
96
+ <SCRIPT>mensaje("MSG_TITULO")</SCRIPT></B></FONT>
97
+ </TD>
98
+ <TD width=122 align="center">
99
+ <IMG src="images/webpay.gif">
100
+ <SCRIPT>
101
+ if (lenguaje == "ENG")
102
+ document.write("<IMG src=\"images/eunservicio.gif\">");
103
+ else
104
+ document.write("<IMG src=\"images/unservicio.gif\">");
105
+ </SCRIPT>
106
+ </TD>
107
+ </TR></TABLE>
108
+ </TD></TR>
109
+ <TR bgcolor="#999999"><TD align="center">
110
+ <SCRIPT>print_images()</SCRIPT>
111
+ <FONT size=3 face="Arial, Helvetica, sans-serif" color="#ffffff">
112
+ <SCRIPT>mensaje("MSG_PROCESANDO_TRANSACCION")</SCRIPT>
113
+ </FONT>
114
+ </TD></TR>
115
+ <TR bgcolor="#ffffff"><TD align="center">
116
+ <TABLE width=550 border=0 cellspacing=0 cellpadding=0><TR>
117
+ <TD width=31><IMG src="/images/lock.gif" width=24 height=30></TD>
118
+ <TD width=519>
119
+ <MARQUEE align="middle" behaviour="slide" direction="Left" scrollamount=4 scrolldelay=2 loop=0>
120
+ <FONT face="Arial, Helvetica, sans-serif" size=2>
121
+ <SCRIPT>mensaje("MSG_LOCK")</SCRIPT></MARQUEE>
122
+ </TD>
123
+ </TR></TABLE>
124
+ </TD></TR>
125
+ </TABLE>
126
+ </TD></TR>
127
+ </TABLE>
128
+ <SCRIPT>startclock()</SCRIPT>
129
+ <IMG SRC="images/cblue.jpg" width="1" height="1">
130
+ <IMG SRC="images/cblanco.jpg" width="1" height="1">
131
+ </BODY>
132
+ </HTML>
@@ -0,0 +1,23 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ module Webpay
5
+ mattr_accessor :service_url
6
+ self.service_url = '/webpay/pay'
7
+
8
+ mattr_accessor :cgis_root
9
+ self.cgis_root = 'vendor/webpay'
10
+
11
+ def self.notification(post)
12
+ Notification.new(post)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ require "active_merchant/billing/integrations/webpay/version"
20
+ require "active_merchant/billing/integrations/webpay/helper"
21
+ require "active_merchant/billing/integrations/webpay/notification"
22
+ require "active_merchant/billing/integrations/webpay/middleware"
23
+ require "active_merchant/billing/integrations/webpay/railtie" if defined? Rails
@@ -0,0 +1,25 @@
1
+ require 'active_merchant/billing/integrations/helper'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ module Integrations #:nodoc:
6
+ module Webpay
7
+ class Helper < ActiveMerchant::Billing::Integrations::Helper
8
+ def initialize(*args)
9
+ super
10
+ add_field('TBK_TIPO_TRANSACCION', 'TR_NORMAL')
11
+ end
12
+
13
+ mapping :amount, 'TBK_MONTO'
14
+ mapping :session, 'TBK_ID_SESION'
15
+
16
+ mapping :order, 'TBK_ORDEN_COMPRA'
17
+ mapping :return_url, 'TBK_URL_EXITO'
18
+ mapping :cancel_return_url, 'TBK_URL_FRACASO'
19
+
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,86 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ module Webpay
5
+ class Middleware
6
+ def initialize(app)
7
+ @app = app
8
+ end
9
+
10
+ def call(env)
11
+ case env['PATH_INFO']
12
+ when '/webpay/pay'
13
+ process(env, payment_cgi_path)
14
+ when '/webpay/result'
15
+ process(env, result_cgi_path)
16
+ else
17
+ @app.call env
18
+ end
19
+ end
20
+
21
+ protected
22
+ # Extracted from rack-legacy
23
+ def process(env,cgi_path)
24
+ raise 'Method not allowed' unless env['REQUEST_METHOD'] == 'POST'
25
+
26
+ status = 200
27
+ headers = {}
28
+ body = ''
29
+
30
+ stderr = Tempfile.new 'webpay-cgi-stderr'
31
+ IO.popen('-', 'r+') do |io|
32
+ if io.nil? # Child
33
+ $stderr.reopen stderr.path
34
+ ENV['DOCUMENT_ROOT'] = root_path
35
+ env.each {|k, v| ENV[k] = v if v.respond_to? :to_str}
36
+
37
+ exec ENV, cgi_path
38
+ else # Parent
39
+ io.write(env['rack.input'].read) if env['rack.input']
40
+ io.close_write
41
+ until io.eof? || (line = io.readline.chomp) == ''
42
+ if line =~ /\s*\:\s*/
43
+ key, value = line.split(/\s*\:\s*/, 2)
44
+ if headers.has_key? key
45
+ headers[key] += "\n" + value
46
+ else
47
+ headers[key] = value
48
+ end
49
+ end
50
+ end
51
+ body = io.read
52
+ stderr.rewind
53
+ stderr = stderr.read
54
+ Process.wait
55
+ unless $?.exitstatus == 0
56
+ raise CGIExecutionError
57
+ end
58
+ end
59
+ end
60
+
61
+ status = headers.delete('Status').to_i if headers.has_key? 'Status'
62
+ [status, headers, [body]]
63
+ end
64
+
65
+ def root_path
66
+ ActiveMerchant::Billing::Integrations::Webpay.cgis_root
67
+ end
68
+
69
+ def payment_cgi_path
70
+ root_path + '/tbk_bp_pago.cgi'
71
+ end
72
+
73
+ def result_cgi_path
74
+ root_path + '/tbk_bp_resultado.cgi'
75
+ end
76
+
77
+ def check_cgi_path
78
+ root_path + '/tbk_check_mac.cgi'
79
+ end
80
+
81
+ class CGIExecutionError < Error; end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,116 @@
1
+ require 'active_merchant/billing/integrations/notification'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ module Integrations #:nodoc:
6
+ module Webpay
7
+ class Notification < ActiveMerchant::Billing::Integrations::Notification
8
+ SUCCESS_RESPONSE = 'ACEPTADO'
9
+ FAILURE_RESPONSE = 'RECHAZADO'
10
+ VALID_MAC_RESPONSE = 'CORRECTO'
11
+
12
+ def initialize(raw_post)
13
+ super(CGI.unescape(raw_post))
14
+ end
15
+
16
+ def complete?
17
+ valid?
18
+ end
19
+
20
+ def transaction_id
21
+ params['TBK_ID_TRANSACCION']
22
+ end
23
+
24
+ # When was this payment received by the client.
25
+ def received_at
26
+ Time.new(
27
+ Time.now.year,
28
+ params['TBK_FECHA_TRANSACCION'][0..1].to_i,
29
+ params['TBK_FECHA_TRANSACCION'][2..3].to_i,
30
+ params['TBK_HORA_TRANSACCION'][0..1].to_i,
31
+ params['TBK_HORA_TRANSACCION'][2..3].to_i,
32
+ params['TBK_HORA_TRANSACCION'][4..5].to_i
33
+ )
34
+ end
35
+
36
+ def security_key
37
+ params['TBK_MAC']
38
+ end
39
+
40
+ # the money amount we received in X.2 decimal.
41
+ def gross
42
+ params['TBK_MONTO'][0..-3] + '.' + params['TBK_MONTO'][-2..-1]
43
+ end
44
+
45
+ # Was this a test transaction?
46
+ def test?
47
+ params[''] == 'test'
48
+ end
49
+
50
+ def status
51
+ params['TBK_RESPUESTA']
52
+ end
53
+
54
+ def session_id
55
+ params['TBK_ID_SESION']
56
+ end
57
+
58
+ def card_number
59
+ params['TBK_FINAL_NUMERO_TARJETA']
60
+ end
61
+
62
+ def order_id
63
+ params['TBK_ORDEN_COMPRA']
64
+ end
65
+
66
+ def cancel!
67
+ @valid = false
68
+ end
69
+
70
+ # Check the transaction's validity. This method has to be called after a new
71
+ # apc arrives to verify it using your private key.
72
+ #
73
+ # Example:
74
+ #
75
+ # def notify
76
+ # notify = Webpay::Notification.new(request.raw_post)
77
+ #
78
+ # if notify.valid?
79
+ # ... process order
80
+ # else
81
+ # ... log possible hacking attempt ...
82
+ # end
83
+ #
84
+ # render :text => notify.acknowledge
85
+ # end
86
+ def valid?
87
+ if @valid.nil?
88
+ file = Tempfile.new 'webpay-mac-check'
89
+ file.write raw
90
+ file.close
91
+ executable = Webpay.cgis_root + '/tbk_check_mac.cgi'
92
+ @valid = ( `#{executable} #{file.path}`.strip == VALID_MAC_RESPONSE )
93
+ file.unlink
94
+ end
95
+
96
+ @valid
97
+ end
98
+
99
+ def acknowledge
100
+ valid? ? SUCCESS_RESPONSE : FAILURE_RESPONSE
101
+ end
102
+
103
+ private
104
+ # Take the posted data and move the relevant data into a hash
105
+ def parse(post)
106
+ @raw = post
107
+ for line in post.split('&')
108
+ key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten
109
+ params[key] = value
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end