khipu-rails 0.0.1 → 1.3.0

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.
@@ -0,0 +1,373 @@
1
+ /**
2
+ * Created by Alejandro Vera @ khipu SpA on 2/7/14.
3
+ * Contact at alejandro.vera@khipu.com
4
+ *
5
+ */
6
+ var kh = jQuery.noConflict();
7
+
8
+ KhipuAtmosphere = {}
9
+
10
+ KhipuAtmosphere.statusServer = {
11
+ socket: null,
12
+ subscription: null,
13
+ transport: null,
14
+ onMessageCallback: null,
15
+ subscribe: function (options) {
16
+ var defaults = {
17
+ type: '',
18
+ contentType: 'application/json',
19
+ shared: false,
20
+ transport: 'websocket',
21
+ reconnect: true,
22
+ fallbackTransport: 'long-polling',
23
+ enableProtocol: true,
24
+ trackMessageLength: true
25
+ };
26
+ var statusRequest = kh.extend({}, defaults, options);
27
+ KhipuAtmosphere.statusServer.onMessageCallback = options.onMessageCallback;
28
+ statusRequest.onOpen = function (response) {
29
+ };
30
+ statusRequest.onReconnect = function (request, response) {
31
+ };
32
+ statusRequest.onMessage = function (response) {
33
+ var message = JSON.parse(response.responseBody);
34
+ if (message.lastEvent == 'notified-ok') {
35
+ document.location.href = message.location
36
+ } else if (message.lastEvent == 'automaton-downloaded') {
37
+ KhipuLib.hideWaitAppModal();
38
+ clearTimeout(KhipuLib.verifyKhipuInstalled);
39
+ }
40
+ };
41
+ statusRequest.onError = function (response) {
42
+ };
43
+ statusRequest.onTransportFailure = function (errorMsg, request) {
44
+ };
45
+ statusRequest.onClose = function (response) {
46
+ };
47
+ KhipuAtmosphere.statusServer.subscription = KhipuAtmosphere.statusServer.socket.subscribe(statusRequest);
48
+ },
49
+ unsubscribe: function () {
50
+ KhipuAtmosphere.statusServer.socket.unsubscribe();
51
+ }
52
+ };
53
+
54
+ KhipuSettings = {
55
+ serverUrl: 'https://khipu.com/'
56
+ }
57
+
58
+ KhipuLib = {
59
+ verifyKhipuInstalled: 0,
60
+ isChrome: function () {
61
+ return window.chrome;
62
+ },
63
+ isIE: function () {
64
+ return navigator.appName == 'Microsoft Internet Explorer';
65
+ },
66
+ installUrl: KhipuSettings.serverUrl + 'installer/tryInstalled',
67
+ isMobile: function () {
68
+ return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Mini/i.test(navigator.userAgent);
69
+ },
70
+ isInstalled: function () {
71
+ if (window.chrome) {
72
+ return document.querySelector('div#extension-kmmojbkhfhninkelnlcnliacgncnnikf-installed') != null;
73
+ }
74
+ if (KhipuLib.isIE()) {
75
+ var wrapper = document.createElement('div');
76
+ wrapper.id = 'khipu-plugin-wrapper';
77
+ document.documentElement.appendChild(wrapper);
78
+ document.getElementById('khipu-plugin-wrapper').innerHTML = '<object id="khPlugin" type="application/x-KHPlugin" width="0" height="0"><param name="onload" value="pluginLoaded"/></object>';
79
+ navigator.plugins.refresh(false);
80
+ } else {
81
+ navigator.plugins.refresh(false);
82
+ var emb = document.createElement('embed');
83
+ emb.id = 'khPlugin';
84
+ emb.type = 'application/x-KHPlugin';
85
+ emb.width = 0;
86
+ emb.height = 0;
87
+ document.documentElement.appendChild(emb);
88
+ navigator.plugins.refresh(false);
89
+ }
90
+ var khPlugin = document.getElementById('khPlugin');
91
+ return khPlugin != null && khPlugin.callKH != undefined && khPlugin.callKH != null;
92
+ },
93
+ options: { },
94
+ onLoad: function (params) {
95
+ if (document.getElementById('khipu-chrome-extension-div') != null) {
96
+ document.getElementById('khipu-chrome-extension-div').style.display = 'none';
97
+ }
98
+ for (var property in params) {
99
+ if (params.hasOwnProperty(property)) {
100
+ KhipuLib.options[property] = params[property];
101
+ }
102
+ }
103
+ if (KhipuLib.isMobile()) {
104
+ KhipuLib.defaultMobile();
105
+ return;
106
+ }
107
+
108
+ var isInstalled = KhipuLib.isInstalled();
109
+ if (isInstalled) {
110
+ KhipuAtmosphere.statusServer.socket = atmosphere;
111
+ KhipuAtmosphere.statusServer.subscribe({url: KhipuSettings.serverUrl + 'atm/payment/status/' + KhipuLib.options.paymentId});
112
+ if (KhipuLib.options.onSuccess != null) {
113
+ KhipuLib.options.onSuccess();
114
+ } else {
115
+ KhipuLib.defaultOnSuccess();
116
+ }
117
+ } else {
118
+ if (KhipuLib.options.onNotInstalled) {
119
+ KhipuLib.options.onNotInstalled(KhipuLib.installUrl + '/' + KhipuLib.options.paymentId + '?returnUrl=' + encodeURIComponent(KhipuLib.options.returnUrl));
120
+ } else {
121
+ KhipuLib.defaultOnNotInstalled();
122
+ }
123
+ }
124
+ return isInstalled;
125
+ },
126
+ defaultMobile: function () {
127
+ if (KhipuLib.options.elementId != null) {
128
+ var element = kh('#' + KhipuLib.options.elementId);
129
+ element.click(function () {
130
+ document.location.href = KhipuSettings.serverUrl + 'payment/show/' + KhipuLib.options.paymentId;
131
+ });
132
+ element.prop('disabled', false);
133
+ }
134
+ },
135
+ defaultOnNotInstalled: function () {
136
+ if (KhipuLib.options.elementId != null) {
137
+ var element = kh('#' + KhipuLib.options.elementId);
138
+ element.click(function () {
139
+ KhipuLib.showNotInstalledModal();
140
+ });
141
+ element.prop('disabled', false);
142
+ }
143
+ },
144
+ goToKhipu: function () {
145
+ document.location.href = KhipuLib.installUrl + '/' + KhipuLib.options.paymentId + '?returnUrl=' + encodeURIComponent(KhipuLib.options.returnUrl);
146
+ },
147
+ showWaitAppModal: function () {
148
+ KhipuLib.showModal({
149
+ html: 'Espere mientras se levanta el terminal del pagos khipu...',
150
+ okCallBack: KhipuLib.goToKhipu,
151
+ height: 100,
152
+ width: 460,
153
+ classes: 'khipu-wait-app-modal',
154
+ closeOnClick: false
155
+ });
156
+ },
157
+ showNotInstalledModal: function () {
158
+ KhipuLib.showModal({
159
+ html: '<iframe width="100%" height="345px" scrolling="no" frameBorder="0" src="https://khipu.com/page/instalar-en-khipu?layout=minimal"></iframe>',
160
+ okLabel: 'Ir a instalar khipu',
161
+ okCallBack: KhipuLib.goToKhipu,
162
+ height: 450,
163
+ width: 600
164
+ });
165
+ },
166
+ hideWaitAppModal: function () {
167
+ kh('.khipu-wait-app-modal').remove();
168
+ kh('.khipu-wait-app-modal-overlay').remove();
169
+ },
170
+ appNotInstalled: function () {
171
+ KhipuLib.hideWaitAppModal();
172
+ KhipuLib.showModal({
173
+ html: '<iframe width="100%" height="345px" scrolling="no" frameBorder="0" src="https://khipu.com/page/instalar-en-khipu?layout=minimal"></iframe>',
174
+ okLabel: 'Ir a instalar khipu',
175
+ okCallBack: KhipuLib.goToKhipu,
176
+ height: 450,
177
+ width: 600
178
+ });
179
+ },
180
+ showModal: function (options) {
181
+ var modalName = 'khipu-modal-window-' + KhipuLib.makeId();
182
+ kh('head').append('<style>.khipu-clearfix:after { content: " "; visibility: hidden; display: block; height: 0; clear: both;}</style>');
183
+ var overlay = document.createElement('div');
184
+ overlay.id = modalName + 'overlay';
185
+ kh(overlay).css({width: '100%', height: '100%', top: 0, left: 0, position: 'fixed', 'opacity': '0.8', 'background-color': '#000000', 'z-index': 500});
186
+ var closeOnClick = typeof options.closeOnClick == 'undefined' ? true : options.closeOnClick;
187
+ if (closeOnClick) {
188
+ kh(overlay).click(function () {
189
+ KhipuLib.closeModal(modalName);
190
+ });
191
+ }
192
+ document.body.appendChild(overlay);
193
+ var modal = document.createElement('div');
194
+ modal.id = modalName;
195
+ if (options.classes) {
196
+ kh(modal).addClass(options.classes);
197
+ kh(overlay).addClass(options.classes + '-overlay');
198
+ }
199
+ kh(modal).css({'display': 'none',
200
+ 'width': options.width + 'px',
201
+ 'height': options.height + 'px',
202
+ 'background-color': '#ffffff',
203
+ 'position': 'fixed',
204
+ 'z-index': 10000,
205
+ 'left': Math.max(0, ((kh(window).width() - options.width) / 2) + kh(window).scrollLeft()) + "px",
206
+ 'top': Math.max(0, ((kh(window).height() - options.height) / 2) + kh(window).scrollTop()) + "px",
207
+ 'border-radius': '5px',
208
+ 'box-shadow': '0px 0px 4px rgba(0,0,0,0.7)',
209
+ 'color': '#333333',
210
+ 'padding': '0'
211
+ });
212
+
213
+ var modalWrapper = document.createElement('div');
214
+ kh(modalWrapper).css({'padding': '30px'});
215
+ modal.appendChild(modalWrapper);
216
+
217
+ document.body.appendChild(modal);
218
+
219
+ var contentWrapper = document.createElement('div');
220
+ kh(contentWrapper).html(options.html);
221
+ modalWrapper.appendChild(contentWrapper);
222
+
223
+ if (options.okLabel) {
224
+ var button = document.createElement('button');
225
+ kh(button).text(options.okLabel);
226
+ if (options.okCallBack) {
227
+ kh(button).click(options.okCallBack);
228
+ }
229
+ kh(button).css({
230
+ 'background': 'transparent',
231
+ 'background-color': '#3c2c70',
232
+ 'border-color': '#32255e',
233
+ 'display': 'inline-block',
234
+ 'float': 'right',
235
+ 'border': 'none',
236
+ 'width': 'auto',
237
+ 'overflow': 'visible',
238
+ 'color': '#FFF',
239
+ 'padding': '6px 12px',
240
+ 'border-radius': '4px',
241
+ '-webkit-border-radius': '4px',
242
+ '-moz-border-radius': '4px',
243
+ 'font-weight': 'normal',
244
+ 'font-size': '14px',
245
+ 'line-height': '1.428571429',
246
+ 'text-align': 'center',
247
+ 'text-decoration': 'none',
248
+ 'cursor': 'pointer',
249
+ 'text-shadow': '0 1px 0 rgba(0,0,0,0.4)',
250
+ 'vertical-align': ' middle',
251
+ 'background-image': ' none',
252
+ 'font-family': ' "Helvetica Neue",Helvetica,Arial,sans-serif',
253
+ '-webkit-user-select': ' none',
254
+ '-moz-user-select': ' none',
255
+ '-ms-user-select': ' none',
256
+ '-o-user-select': ' none',
257
+ 'margin': '0 5px 10px'
258
+ });
259
+
260
+ var closeLink = document.createElement('a');
261
+ kh(closeLink).html('Cerrar');
262
+ kh(closeLink).click(function () {
263
+ KhipuLib.closeModal(modalName);
264
+ });
265
+ kh(closeLink).attr('href', 'javascript:void(0)');
266
+ var buttons = document.createElement('div');
267
+ buttons.id = 'buttons-wrapper';
268
+ kh(buttons).addClass('khipu-clearfix');
269
+ kh(buttons).css({'font-family': '"Helvetica Neue", "Helvetica", "Arial", "sans-serif"'})
270
+ buttons.appendChild(button);
271
+ buttons.appendChild(closeLink);
272
+
273
+ modalWrapper.appendChild(buttons);
274
+ }
275
+
276
+ kh('#' + modalName + ' iframe').css('overflow', 'hidden');
277
+ kh('#' + modalName + ' .modal-header h2').css({
278
+ 'background-color': '#e3e3e3',
279
+ 'color': '#444',
280
+ 'font-size': '2em',
281
+ 'font-weight': '700',
282
+ 'margin': '3px',
283
+ 'text-shadow': '1px 1px 0'
284
+ });
285
+ if (options.okLabel) {
286
+ kh(buttons).css({
287
+ width: '100%',
288
+ 'margin-top': '10px',
289
+ 'height': '50px'
290
+ });
291
+ kh(closeLink).css({
292
+ 'margin-right': '10px',
293
+ 'background-color': 'transparent',
294
+ 'background': 'transparent',
295
+ 'background-image': 'none',
296
+ 'border-radius': '0',
297
+ 'border': '1px solid transparent',
298
+ 'box-shadow': 'none',
299
+ 'color': '#2cbbe8',
300
+ 'cursor': 'pointer',
301
+ 'display': 'inline-block',
302
+ 'float': 'right',
303
+ 'font-family': ' "Helvetica Neue",Helvetica,Arial,sans-serif',
304
+ 'font-size': '14px',
305
+ 'font-weight': 'normal',
306
+ 'line-height': '1.428571429',
307
+ 'margin-bottom': '0',
308
+ 'padding': '6px 12px',
309
+ 'text-align': 'center',
310
+ 'text-decoration': 'none',
311
+ 'text-shadow': 'none',
312
+ 'user-select': 'none',
313
+ 'white-space': 'nowrap',
314
+ 'vertical-align': 'middle',
315
+ '-moz-user-select': 'none',
316
+ '-ms-user-select': 'none',
317
+ '-o-user-select': 'none',
318
+ '-webkit-box-shadow': 'none',
319
+ '-webkit-user-select': 'none'
320
+ });
321
+ }
322
+ kh(overlay).fadeIn();
323
+ kh(modal).fadeIn();
324
+
325
+ },
326
+ closeModal: function (modalName) {
327
+ kh('#' + modalName + 'overlay').fadeOut("fast", function () {
328
+ kh('#' + modalName + 'overlay').remove()
329
+ });
330
+ kh('#' + modalName).fadeOut("fast", function () {
331
+ kh('#' + modalName).remove()
332
+ });
333
+ },
334
+ defaultOnSuccess: function () {
335
+ if (KhipuLib.options.elementId != null) {
336
+ var element = document.getElementById(KhipuLib.options.elementId);
337
+ if (element != null) {
338
+ var paymentId = KhipuLib.options.paymentId;
339
+ element.onclick = function () {
340
+ KhipuLib.startKhipu(paymentId);
341
+ };
342
+ if (element.disabled) {
343
+ element.disabled = false;
344
+ }
345
+ }
346
+ }
347
+ },
348
+ startKhipu: function (paymentId) {
349
+ if (KhipuLib.isChrome()) {
350
+ KhipuLib.sendEvent('startKhipuEvent', paymentId + '|' + false)
351
+ KhipuLib.showWaitAppModal();
352
+ KhipuLib.verifyKhipuInstalled = setTimeout(KhipuLib.appNotInstalled, 10000);
353
+ } else {
354
+ var khPlugin = document.getElementById('khPlugin');
355
+ khPlugin.callKH(KhipuSettings.serverUrl + 'payment/getPaymentData/' + paymentId)
356
+ }
357
+ },
358
+ sendEvent: function (type, data) {
359
+ var event = document.createEvent('Event');
360
+ event.initEvent(type, true, true);
361
+ var eventDiv = document.getElementById('khipu-chrome-extension-div');
362
+ eventDiv.innerText = data;
363
+ eventDiv.dispatchEvent(event);
364
+ },
365
+ makeId: function () {
366
+ var ret = '';
367
+ var pallete = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
368
+ for (var i = 0; i < 10; i++) {
369
+ ret += pallete.charAt(Math.floor(Math.random() * pallete.length));
370
+ }
371
+ return ret;
372
+ }
373
+ };
metadata CHANGED
@@ -1,128 +1,164 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: khipu-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 1.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Klaus Hott Vidal
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-01-21 00:00:00.000000000 Z
11
+ date: 2014-04-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rails
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 3.1.10
19
+ version: '3.1'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 3.1.10
26
+ version: '3.1'
30
27
  - !ruby/object:Gem::Dependency
