Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove prototype package dependency #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions Class.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Extracted from Prototype.js's Class implementation
// See: https://github.com/Rixius/prototype.node.js
var Class;

function extend(destination, source) {
for (var property in source)
destination[property] = source[property];
return destination;
}

function isFunction(object) {
return Object.prototype.toString.call(object) === '[object Function]';
}

function wrapFunction(fn, wrapper) {
var __method = fn;
return function() {
var a = update([__method.bind(this)], arguments);
return wrapper.apply(this, a);
}
}

function updateArguments(array, args) {
var arrayLength = array.length, length = args.length;
while (length--) array[arrayLength + length] = args[length];
return array;
}

function wrap(method, wrapper) {
return function() {
var a = updateArguments([method.bind(this)], arguments);
return wrapper.apply(this, a);
}
}

function emptyFunction() {}

function argumentNames(fn) {
var names = fn.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1]
.replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g, '')
.replace(/\s+/g, '').split(',');
return names.length == 1 && !names[0] ? [] : names;
}

var IS_DONTENUM_BUGGY = (function(){
for (var p in { toString: 1 }) {
if (p === 'toString') return false;
}
return true;
})();

function subclass() {};

function create() {
var parent = null, properties = [].slice.call(arguments);
if (isFunction(properties[0]))
parent = properties.shift();

function klass() {
this.initialize.apply(this, arguments);
}

extend(klass, Class.Methods);
klass.superclass = parent;
klass.subclasses = [];

if (parent) {
subclass.prototype = parent.prototype;
klass.prototype = new subclass;
parent.subclasses.push(klass);
}

for (var i = 0, length = properties.length; i < length; i++)
klass.addMethods(properties[i]);

if (!klass.prototype.initialize)
klass.prototype.initialize = emptyFunction;

klass.prototype.constructor = klass;
return klass;
}

function addMethods(source) {
var ancestor = this.superclass && this.superclass.prototype,
properties = Object.keys(source);

if (IS_DONTENUM_BUGGY) {
if (source.toString != Object.prototype.toString)
properties.push("toString");
if (source.valueOf != Object.prototype.valueOf)
properties.push("valueOf");
}

for (var i = 0, length = properties.length; i < length; i++) {
var property = properties[i], value = source[property];
if (ancestor && isFunction(value) &&
argumentNames(value)[0] == "$super") {
var method = value;
value = wrap(
(function(m) {
return function() { return ancestor[m].apply(this, arguments); };
})(property),
method
);

value.valueOf = method.valueOf.bind(method);
value.toString = method.toString.bind(method);
}
this.prototype[property] = value;
}

return this;
}

module.exports = Class = {
create: create,
Methods: {
addMethods: addMethods
}
};
2 changes: 1 addition & 1 deletion CloverConnectorFactory.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("prototype");
var Class = require("./Class.js");

var CloverConnectorImpl = require("./CloverConnectorImpl.js");

Expand Down
3 changes: 1 addition & 2 deletions CloverConnectorImpl.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("prototype");
var Class = require("./Class.js");

var log = require('./Logger.js').create();

Expand Down Expand Up @@ -1831,4 +1831,3 @@ if ('undefined' !== typeof module) {
* @property {string} host
* @property {string} token
*/

4 changes: 2 additions & 2 deletions CloverOAuth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* }
*/

require("prototype");
var Class = require("./Class.js");
var EndPointConfig = require("./EndpointConfig.js");

