Skip to content

Commit

Permalink
first implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbatista committed Mar 29, 2016
0 parents commit 7f5c4e2
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{

}
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
coverage
dist
.idea
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- v5
- v4
- '0.12'
- '0.10'
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Matteo Padovano <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# loopback-component-paypal
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url]
>
## Installation

```sh
$ npm install --save loopback-component-paypal
```

## Usage
Add configuration in file component-config.json
```js
{
"loopback-component-paypal": {
"clientID": "CLIENT_ID",
"clientSecret": "CLIENT_SECRET",
"mode": "sandbox",
"payment": {
"intent": "sale",
"redirect_urls": {
"return_url": "return_url",
"cancel_url": "cancel_url"
},
"payer": {
"payment_method": "paypal"
}
}
}
}

var PayPal = app.models.PayPal;
PayPal.payment.create(create_payment_json, function (error, payment) {
if (error) {
console.log(error.response);
throw error;
} else {
console.log("Create Payment Response");
console.log(payment);
}
});
```
## License

MIT © [Matteo Padovano](https://github.com/mrbatista)


[npm-image]: https://badge.fury.io/js/loopback-component-paypal.svg
[npm-url]: https://npmjs.org/package/loopback-component-paypal
[travis-image]: https://travis-ci.org/mrbatista/loopback-component-paypal.svg?branch=master
[travis-url]: https://travis-ci.org/mrbatista/loopback-component-paypal
[daviddm-image]: https://david-dm.org/mrbatista/loopback-component-paypal.svg?theme=shields.io
[daviddm-url]: https://david-dm.org/mrbatista/loopback-component-paypal
69 changes: 69 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
var path = require('path');
var gulp = require('gulp');
var eslint = require('gulp-eslint');
var excludeGitignore = require('gulp-exclude-gitignore');
var mocha = require('gulp-mocha');
var istanbul = require('gulp-istanbul');
var nsp = require('gulp-nsp');
var plumber = require('gulp-plumber');
var babel = require('gulp-babel');
var del = require('del');
var isparta = require('isparta');

// Initialize the babel transpiler so ES2015 files gets compiled
// when they're loaded
require('babel-core/register');

gulp.task('static', function () {
return gulp.src('**/*.js')
.pipe(excludeGitignore())
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('nsp', function (cb) {
nsp({package: path.resolve('package.json')}, cb);
});

gulp.task('pre-test', function () {
return gulp.src('lib/**/*.js')
.pipe(excludeGitignore())
.pipe(istanbul({
includeUntested: true,
instrumenter: isparta.Instrumenter
}))
.pipe(istanbul.hookRequire());
});

gulp.task('test', ['pre-test'], function (cb) {
var mochaErr;

gulp.src('test/**/*.js')
.pipe(plumber())
.pipe(mocha({reporter: 'spec'}))
.on('error', function (err) {
mochaErr = err;
})
.pipe(istanbul.writeReports())
.on('end', function () {
cb(mochaErr);
});
});

gulp.task('watch', function () {
gulp.watch(['lib/**/*.js', 'test/**'], ['test']);
});

gulp.task('babel', ['clean'], function () {
return gulp.src('lib/**/*.js')
.pipe(babel())
.pipe(gulp.dest('dist'));
});

gulp.task('clean', function () {
return del('dist');
});

gulp.task('prepublish', ['nsp', 'babel']);
gulp.task('default', ['static', 'test']);
11 changes: 11 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import assert from 'assert'
import * as PayPalConnector from './paypal-connector'

export default function(app, options) {

assert(typeof options === 'object', 'cannot initialize paypal component without a options object');

let loopback = app.loopback;
let ds = loopback.createDataSource(Object.assign(options, {connector: PayPalConnector}));
app.model('PayPal', {dataSource: ds, public: false});
}
34 changes: 34 additions & 0 deletions lib/paypal-connector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {PayPalService} from './paypal-service';

/**
* Initialize the paypal service as a connector for LoopBack data sources
* @param {dataSource} dataSource DataSource instance
* @prop {Object} settings Connector settings
*/
export function initialize(dataSource) {
let settings = dataSource.settings || {};
let connector = new PayPalService(settings);
dataSource.connector = connector;
dataSource.connector.dataSource = dataSource;

connector.DataAccessObject = DataAccessObject;

function DataAccessObject() {}
DataAccessObject.payment = connector.client.payment;
DataAccessObject.sale = connector.client.sale;
DataAccessObject.refund = connector.client.refund;
DataAccessObject.authorization = connector.client.authorization;
DataAccessObject.capture = connector.client.capture;
DataAccessObject.order = connector.client.order;
DataAccessObject.payout = connector.client.payout;
DataAccessObject.payoutItem = connector.client.payoutItem;
DataAccessObject.billingPlan = connector.client.billingPlan;
DataAccessObject.billingAgreement = connector.client.billingAgreement;
DataAccessObject.creditCard = connector.client.creditCard;
DataAccessObject.invoice = connector.client.invoice;
DataAccessObject.openIdConnect = connector.client.openIdConnect;
DataAccessObject.webProfile = connector.client.webProfile;
DataAccessObject.notification = connector.client.notification;
DataAccessObject.generate_token = connector.client.generate_token;
DataAccessObject.billing_plan = connector.client.billing_plan;
}
15 changes: 15 additions & 0 deletions lib/paypal-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import paypal from 'paypal-rest-sdk';

export class PayPalService {

constructor(options) {

paypal.configure({
client_id: options.clientID,
client_secret: options.clientSecret,
mode: options.mode || 'sandbox'
});
this.client = paypal;
}

}
61 changes: 61 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "loopback-component-paypal",
"version": "0.1.0",
"description": "Loopback PayPal Component",
"homepage": "https://github.com/mrbatista/loopback-component-paypal",
"author": "Matteo Padovano <[email protected]> (https://github.com/mrbatista)",
"files": [
"dist"
],
"main": "dist/index.js",
"keywords": [
"loopback",
"paypal"
],
"devDependencies": {
"babel-core": "^5.8.35",
"babel-eslint": "^4.1.8",
"babel-preset-es2015": "^6.6.0",
"chai": "^3.5.0",
"del": "^2.0.2",
"dirty-chai": "^1.2.2",
"eslint": "^2.1.0",
"eslint-config-xo-space": "^0.10.0",
"eslint-plugin-babel": "^3.1.0",
"gulp": "^3.9.0",
"gulp-babel": "^5.1.0",
"gulp-eslint": "^2.0.0",
"gulp-exclude-gitignore": "^1.0.0",
"gulp-istanbul": "^0.10.3",
"gulp-line-ending-corrector": "^1.0.1",
"gulp-mocha": "^2.0.0",
"gulp-nsp": "^2.1.0",
"gulp-plumber": "^1.0.0",
"isparta": "^3.0.3",
"loopback": "^2.27.0"
},
"eslintConfig": {
"extends": "xo-space/esnext",
"env": {
"mocha": true
}
},
"repository": {
"type": "git",
"url": "git+https://github.com/mrbatista/loopback-component-paypal.git"
},
"scripts": {
"prepublish": "gulp prepublish",
"test": "gulp"
},
"license": "MIT",
"dependencies": {
"paypal-rest-sdk": "^1.6.8"
},
"bugs": {
"url": "https://github.com/mrbatista/loopback-component-paypal/issues"
},
"directories": {
"test": "test"
}
}
20 changes: 20 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import * as chai from 'chai';
import dirtyChai from 'dirty-chai'
import loopback from 'loopback';
import loopbackComponentPaypal from '../lib';
let expect = chai.expect;
chai.use(dirtyChai);

describe('loopback-component-paypal', () => {
let app;
before((done) => {
app = loopback();
loopbackComponentPaypal(app, {});
done();
});

it('PayPal connector should have property payment', (done) => {
expect(app.models.PayPal.payment).to.exist();
done();
});
});

0 comments on commit 7f5c4e2

Please sign in to comment.