Skip to content

Commit fb89375

Browse files
committed
Merge pull request #116 from paypal/refactory
Refactory
2 parents 607795d + b72399a commit fb89375

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1749
-1043
lines changed

.banner

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*!
2+
* <%= pkg.name %>
3+
* <%= pkg.description %>
4+
*
5+
* @version <%= pkg.version %>
6+
* @url <%= pkg.homepage %>
7+
* @license <%= pkg.licenses[0].type %> <<%= pkg.licenses[0].url %>>
8+
*/

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
root = true
33

44
[*]
5-
indent_style = tab
5+
indent_style = spaces
66
indent_size = 4
77
end_of_line = lf
88
charset = utf-8

.jshintrc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@
1414
"mootools": false,
1515
"dojo": false,
1616

17-
"predef": [],
17+
"predef": [
18+
"describe",
19+
"it",
20+
"before",
21+
"beforeEach",
22+
"after",
23+
"afterEach"
24+
],
1825

1926
"debug": false,
2027
"devel": false,
2128

2229
"strict": true,
2330
"globalstrict": false,
2431

32+
"globals": {
33+
"$TEMPLATES$": true,
34+
"$STRINGS$": true
35+
},
36+
2537
"asi": false,
2638
"laxbreak": false,
2739
"bitwise": false,

Gruntfile.js

Lines changed: 21 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,25 @@
1+
'use strict';
2+
3+
14
module.exports = function (grunt) {
25

3-
'use strict';
4-
5-
// Project configuration.
6-
grunt.initConfig({
7-
8-
pkg: grunt.file.readJSON('package.json'),
9-
10-
meta: {
11-
banner: '/*!\n * <%= pkg.name %>\n * <%= pkg.description %>\n * @version <%= pkg.version %> - <%= grunt.template.today(\'yyyy-mm-dd\') %>\n * @author <%= pkg.author.name %> <<%= pkg.author.url %>>\n */\n'
12-
},
13-
14-
jshint: {
15-
all: {
16-
src: ['src/*.js', 'test/spec/*.js'],
17-
options: {
18-
jshintrc: '.jshintrc'
19-
}
20-
}
21-
},
22-
23-
uglify: {
24-
dist: {
25-
src: ['<%= meta.banner %>', 'src/paypal-button.js'],
26-
dest: 'dist/paypal-button.min.js',
27-
options: {
28-
banner: '<%= meta.banner %>'
29-
}
30-
}
31-
},
32-
33-
mochaTest: {
34-
all: {
35-
options: {
36-
reporter: 'spec'
37-
},
38-
src: ['test/spec/*.js']
39-
}
40-
},
41-
watch: {
42-
scripts: {
43-
files: ['src/**/*.js'],
44-
tasks: ['build'],
45-
options: {
46-
spawn: false
47-
}
48-
}
49-
}
50-
});
51-
52-
// Load grunt tasks from npm packages
53-
grunt.loadNpmTasks('grunt-contrib-jshint');
54-
grunt.loadNpmTasks('grunt-contrib-uglify');
55-
grunt.loadNpmTasks('grunt-contrib-watch');
56-
grunt.loadNpmTasks('grunt-mocha-test');
57-
58-
grunt.registerTask('build', ['jshint', 'uglify']);
59-
grunt.registerTask('test', ['jshint', 'mochaTest']);
6+
7+
// load all grunt tasks matching the `grunt-*` pattern
8+
require('load-grunt-config')(grunt, {
9+
configPath: require('path').resolve('tasks')
10+
});
11+
12+
13+
// Aliases for ease of use.
14+
grunt.registerTask('lint', ['jshint', 'eslint']);
15+
grunt.registerTask('coverage', ['mocha_istanbul']);
16+
grunt.registerTask('mocha', ['mochaTest']);
17+
grunt.registerTask('themify', ['templates', 'css', 'images', 'content']);
18+
grunt.registerTask('test', ['lint', 'build', 'coverage']);
19+
grunt.registerTask('develop', ['browserify', 'themify']);
20+
grunt.registerTask('build', ['browserify', 'themify', 'uglify', 'usebanner']);
21+
6022

6123
};
24+
25+