/**
Expand Down Expand Up @@ -205,4 +205,4 @@ CloverOAuth2.accessTokenKey = '#' + CloverOAuth2._accessTokenKey;
//
if ('undefined' !== typeof module) {
module.exports = CloverOAuth2;
}
}
3 changes: 1 addition & 2 deletions DebugCloverConnectorListener.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("prototype");
var Class = require("./Class.js");
var log = require('./Logger.js').create();
var ICloverConnectorListener = require("./remotepay/ICloverConnectorListener.js");

Expand Down Expand Up @@ -183,4 +183,3 @@ DebugCloverConnectorListener = Class.create(ICloverConnectorListener, {
if ('undefined' !== typeof module) {
module.exports = DebugCloverConnectorListener;
}

5 changes: 2 additions & 3 deletions DelegateCloverConnectorListener.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("prototype");
var Class = require("./Class.js");
var log = require('./Logger.js').create();
var ICloverConnectorListener = require("./remotepay/ICloverConnectorListener.js");

Expand Down Expand Up @@ -331,7 +331,7 @@ DelegateCloverConnectorListener = Class.create(ICloverConnectorListener, {
},

/**
*
*
* @param functionName
* @param listener
* @param error
Expand All @@ -355,4 +355,3 @@ DelegateCloverConnectorListener = Class.create(ICloverConnectorListener, {
if ('undefined' !== typeof module) {
module.exports = DelegateCloverConnectorListener;
}

4 changes: 2 additions & 2 deletions DeviceContactInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("prototype");
var Class = require("./Class.js");

/**
* @constructor
Expand All @@ -19,4 +19,4 @@ DeviceContactInfo = Class.create( {
//
if ('undefined' !== typeof module) {
module.exports = DeviceContactInfo;
}
}
4 changes: 2 additions & 2 deletions EndpointConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("prototype");
var Class = require("./Class.js");

/**
* @constructor
Expand Down Expand Up @@ -28,4 +28,4 @@ EndPointConfig = Class.create( {
//
if ('undefined' !== typeof module) {
module.exports = EndPointConfig;
}
}
2 changes: 1 addition & 1 deletion JSONToCustomObject.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("prototype");
var Class = require("./Class.js");
var log = require('./Logger.js').create();

JSONToCustomObject = Class.create({
Expand Down
1 change: 0 additions & 1 deletion MethodToMessage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Prototype.js required
var remotemessage = require("./remotemessage");

MethodToMessage = {};
Expand Down
38 changes: 18 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ Please report back to us any questions/comments/concerns, by emailing semi-integ

A deprecated beta version of the Connector (Clover.js) is included in this version with `require` directive syntax, but will removed in the future.

### Version [BETA](https://github.com/clover/remote-pay-cloud-BETA/tree/BETA_Final)
### Version [BETA](https://github.com/clover/remote-pay-cloud-BETA/tree/BETA_Final)

The beta version includes the earliest library as well as a server with examples of the functions.
The beta version includes the earliest library as well as a server with examples of the functions.

---

Expand All @@ -61,8 +61,7 @@ Clover's cloud connector API. Published as an NPM package. Intended for use in
## At a Glance

### Make a sale.
```
require("prototype");
```javascript
var $ = require('jQuery');

var clover = require("remote-pay-cloud");
Expand All @@ -77,7 +76,7 @@ var connector = new clover.CloverConnectorFactory().createICloverConnector({
"domain": "https://dev1.dev.clover.com/"
});

var ExampleCloverConnectorListener = Class.create( clover.remotepay.ICloverConnectorListener, {
var ExampleCloverConnectorListener = clover.Class.create( clover.remotepay.ICloverConnectorListener, {
initialize: function (cloverConnector) {
this.cloverConnector = cloverConnector;
},
Expand Down Expand Up @@ -116,14 +115,13 @@ $(window).on('beforeunload ', function () {
```

### To make a payment using the High Level Cloud API
#### Import the libraries needed to create the clover object.
```
require("prototype");
#### Import the Clover library.
```javascript
var clover = require("remote-pay-cloud");
```
#### Create the Clover Connector object.
This will require gathering the configuration information to create the connector. In this example, the configuration is hard coded. The creation of the connector is done using the connector factory.
```
```javascript
var connector = new clover.CloverConnectorFactory().createICloverConnector({
"merchantId": "BBFF8NBCXEMDT",
"clientId": "3RPTN642FHXTC",
Expand All @@ -138,7 +136,7 @@ There are several ways the Clover Connector object can be configured.
Examples of configurations that can be used when creating the Clover Connector object:

1. With a clientID, domain, merchantId, deviceSerialId
```
```javascript
{
"clientId" : "3BZPZ6A6FQ8ZM",
"remoteApplicationId": "com.yourname.yourapplication:1.0.0-beta1",
Expand All @@ -148,7 +146,7 @@ Examples of configurations that can be used when creating the Clover Connector o
}
```
1. With a oauthToken, domain, merchantId, clientId, deviceSerialId
```
```javascript
{
"oauthToken" : "6e6313e8-fe33-8662-7ff2-3a6690e0ff14",
"domain" : "https://sandbox.dev.clover.com/",
Expand All @@ -160,11 +158,11 @@ Examples of configurations that can be used when creating the Clover Connector o
```

#### Define a listener that will listen for events produced byt the Clover Connector.
The functions implemented will be called as the connector encounters the events. These functions can be found in the clover.remotepay.ICloverConnectorListener.
```
var ExampleCloverConnectorListener = Class.create( clover.remotepay.ICloverConnectorListener, {
// This function overrides the basic prototype.js initialization function. This example
// expects that a coler connector implementation instance is passed to the created listener.
The functions implemented will be called as the connector encounters the events. These functions can be found in the clover.remotepay.ICloverConnectorListener.
```javascript
var ExampleCloverConnectorListener = clover.Class.create( clover.remotepay.ICloverConnectorListener, {
// This function overrides the basic class initialization method. This example
// expects that a Clover connector implementation instance is passed to the created listener.
initialize: function (cloverConnector) {
this.cloverConnector = cloverConnector;
},
Expand All @@ -184,7 +182,7 @@ var ExampleCloverConnectorListener = Class.create( clover.remotepay.ICloverConne
this.cloverConnector.acceptSignature(request);
},
// The ICloverConnectorListener function that is called when a sale request is completed.
// This example logs the response, and disposes of the connector. If the response is not an expected
// This example logs the response, and disposes of the connector. If the response is not an expected
// type, it will log an error.
onSaleResponse: function (response) {
log.info(response);
Expand All @@ -198,15 +196,15 @@ var ExampleCloverConnectorListener = Class.create( clover.remotepay.ICloverConne
```

#### Add the listener instance to the connector, and initialize the connection to the device.
```
```javascript
var connectorListener = new ExampleCloverConnectorListener(connector);
connector.addCloverConnectorListener(connectorListener);
connector.initializeConnection();
```

#### Clean up the connection on exit of the window. This should be done with all connectors.
This example uses jQuery to add a hook for the window `beforeunload` event that ensures that the connector is displosed of.
```
```javascript
$(window).on('beforeunload ', function () {
try {
connector.dispose();
Expand All @@ -217,5 +215,5 @@ $(window).on('beforeunload ', function () {
```

## Generate Documentation
API documentation is generated when `npm install` is run.
API documentation is generated when `npm install` is run.
[Online Docs](http://clover.github.io/remote-pay-cloud/1.1.0-rc4.0/)
3 changes: 1 addition & 2 deletions RemoteMessageParser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require("prototype");
var Class = require("./Class.js");

var remotemessage = require("./remotemessage");

Expand Down Expand Up @@ -46,4 +46,3 @@ RemoteMessageParser.KEY_Package = "code_package";
if ('undefined' !== typeof module) {
module.exports = RemoteMessageParser;
}

3 changes: 1 addition & 2 deletions apps/AppTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* DO NOT EDIT DIRECTLY
*/

// Prototype.js required
require("prototype");
var Class = require("../Class.js");

/** Used to track the origin of a distributed call. */
/**
Expand Down
3 changes: 1 addition & 2 deletions base/Address.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* DO NOT EDIT DIRECTLY
*/

// Prototype.js required
require("prototype");
var Class = require("../Class.js");

/**
* @constructor
Expand Down
3 changes: 1 addition & 2 deletions base/CardData.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* DO NOT EDIT DIRECTLY
*/

// Prototype.js required
require("prototype");
var Class = require("../Class.js");

/**
* @constructor
Expand Down
3 changes: 1 addition & 2 deletions base/Challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
* DO NOT EDIT DIRECTLY
*/

// Prototype.js required
require("prototype");
var Class = require("../Class.js");
var order_VoidReason = require("../order/VoidReason");
var base_ChallengeType = require("../base/ChallengeType");

Expand Down
Loading