Skip to content

Commit b5f6acd

Browse files
committed
Adding support for donation buttons
1 parent 11664db commit b5f6acd

3 files changed

Lines changed: 70 additions & 18 deletions

File tree

src/paypal-button.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ PAYPAL.apps = PAYPAL.apps || {};
2323
},
2424
buttonImgs = {
2525
buynow: '//www.paypalobjects.com/{locale}/i/btn/btn_buynow_{size}.gif',
26-
cart: '//www.paypalobjects.com/{locale}/i/btn/btn_cart_{size}.gif'
26+
cart: '//www.paypalobjects.com/{locale}/i/btn/btn_cart_{size}.gif',
27+
donate: '//www.paypalobjects.com/{locale}/i/btn/btn_donate_{size}.gif'
2728
};
2829

2930
if (!PAYPAL.apps.ButtonFactory) {
@@ -47,6 +48,7 @@ PAYPAL.apps = PAYPAL.apps || {};
4748
buynow: 0,
4849
cart: 0,
4950
hosted: 0,
51+
donate: 0,
5052
qr: 0
5153
};
5254

@@ -80,7 +82,10 @@ PAYPAL.apps = PAYPAL.apps || {};
8082
} else if (type === 'cart') {
8183
data.add('cmd', '_cart');
8284
data.add('add', true);
83-
// Plain text buttons
85+
// Donation buttons
86+
} else if (type === 'donate') {
87+
data.add('cmd', '_donations');
88+
// Buy Now buttons
8489
} else {
8590
data.add('cmd', '_xclick');
8691
}

test/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ <h2>Cart (Large)</h2>
8888
></script>
8989
</div>
9090

91+
<div id="donate-sm">
92+
<h2>Donate (Small)</h2>
93+
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
94+
data-button="donate"
95+
data-name="Donate!"
96+
data-amount="1.00"
97+
data-size="small"
98+
></script>
99+
</div>
100+
101+
<div id="donate-lg">
102+
<h2>Donate (Large)</h2>
103+
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"
104+
data-button="donate"
105+
data-name="Donate!"
106+
data-amount="1.00"
107+
data-size="large"
108+
></script>
109+
</div>
110+
91111
<div id="hosted-sm">
92112
<h2>Hosted (Small)</h2>
93113
<script src="../src/paypal-button.js?merchant=6XF3MPZBZV6HU"

test/test.js

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,63 @@ var fs = require('fs'),
99
document = jsdom(testFile, null, jsdomOptions),
1010
window = document.createWindow();
1111

12+
1213
eval(fs.readFileSync('src/paypal-button.js').toString());
1314

1415

1516
// Test the object's integrity
16-
describe('PAYPAL.apps.ButtonFactory', function () {
17+
describe('JavaScript API', function () {
1718
'use strict';
1819

19-
it('Should have a PAYPAL object', function () {
20+
it('Should have a PAYPAL namespace', function () {
2021
PAYPAL.should.be.a('object');
2122
});
2223

23-
it('Should have a PAYPAL.apps object', function () {
24+
it('Should have a PAYPAL.apps namespace', function () {
2425
PAYPAL.apps.should.be.a('object');
2526
});
2627

27-
it('Should have a PAYPAL.apps.ButtonFactory object', function () {
28+
it('Should have a PAYPAL.apps.ButtonFactory namespace', function () {
2829
PAYPAL.apps.ButtonFactory.should.be.a('object');
2930
});
3031

31-
});
32-
33-
34-
// Test the create method
35-
describe('PAYPAL.apps.ButtonFactory.create', function () {
36-
'use strict';
32+
it('Should have a configuration object', function () {
33+
PAYPAL.apps.ButtonFactory.config.should.be.a('object');
34+
});
3735

38-
it('Should be a function', function () {
36+
it('Should have a create method', function () {
3937
PAYPAL.apps.ButtonFactory.create.should.be.a('function');
4038
});
4139

42-
it('Should return false if no parameters', function () {
40+
it('Create return false if no parameters', function () {
4341
var result = PAYPAL.apps.ButtonFactory.create();
4442

4543
result.should.equal(false);
4644
});
45+
4746
});
4847

4948

5049
// Test the buttons counter object
51-
describe('PAYPAL.apps.ButtonFactory.buttons', function () {
50+
describe('Test page button counter', function () {
5251

5352
'use strict';
5453

5554
var buttons = PAYPAL.apps.ButtonFactory.buttons;
5655

57-
it('Should have four buy now buttons', function () {
56+
it('Should have six buy now buttons', function () {
5857
buttons.buynow.should.equal(6);
5958
});
6059

61-
it('Should have three cart buttons', function () {
60+
it('Should have two cart buttons', function () {
6261
buttons.cart.should.equal(2);
6362
});
6463

65-
it('Should have three hosted buttons', function () {
64+
it('Should have two donation buttons', function () {
65+
buttons.donate.should.equal(2);
66+
});
67+
68+
it('Should have two hosted buttons', function () {
6669
buttons.hosted.should.equal(2);
6770
});
6871

@@ -72,6 +75,30 @@ describe('PAYPAL.apps.ButtonFactory.buttons', function () {
7275
});
7376

7477

78+
// Test editable fields
79+
describe('Editable buttons', function () {
80+
'use strict';
81+
82+
var inputs = document.querySelectorAll('#buynow-editable input[type="text"]');
83+
84+
it('Should have two inputs', function () {
85+
inputs.length.should.equal(2);
86+
});
87+
88+
it('Should have a CSS class on the input', function () {
89+
inputs[0].className.should.include('paypal-input');
90+
});
91+
92+
it('Should have a CSS class on the label', function () {
93+
inputs[0].parentNode.className.should.include('paypal-label');
94+
});
95+
96+
it('Should have a CSS class on the container', function () {
97+
inputs[0].parentNode.parentNode.className.should.include('paypal-group');
98+
});
99+
100+
});
101+
75102

76103
// Test multi-language support
77104
describe('Multi-language button images', function () {

0 commit comments

Comments
 (0)