31
- name: rspec-rails
28
+ name: jquery-rails
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
- type: :development
34
+ type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: nokogiri
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httpclient
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
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: rspec-rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
52
74
  - !ruby/object:Gem::Version
53
75
  version: '0'
54
76
  type: :development
55
77
  prerelease: false
56
78
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
79
  requirements:
59
- - - ! '>='
80
+ - - ">="
60
81
  - !ruby/object:Gem::Version
61
82
  version: '0'
62
83
  - !ruby/object:Gem::Dependency
63
84
  name: capybara
64
85
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
86
  requirements:
67
- - - ~>
87
+ - - "~>"
68
88
  - !ruby/object:Gem::Version
69
89
  version: 1.1.2
70
90
  type: :development
71
91
  prerelease: false
72
92
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
93
  requirements:
75
- - - ~>
94
+ - - "~>"
76
95
  - !ruby/object:Gem::Version
77
96
  version: 1.1.2
78
- description: This gem provides a rails wrapper for the khipu api.
97
+ description: This gem provides an ActionView helper that creates a form following
98
+ Khipu's documentation.
79
99
  email:
80
100
  - klahott@gmail.com
81
101
  executables: []
82
102
  extensions: []
83
103
  extra_rdoc_files: []
84
104
  files:
85
- - .gitignore
86
- - .rspec
105
+ - ".gitignore"
106
+ - ".rspec"
87
107
  - CHANGELOG.md