README.md

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,23 @@ All of PayPal's [HTML button variables](https://developer.paypal.com/webapps/dev
106106
* `data-style` The style of the button. Can be set to `primary` (default) and `secondary`.
107107
* `data-locale` The desired locale of the PayPal site.
108108
* `data-callback` The IPN notify URL to be called on completion of the transaction.
109-
* `data-env` The PayPal environment to checkout in, e.g. `sandbox` (defaults to 'www').
109+
* `data-host` The PayPal host to checkout in, e.g. `www.sandbox.paypal.com` (defaults to 'www.paypal.com').
110110
* `data-type` The type of button to render. `button` for a plain button (default), `form` to create a button with a PayPal Payments Standard HTML form, or `qr` to create a PayPal Payments Standard compatible QR code.
111111

112112

113-
### Editable fields
114-
Creating editable fields is easy! Just add `-editable` to the name of your variable, e.g. `data-quantity-editable`, and an input field will magically appear for your users.
113+
### Editable inputs
114+
Creating editable inputs is easy. Just add `-editable` to the name of your variable, e.g. `data-quantity-editable`, and an input field will magically appear for your users.
115115

116116

117-
### Custom fields
118-
You can also add custom text fields and dropdowns to your form.
117+
### Options fields
118+
Allow the user to choose from multiple options with the following sytax:
119119

120-
121-
For a text field:
122-
```javascript
123-
data-option0name="Coupon Number"
124120
```
125-
126-
For a dropdown:
127-
```javascript
128-
data-option0name="Size"
129-
data-option0select0="Small"
130-
data-option0select1="Medium"
131-
data-option0select2="Large"
132-
data-option0price0="8.00"
133-
data-option0price1="10.00"
134-
data-option0price2="12.00"
121+
data-option0="Color=Blue:8.00,Green:12.00,Red:10.00"
122+
data-option1="Size=Small,Medium,Large"
135123
```
136124

