CyoGate_17x - Version 1.7.0.1

Version Notes

Last updated on 03/01/2014

Download this release

Release Info

Developer CyoGate Merchant Solutions
Extension CyoGate_17x
Version 1.7.0.1
Comparing to
See all releases


Version 1.7.0.1

Files changed (2) hide show
  1. js/mage/threestep.js +399 -0
  2. package.xml +18 -0
js/mage/threestep.js ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ var threeStep = Class.create();
3
+ threeStep.prototype = {
4
+ initialize : function(methodCode, iframeId, controller, orderSaveUrl,
5
+ cgiUrl, nativeAction) {
6
+ this.iframeId = iframeId;
7
+ this.controller = controller;
8
+ this.orderSaveUrl = orderSaveUrl;
9
+ this.nativeAction = nativeAction;
10
+ this.cgiUrl = cgiUrl;
11
+ this.code = methodCode;
12
+ this.inputs = ['cc_type', 'cc_number', 'expiration', 'expiration_yr', 'cc_cid'];
13
+ this.headers = [];
14
+ this.isValid = true;
15
+ this.paymentRequestSent = false;
16
+ this.isResponse = false;
17
+ this.orderIncrementId = false;
18
+ this.successUrl = false;
19
+ this.hasError = false;
20
+ this.tmpForm = false;
21
+
22
+ this.onSaveOnepageOrderSuccess = this.saveOnepageOrderSuccess.bindAsEventListener(this);
23
+ this.onLoadIframe = this.loadIframe.bindAsEventListener(this);
24
+ this.onLoadOrderIframe = this.loadOrderIframe.bindAsEventListener(this);
25
+ this.onSubmitAdminOrder = this.submitAdminOrder.bindAsEventListener(this);
26
+ this.preparePayment();
27
+ },
28
+
29
+ validate : function() {
30
+ this.isValid = true;
31
+ this.inputs.each(function(elemIndex) {
32
+ if ($(this.code + '_' + elemIndex)) {
33
+ if (!Validation.validate($(this.code + '_' + elemIndex))) {
34
+ this.isValid = false;
35
+ }
36
+ }
37
+ }, this);
38
+
39
+ return this.isValid;
40
+ },
41
+
42
+ changeInputOptions : function(param, value) {
43
+ this.inputs.each(function(elemIndex) {
44
+ if ($(this.code + '_' + elemIndex)) {
45
+ $(this.code + '_' + elemIndex).writeAttribute(param, value);
46
+ }
47
+ }, this);
48
+ },
49
+
50
+ preparePayment : function() {
51
+ this.changeInputOptions('autocomplete', 'off');
52
+ if ($(this.iframeId)) {
53
+ switch (this.controller) {
54
+ case 'onepage':
55
+ this.headers = $$('#' + checkout.accordion.container.readAttribute('id') + ' .section');
56
+ var button = $('review-buttons-container').down('button');
57
+ button.writeAttribute('onclick', '');
58
+ button.stopObserving('click');
59
+ button.observe('click', function() {
60
+ if ($(this.iframeId)) {
61
+ if (this.validate()) {
62
+ this.saveOnepageOrder();
63
+ }
64
+ } else {
65
+ review.save();
66
+ }
67
+ }.bind(this));
68
+ break;
69
+ case 'sales_order_create':
70
+ case 'sales_order_edit':
71
+ var buttons = document.getElementsByClassName('scalable save');
72
+ for ( var i = 0; i < buttons.length; i++) {
73
+ buttons[i].writeAttribute('onclick', '');
74
+ buttons[i].observe('click', this.onSubmitAdminOrder);
75
+ }
76
+ $('order-' + this.iframeId).observe('load', this.onLoadOrderIframe);
77
+ break;
78
+ }
79
+ $(this.iframeId).observe('load', this.onLoadIframe);
80
+ }
81
+ },
82
+
83
+ loadIframe : function() {
84
+ if (this.paymentRequestSent) {
85
+ switch (this.controller) {
86
+ case 'onepage':
87
+ this.paymentRequestSent = false;
88
+ if (!this.hasError) {
89
+ this.returnQuote();
90
+ }
91
+ break;
92
+ case 'sales_order_edit':
93
+ case 'sales_order_create':
94
+ if (!this.orderRequestSent) {
95
+ this.paymentRequestSent = false;
96
+ if (!this.hasError) {
97
+ this.returnQuote();
98
+ } else {
99
+ this.changeInputOptions('disabled', false);
100
+ toggleSelectsUnderBlock($('loading-mask'), true);
101
+ $('loading-mask').hide();
102
+ enableElements('save');
103
+ }
104
+ }
105
+ break;
106
+ }
107
+ if (this.tmpForm) {
108
+ document.body.removeChild(this.tmpForm);
109
+ }
110
+ if (!this.hasError) {
111
+ $('co-threestep-form').style.visibility="hidden";
112
+ var parent = document.getElementById('review-buttons-container');
113
+ var ele = parent.getElementsByTagName('button')[0];
114
+ ele.style.visibility="hidden";
115
+ }
116
+ }
117
+ },
118
+
119
+ loadOrderIframe : function() {
120
+ if (this.orderRequestSent) {
121
+ $(this.iframeId).hide();
122
+ var data = $('order-' + this.iframeId).contentWindow.document.body.innerHTML;
123
+ this.saveAdminOrderSuccess(data);
124
+ this.orderRequestSent = false;
125
+ }
126
+ },
127
+
128
+ showError : function(msg) {
129
+ this.hasError = true;
130
+ if (this.controller == 'onepage') {
131
+ $(this.iframeId).hide();
132
+ this.resetLoadWaiting();
133
+ }
134
+ alert(msg);
135
+ $('co-threestep-form').style.visibility="visible";
136
+ var parent = document.getElementById('review-buttons-container');
137
+ var ele = parent.getElementsByTagName('button')[0];
138
+ ele.style.visibility="visible";
139
+ },
140
+
141
+ returnQuote : function() {
142
+ var url = this.orderSaveUrl.replace('place', 'returnQuote');
143
+ new Ajax.Request(url, {
144
+ onSuccess : function(transport) {
145
+ try {
146
+ response = eval('(' + transport.responseText + ')');
147
+ } catch (e) {
148
+ response = {};
149
+ }
150
+ if (response.error_message) {
151
+ alert(response.error_message);
152
+ this.setLoadWaiting();}
153
+ $(this.iframeId).show();
154
+ switch (this.controller) {
155
+ case 'onepage':
156
+ this.resetLoadWaiting();
157
+ break;
158
+ case 'sales_order_edit':
159
+ case 'sales_order_create':
160
+ this.changeInputOptions('disabled', false);
161
+ toggleSelectsUnderBlock($('loading-mask'), true);
162
+ $('loading-mask').hide();
163
+ enableElements('save');
164
+ break;
165
+ }
166
+ }.bind(this)
167
+ });
168
+ },
169
+
170
+ setLoadWaiting : function() {
171
+ this.headers.each(function(header) {
172
+ header.removeClassName('allow');
173
+ });
174
+ checkout.setLoadWaiting('review');
175
+ },
176
+
177
+ resetLoadWaiting : function() {
178
+ this.headers.each(function(header) {
179
+ header.addClassName('allow');
180
+ });
181
+ checkout.setLoadWaiting(false);
182
+ },
183
+
184
+ saveOnepageOrder : function() {
185
+ this.hasError = false;
186
+ this.setLoadWaiting();
187
+ var params = Form.serialize(payment.form);
188
+ if (review.agreementsForm) {
189
+ params += '&' + Form.serialize(review.agreementsForm);
190
+ }
191
+ params += '&controller=' + this.controller;
192
+ new Ajax.Request(this.orderSaveUrl, {
193
+ method : 'post',
194
+ parameters : params,
195
+ onComplete : this.onSaveOnepageOrderSuccess,
196
+ onFailure : function(transport) {
197
+ this.resetLoadWaiting();
198
+ if (transport.status == 403) {
199
+ checkout.ajaxFailure();
200
+ }
201
+ }
202
+ });
203
+ },
204
+
205
+ saveOnepageOrderSuccess : function(transport) {
206
+ if (transport.status == 403) {
207
+ checkout.ajaxFailure();
208
+ }
209
+ try {
210
+ response = eval('(' + transport.responseText + ')');
211
+ } catch (e) {
212
+ response = {};
213
+ }
214
+
215
+ this.cgiUrl = response.formUrl[0];
216
+
217
+ if (response.success && response.threestep) {
218
+ this.orderIncrementId = response.threestep.fields.order_id;
219
+ var paymentData = {};
220
+ var preparedData = this.preparePaymentRequest(paymentData);
221
+ this.sendPaymentRequest(preparedData);
222
+ } else {
223
+ var msg = response.error_messages;
224
+ if (typeof (msg) == 'object') {
225
+ msg = msg.join("\n");
226
+ }
227
+ if (msg) {
228
+ alert(msg);
229
+ }
230
+
231
+ if (response.update_section) {
232
+ $('checkout-' + response.update_section.name + '-load').update(response.update_section.html);
233
+ response.update_section.html.evalScripts();
234
+ }
235
+
236
+ if (response.goto_section) {
237
+ checkout.gotoSection(response.goto_section);
238
+ checkout.reloadProgressBlock();
239
+ }
240
+ }
241
+ },
242
+
243
+ submitAdminOrder : function() {
244
+ if (editForm.validate()) {
245
+ var paymentMethodEl = $(editForm.formId).getInputs('radio','payment[method]').find(function(radio) {
246
+ return radio.checked;
247
+ });
248
+ this.hasError = false;
249
+ if (paymentMethodEl.value == this.code) {
250
+ toggleSelectsUnderBlock($('loading-mask'), false);
251
+ $('loading-mask').show();
252
+ setLoaderPosition();
253
+ this.changeInputOptions('disabled', 'disabled');
254
+ this.paymentRequestSent = true;
255
+ this.orderRequestSent = true;
256
+ $(editForm.formId).writeAttribute('action', this.orderSaveUrl);
257
+ $(editForm.formId).writeAttribute('target',
258
+ $('order-' + this.iframeId).readAttribute('name'));
259
+ $(editForm.formId).appendChild(this.createHiddenElement('controller', this.controller));
260
+ disableElements('save');
261
+ $(editForm.formId).submit();
262
+ } else {
263
+ $(editForm.formId).writeAttribute('action', this.nativeAction);
264
+ $(editForm.formId).writeAttribute('target', '_top');
265
+ disableElements('save');
266
+ $(editForm.formId).submit();
267
+ }
268
+ }
269
+ },
270
+
271
+ recollectQuote : function() {
272
+ var area = [ 'sidebar', 'items', 'shipping_method', 'billing_method', 'totals', 'giftmessage' ];
273
+ area = order.prepareArea(area);
274
+ var url = order.loadBaseUrl + 'block/' + area;
275
+ var info = $('order-items_grid').select('input', 'select', 'textarea');
276
+ var data = {};
277
+ for ( var i = 0; i < info.length; i++) {
278
+ if (!info[i].disabled && (info[i].type != 'checkbox' || info[i].checked)) {
279
+ data[info[i].name] = info[i].getValue();
280
+ }
281
+ }
282
+ data.reset_shipping = true;
283
+ data.update_items = true;
284
+ if ($('coupons:code') && $F('coupons:code')) {
285
+ data['order[coupon][code]'] = $F('coupons:code');
286
+ }
287
+ data.json = true;
288
+ new Ajax.Request(url, {
289
+ parameters : data,
290
+ loaderArea : 'html-body',
291
+ onSuccess : function(transport) {
292
+ $(editForm.formId).submit();
293
+ }.bind(this)
294
+ });
295
+
296
+ },
297
+
298
+ saveAdminOrderSuccess : function(data) {
299
+ try {
300
+ response = eval('(' + data + ')');
301
+ } catch (e) {
302
+ response = {};
303
+ }
304
+
305
+ this.cgiUrl = response.formUrl[0];
306
+
307
+ if (response.threestep) {
308
+ this.orderIncrementId = response.threestep.fields.order_id;
309
+ var paymentData = {};
310
+ var preparedData = this.preparePaymentRequest(paymentData);
311
+
312
+ this.sendPaymentRequest(preparedData);
313
+ } else {
314
+ if (response.redirect) {
315
+ window.location = response.redirect;
316
+ }
317
+ if (response.error_messages) {
318
+ var msg = response.error_messages;
319
+ if (typeof (msg) == 'object') {
320
+ msg = msg.join("\n");
321
+ }
322
+ if (msg) {
323
+ alert(msg);
324
+ }
325
+ }
326
+ }
327
+ },
328
+
329
+ preparePaymentRequest : function(data) {
330
+ if ($(this.code + '_cc_cid')) {
331
+ data['billing-cvv'] = $(this.code + '_cc_cid').value;
332
+ }
333
+ var year = $(this.code + '_expiration_yr').value;
334
+ if (year.length > 2) {
335
+ year = year.substring(2);
336
+ }
337
+ var month = parseInt($(this.code + '_expiration').value, 10);
338
+ if (month < 10) {
339
+ month = '0' + month;
340
+ }
341
+
342
+ data['billing-cc-exp'] = month + year;
343
+
344
+ data['billing-cc-number'] = $(this.code + '_cc_number').value;
345
+
346
+ return data;
347
+ },
348
+
349
+ sendPaymentRequest : function(preparedData) {
350
+ this.recreateIframe();
351
+ this.tmpForm = document.createElement('form');
352
+ this.tmpForm.style.display = 'none';
353
+ this.tmpForm.enctype = 'application/x-www-form-urlencoded';
354
+ this.tmpForm.method = 'POST';
355
+ document.body.appendChild(this.tmpForm);
356
+ this.tmpForm.action = this.cgiUrl;
357
+ this.tmpForm.target = $(this.iframeId).readAttribute('name');
358
+ this.tmpForm.setAttribute('target', $(this.iframeId).readAttribute('name'));
359
+
360
+ for ( var param in preparedData) {
361
+ this.tmpForm.appendChild(this.createHiddenElement(param, preparedData[param]));
362
+ }
363
+
364
+ this.paymentRequestSent = true;
365
+ this.tmpForm.submit();
366
+ },
367
+
368
+ createHiddenElement : function(name, value) {
369
+ var field;
370
+ if (isIE) {
371
+ field = document.createElement('input');
372
+ field.setAttribute('type', 'hidden');
373
+ field.setAttribute('name', name);
374
+ field.setAttribute('value', value);
375
+ } else {
376
+ field = document.createElement('input');
377
+ field.type = 'hidden';
378
+ field.name = name;
379
+ field.value = value;
380
+ }
381
+
382
+ return field;
383
+ },
384
+
385
+ recreateIframe : function() {
386
+ if ($(this.iframeId)) {
387
+ var nextElement = $(this.iframeId).next();
388
+ var src = $(this.iframeId).readAttribute('src');
389
+ var name = $(this.iframeId).readAttribute('name');
390
+ $(this.iframeId).stopObserving();
391
+ $(this.iframeId).remove();
392
+ var iframe = '<iframe id="' + this.iframeId +
393
+ '" allowtransparency="true" frameborder="0" name="' + name +
394
+ '" style="display:none;height:375px;width:100%;background-color:transparent" src="' + src + '" />';
395
+ Element.insert(nextElement, {'before':iframe});
396
+ $(this.iframeId).observe('load', this.onLoadIframe);
397
+ }
398
+ }
399
+ };
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>CyoGate_17x</name>
4
+ <version>1.7.0.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This payment module enables processing of Credit Card transactions using the CyoGate Payment Gateway.</summary>
10
+ <description>This payment module enables the processing of Credit Card transactions through Magento v1.7.x using the CyoGate Payment Gateway. It uses the CyoGate "Three Step Redirect" API and is not compatible with One-Step-Checkout</description>
11
+ <notes>Last updated on 03/01/2014</notes>
12
+ <authors><author><name>CyoGate Merchant Solutions</name><user>cyberoptic</user><email>jon@cyop.net</email></author></authors>
13
+ <date>2014-03-01</date>
14
+ <time>15:51:41</time>
15
+ <contents><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="threestep.xml" hash=""/></dir></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="threestep.xml" hash=""/></dir></dir></dir><dir name="default"><dir name="default"><dir name="template"><dir name="threestep"><dir name="payment"><file name="form.phtml" hash=""/><file name="iframe.phtml" hash=""/><file name="info.phtml" hash=""/></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="GatewayProcessingServices_ThreeStep.xml" hash=""/></dir></target><target name="mageweb"><dir name="js"><dir name="mage"><file name="threestep.js" hash=""/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>5.5.9</max></php></required></dependencies>
18
+ </package>