88
108
  - Gemfile
89
109
  - LICENSE.txt
90
110
  - README.md
91
111
  - Rakefile
112
+ - app/controllers/khipu_rails/application_controller.rb
113
+ - app/controllers/khipu_rails/khipu_controller.rb
114
+ - app/views/khipu_rails/khipu/notification.html
115
+ - app/views/layouts/khipu_rails/application.html.erb
116
+ - config/khipu.pem.cer
117
+ - config/khipu_dev.pem.cer
118
+ - config/routes.rb
92
119
  - khipu-rails.gemspec
93
120
  - lib/khipu-rails.rb
94
121
  - lib/khipu_rails.rb
95
122
  - lib/khipu_rails/button_helper.rb
96
123
  - lib/khipu_rails/config.rb
124
+ - lib/khipu_rails/notification_validator.rb
125
+ - lib/khipu_rails/receiver.rb
97
126
  - lib/khipu_rails/version.rb
98
- - spec/khipu_rails/khipu_helpers_spec.rb
127
+ - spec/khipu_rails/button_helper_spec.rb
128
+ - spec/khipu_rails/config_spec.rb
129
+ - spec/khipu_rails/notification_validator_spec.rb
130
+ - spec/khipu_rails/receiver_spec.rb
99
131
  - spec/khipu_rails_spec.rb