125+
137126
### Callback notification
138127
On completion of a transaction you can get a payment notification ([IPN](https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNIntro/)) on a callback URL you specify using the `data-callback` attribute. An [IPN simulator](https://developer.paypal.com/webapps/developer/applications/ipn_simulator) is available on the sandbox.
139128

@@ -142,22 +131,22 @@ On completion of a transaction you can get a payment notification ([IPN](https:/
142131

143132
### Localization
144133
* Changing the default language of a button can be done by setting the variable `data-lc` with the correct locale code, e.g. es_ES.
145-
* Changing the default input labels of editable buttons can be done by overriding the default configuration, e.g. PAYPAL.apps.ButtonFactory.config.labels.
134+
* Changing the default input labels of editable buttons can be done by overriding the default configuration, e.g. `paypal.button.config.labels`.
146135

147136

148137
### JavaScript API
149138
There's even a fancy JavaScript API if you'd like to pragmatically create your buttons.
150139

151-
**PAYPAL.apps.ButtonFactory.config**
152-
This can be overridden to change the default behavior of the buttons.
153-
154-
**PAYPAL.apps.ButtonFactory.create(business, data, type, parentNode)**
140+
**paypal.button.create(business, data, config, parentNode)**
155141
Creates and returns an HTML element that contains the button code.
156142
> **business** - A string containing either the business ID or the business email
157143
> **data** - A JavaScript object containing the button variables
158-
> **type** - The button type, e.g. "buynow", "cart", "qr"
144+
> **config** - A configuration object for the button. Possible settings are `button`, `type`, `style`, `size`, and `host`
159145
> **parentNode** - An HTML element to add the newly created button to (Optional)
160146
147+
**paypal.button.process(node)**
148+
Parses `node` and automatically runs `paypal.button.create` on any `<script>` element it finds matching the right criteria. This is called automatically on `document.body`.
149+
161150

162151
## Browser support
163152
The JavaScript buttons have been tested and work in all modern browsers including:

dist/all.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/paypal-button.min.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

eslint.json

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"node": true,
5+
"amd": true,
6+
"mocha": true
7+
},
8+
9+
"rules": {
10+
"no-cond-assign": 2,
11+
"no-console": 0,
12+
"no-constant-condition": 2,
13+
"no-comma-dangle": 2,
14+
"no-control-regex": 2,
15+
"no-debugger": 2,
16+
"no-dupe-keys": 2,
17+
"no-empty": 2,
18+
"no-empty-class": 2,
19+
"no-ex-assign": 2,
20+
"no-extra-boolean-cast": 2,
21+
"no-extra-parens": 0,
22+
"no-extra-semi": 2,
23+
"no-func-assign": 2,
24+
"no-inner-declarations": [2, "functions"],
25+
"no-invalid-regexp": 2,
26+
"no-negated-in-lhs": 2,
27+
"no-obj-calls": 2,
28+
"no-regex-spaces": 2,
29+
"no-sparse-arrays": 2,
30+
"no-unreachable": 2,
31+
"use-isnan": 2,
32+
"valid-jsdoc": 0,
33+
"valid-typeof": 2,
34+
35+
"block-scoped-var": 0,
36+
"complexity": [0, 11],
37+
"consistent-return": 2,
38+
"curly": [2, "all"],
39+
"default-case": 2,
40+
"dot-notation": 2,
41+
"eqeqeq": 2,
42+
"guard-for-in": 2,
43+
"no-alert": 2,
44+
"no-caller": 2,
45+
"no-div-regex": 2,
46+
"no-else-return": 2,
47+
"no-empty-label": 2,
48+
"no-eq-null": 2,
49+
"no-eval": 2,
50+
"no-extend-native": 0,
51+
"no-fallthrough": 2,
52+
"no-floating-decimal": 2,
53+
"no-implied-eval": 2,
54+
"no-labels": 2,
55+
"no-iterator": 2,
56+
"no-lone-blocks": 2,
57+
"no-loop-func": 2,
58+
"no-multi-str": 2,
59+
"no-native-reassign": 2,
60+
"no-new": 2,
61+
"no-new-func": 2,
62+
"no-new-wrappers": 2,
63+
"no-octal": 2,
64+
"no-octal-escape": 2,
65+
"no-proto": 2,
66+
"no-redeclare": 2,
67+
"no-return-assign": 2,
68+
"no-script-url": 2,
69+
"no-self-compare": 2,
70+
"no-sequences": 2,
71+
"no-unused-expressions": 2,
72+
"no-warning-comments": 0,
73+
"no-with": 2,
74+
"no-yoda": 2,
75+
"radix": 2,
76+
"wrap-iife": [2, "inside"],
77+
78+
"no-global-strict": 0,
79+
"no-extra-strict": 2,
80+
"strict": 2,
81+
82+
"no-catch-shadow": 2,
83+
"no-delete-var": 2,
84+
"no-label-var": 2,
85+
"no-shadow": 2,
86+
"no-shadow-restricted-names": 2,
87+
"no-undef": 2,
88+
"no-undef-init": 2,
89+
"no-unused-vars": [2, {"vars": "all", "args": "after-used"}],
90+
"no-use-before-define": 2,
91+
92+
"handle-callback-err": 0,
93+
"no-mixed-requires": 0,
94+
"no-new-require": 2,
95+
"no-path-concat": 2,
96+
"no-process-exit": 2,
97+
"no-restricted-modules": 2,
98+
"no-sync": 2,
99+
100+
"brace-style": [2, "1tbs"],
101+
"camelcase": 0,
102+
"consistent-this": [2, "self"],
103+
"func-names": 0,
104+
"func-style": [0, "declaration"],
105+
"new-cap": 2,
106+
"new-parens": 2,
107+
"no-nested-ternary": 2,
108+
"no-array-constructor": 2,
109+
"no-lonely-if": 2,
110+
"no-new-object": 2,
111+
"no-spaced-func": 2,
112+
"no-space-before-semi": 2,
113+
"no-ternary": 0,
114+
"no-underscore-dangle": 0,
115+
"no-wrap-func": 2,
116+
"quotes": [2, "single"],
117+
"quote-props": 0,
118+
"semi": 2,
119+
"sort-vars": 0,
120+
"space-after-keywords": 2,
121+
"space-in-brackets": [0, "never"],
122+
"space-infix-ops": 2,
123+
"space-return-throw-case": 2,
124+
"space-unary-word-ops": 2,
125+
"max-nested-callbacks": [0, 2],
126+
"one-var": 0,
127+
"wrap-regex": 2,
128+
129+
"max-depth": [0, 4],
130+
"max-len": [0, 80, 4],
131+
"max-params": [0, 3],
132+
"max-statements": [0, 10],
133+
"no-bitwise": 2,
134+
"no-plusplus": 0
135+
}
136+
}

locales/AU/en/button.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
buynow=Buy with {wordmark}
2+
cart=Add to Cart
3+
donate=Donate
4+
subscribe=Subscribe
5+
paynow=Pay Now
6+
item_name=Item
7+
number=Number
8+
amount=Amount
9+
quantity=Quantity

locales/CA/fr/button.properties

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
buynow=Acheter
2+
cart=Ajouter au panier
3+
donate=Faire un don
4+
subscribe=Souscrire
5+
paynow=Payer maintenant
6+
item_name=Objet
7+
number=Numéro
8+
amount=Montant
9+
quantity=Quantité

0 commit comments

Comments
 (0)