100
132
  - spec/spec_helper.rb
133
+ - vendor/assets/javascripts/atmosphere.js
134
+ - vendor/assets/javascripts/khipu.js
101
135
  homepage: https://github.com/janther/khipu-rails
102
136
  licenses: []
137
+ metadata: {}
103
138
  post_install_message:
104
139
  rdoc_options: []
105
140
  require_paths:
106
141
  - lib
107
142
  required_ruby_version: !ruby/object:Gem::Requirement
108
- none: false
109
143
  requirements:
110
- - - ! '>='
144
+ - - ">="
111
145
  - !ruby/object:Gem::Version
112
146
  version: '0'
113
147
  required_rubygems_version: !ruby/object:Gem::Requirement
114
- none: false
115
148
  requirements:
116
- - - ! '>='
149
+ - - ">="
117
150
  - !ruby/object:Gem::Version
118
151
  version: '0'
119
152
  requirements: []
120
153
  rubyforge_project:
121
- rubygems_version: 1.8.24
154
+ rubygems_version: 2.2.2
122
155
  signing_key:
123
- specification_version: 3
124
- summary: This gem provides a rails wrapper for the khipu api.
156
+ specification_version: 4
157
+ summary: Wrapper for the Khipu api.
125
158
  test_files:
126
- - spec/khipu_rails/khipu_helpers_spec.rb
159
+ - spec/khipu_rails/button_helper_spec.rb
160
+ - spec/khipu_rails/config_spec.rb
161
+ - spec/khipu_rails/notification_validator_spec.rb
162
+ - spec/khipu_rails/receiver_spec.rb
127
163
  - spec/khipu_rails_spec.rb
128
164
  - spec/spec_helper.rb