Skip to content

Commit fae0f35

Browse files
committed
Fix for #31 to enable different environments
1 parent 01be5e2 commit fae0f35

7 files changed

Lines changed: 136 additions & 96 deletions

File tree

dist/paypal-button-minicart.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* PayPalJSButtons
33
* JavaScript integration for PayPal's payment buttons
4-
* @version 1.0.1 - 2013-04-03
4+
* @version 1.0.1 - 2013-04-13
55
* @author Jeff Harrell <https://github.com/jeffharrell/>
66
*/
77
/*!
@@ -1750,8 +1750,8 @@ PAYPAL.apps = PAYPAL.apps || {};
17501750

17511751

17521752
var app = {},
1753-
paypalURL = 'https://www.paypal.com/cgi-bin/webscr',
1754-
qrCodeURL = 'https://www.paypal.com/webapps/ppint/qrcode?data={url}&pattern={pattern}&height={size}',
1753+
paypalURL = 'https://{env}.paypal.com/cgi-bin/webscr',
1754+
qrCodeURL = 'https://{env}.paypal.com/webapps/ppint/qrcode?data={url}&pattern={pattern}&height={size}',
17551755
bnCode = 'JavaScriptButton_{type}',
17561756
prettyParams = {
17571757
name: 'item_name',
@@ -1821,7 +1821,7 @@ PAYPAL.apps = PAYPAL.apps || {};
18211821
* @return {HTMLElement}
18221822
*/
18231823
app.create = function (business, raw, type, parent) {
1824-
var data = new DataStore(), button, key;
1824+
var data = new DataStore(), button, key, env;
18251825

18261826
if (!business) { return false; }
18271827

@@ -1832,6 +1832,7 @@ PAYPAL.apps = PAYPAL.apps || {};
18321832

18331833
// Defaults
18341834
type = type || 'buynow';
1835+
env = data.items.env && data.items.env.value || 'www';
18351836

18361837
// Cart buttons
18371838
if (type === 'cart') {
@@ -1857,6 +1858,7 @@ PAYPAL.apps = PAYPAL.apps || {};
18571858
// Add common data
18581859
data.add('business', business);
18591860
data.add('bn', bnCode.replace(/\{type\}/, type));
1861+
data.add('env', env);
18601862

18611863
// Build the UI components
18621864
if (type === 'qr') {
@@ -1885,6 +1887,43 @@ PAYPAL.apps = PAYPAL.apps || {};
18851887
}
18861888

18871889

1890+
/**
1891+
* Injects button CSS in the <head>
1892+
*
1893+
* @return {void}
1894+
*/
1895+
function injectCSS() {
1896+
var css, styleEl, paypalButton, paypalInput;
1897+
1898+
if (document.getElementById('paypal-button')) {
1899+
return;
1900+
}
1901+
1902+
css = '';
1903+
styleEl = document.createElement('style');
1904+
paypalButton = '.paypal-button';
1905+
paypalInput = paypalButton + ' button';
1906+
1907+
css += paypalButton + ' { white-space: nowrap; }';
1908+
css += paypalInput + ' { white-space: nowrap; overflow: hidden; border-radius: 13px; font-family: "Arial", bold, italic; font-weight: bold; font-style: italic; border: 1px solid #ffa823; color: #0E3168; background: #ffa823; position: relative; text-shadow: 0 1px 0 rgba(255,255,255,.5); cursor: pointer; z-index: 0; }';
1909+
css += paypalInput + ':before { content: " "; position: absolute; width: 100%; height: 100%; border-radius: 11px; top: 0; left: 0; background: #ffa823; background: -webkit-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -moz-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -ms-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); z-index: -2; }';
1910+
css += paypalInput + ':after { content: " "; position: absolute; width: 98%; height: 60%; border-radius: 40px 40px 38px 38px; top: 0; left: 0; background: -webkit-linear-gradient(top, #fefefe 0%, #fed994 100%); background: -moz-linear-gradient(top, #fefefe 0%, #fed994 100%); background: -ms-linear-gradient(top, #fefefe 0%, #fed994 100%); background: linear-gradient(top, #fefefe 0%, #fed994 100%); z-index: -1; -webkit-transform: translateX(1%);-moz-transform: translateX(1%); -ms-transform: translateX(1%); transform: translateX(1%); }';
1911+
css += paypalInput + '.small { padding: 3px 15px; font-size: 12px; }';
1912+
css += paypalInput + '.large { padding: 4px 19px; font-size: 14px; }';
1913+
1914+
styleEl.type = 'text/css';
1915+
styleEl.id = 'paypal-button';
1916+
1917+
if (styleEl.styleSheet) {
1918+
styleEl.styleSheet.cssText = css;
1919+
} else {
1920+
styleEl.appendChild(document.createTextNode(css));
1921+
}
1922+
1923+
document.getElementsByTagName('head')[0].appendChild(styleEl);
1924+
}
1925+
1926+
18881927
/**
18891928
* Builds the form DOM structure for a button
18901929
*
@@ -1900,7 +1939,7 @@ PAYPAL.apps = PAYPAL.apps || {};
19001939
item, child, label, input, key, size, locale, localeText;
19011940

19021941
form.method = 'post';
1903-
form.action = paypalURL;
1942+
form.action = paypalURL.replace('{env}', data.items.env.value);
19041943
form.className = 'paypal-button';
19051944
form.target = '_top';
19061945

@@ -1962,42 +2001,6 @@ PAYPAL.apps = PAYPAL.apps || {};
19622001
return form;
19632002
}
19642003

1965-
/**
1966-
* Injects button CSS in the <head>
1967-
*
1968-
* @return {void}
1969-
*/
1970-
function injectCSS() {
1971-
var css, styleEl, paypalButton, paypalInput;
1972-
1973-
if (document.getElementById('paypal-button')) {
1974-
return;
1975-
}
1976-
1977-
css = '';
1978-
styleEl = document.createElement('style');
1979-
paypalButton = '.paypal-button';
1980-
paypalInput = paypalButton + ' button';
1981-
1982-
css += paypalButton + ' { white-space: nowrap; }';
1983-
css += paypalInput + ' { white-space: nowrap; overflow: hidden; border-radius: 13px; font-family: "Arial", bold, italic; font-weight: bold; font-style: italic; border: 1px solid #ffa823; color: #0E3168; background: #ffa823; position: relative; text-shadow: 0 1px 0 rgba(255,255,255,.5); cursor: pointer; z-index: 0; }';
1984-
css += paypalInput + ':before { content: " "; position: absolute; width: 100%; height: 100%; border-radius: 11px; top: 0; left: 0; background: #ffa823; background: -webkit-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -moz-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -ms-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); z-index: -2; }';
1985-
css += paypalInput + ':after { content: " "; position: absolute; width: 98%; height: 60%; border-radius: 40px 40px 38px 38px; top: 0; left: 0; background: -webkit-linear-gradient(top, #fefefe 0%, #fed994 100%); background: -moz-linear-gradient(top, #fefefe 0%, #fed994 100%); background: -ms-linear-gradient(top, #fefefe 0%, #fed994 100%); background: linear-gradient(top, #fefefe 0%, #fed994 100%); z-index: -1; -webkit-transform: translateX(1%);-moz-transform: translateX(1%); -ms-transform: translateX(1%); transform: translateX(1%); }';
1986-
css += paypalInput + '.small { padding: 3px 15px; font-size: 12px; }';
1987-
css += paypalInput + '.large { padding: 4px 19px; font-size: 14px; }';
1988-
1989-
styleEl.type = 'text/css';
1990-
styleEl.id = 'paypal-button';
1991-
1992-
if (styleEl.styleSheet) {
1993-
styleEl.styleSheet.cssText = css;
1994-
} else {
1995-
styleEl.appendChild(document.createTextNode(css));
1996-
}
1997-
1998-
document.getElementsByTagName('head')[0].appendChild(styleEl);
1999-
}
2000-
20012004

20022005
/**
20032006
* Builds the image for a QR code
@@ -2022,7 +2025,7 @@ PAYPAL.apps = PAYPAL.apps || {};
20222025
}
20232026

20242027
url = encodeURIComponent(url);
2025-
img.src = qrCodeURL.replace('{url}', url).replace('{pattern}', pattern).replace('{size}', size);
2028+
img.src = qrCodeURL.replace('{env}', data.items.env.value).replace('{url}', url).replace('{pattern}', pattern).replace('{size}', size);
20262029

20272030
return img;
20282031
}

dist/paypal-button-minicart.min.js

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

dist/paypal-button.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*!
22
* PayPalJSButtons
33
* JavaScript integration for PayPal's payment buttons
4-
* @version 1.0.1 - 2013-04-03
4+
* @version 1.0.1 - 2013-04-13
55
* @author Jeff Harrell <https://github.com/jeffharrell/>
66
*/
77
if (typeof PAYPAL === 'undefined' || !PAYPAL) {
@@ -17,8 +17,8 @@ PAYPAL.apps = PAYPAL.apps || {};
1717

1818

1919
var app = {},
20-
paypalURL = 'https://www.paypal.com/cgi-bin/webscr',
21-
qrCodeURL = 'https://www.paypal.com/webapps/ppint/qrcode?data={url}&pattern={pattern}&height={size}',
20+
paypalURL = 'https://{env}.paypal.com/cgi-bin/webscr',
21+
qrCodeURL = 'https://{env}.paypal.com/webapps/ppint/qrcode?data={url}&pattern={pattern}&height={size}',
2222
bnCode = 'JavaScriptButton_{type}',
2323
prettyParams = {
2424
name: 'item_name',
@@ -88,7 +88,7 @@ PAYPAL.apps = PAYPAL.apps || {};
8888
* @return {HTMLElement}
8989
*/
9090
app.create = function (business, raw, type, parent) {
91-
var data = new DataStore(), button, key;
91+
var data = new DataStore(), button, key, env;
9292

9393
if (!business) { return false; }
9494

@@ -99,6 +99,7 @@ PAYPAL.apps = PAYPAL.apps || {};
9999

100100
// Defaults
101101
type = type || 'buynow';
102+
env = data.items.env && data.items.env.value || 'www';
102103

103104
// Cart buttons
104105
if (type === 'cart') {
@@ -124,6 +125,7 @@ PAYPAL.apps = PAYPAL.apps || {};
124125
// Add common data
125126
data.add('business', business);
126127
data.add('bn', bnCode.replace(/\{type\}/, type));
128+
data.add('env', env);
127129

128130
// Build the UI components
129131
if (type === 'qr') {
@@ -152,6 +154,43 @@ PAYPAL.apps = PAYPAL.apps || {};
152154
}
153155

154156

157+
/**
158+
* Injects button CSS in the <head>
159+
*
160+
* @return {void}
161+
*/
162+
function injectCSS() {
163+
var css, styleEl, paypalButton, paypalInput;
164+
165+
if (document.getElementById('paypal-button')) {
166+
return;
167+
}
168+
169+
css = '';
170+
styleEl = document.createElement('style');
171+
paypalButton = '.paypal-button';
172+
paypalInput = paypalButton + ' button';
173+
174+
css += paypalButton + ' { white-space: nowrap; }';
175+
css += paypalInput + ' { white-space: nowrap; overflow: hidden; border-radius: 13px; font-family: "Arial", bold, italic; font-weight: bold; font-style: italic; border: 1px solid #ffa823; color: #0E3168; background: #ffa823; position: relative; text-shadow: 0 1px 0 rgba(255,255,255,.5); cursor: pointer; z-index: 0; }';
176+
css += paypalInput + ':before { content: " "; position: absolute; width: 100%; height: 100%; border-radius: 11px; top: 0; left: 0; background: #ffa823; background: -webkit-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -moz-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -ms-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); z-index: -2; }';
177+
css += paypalInput + ':after { content: " "; position: absolute; width: 98%; height: 60%; border-radius: 40px 40px 38px 38px; top: 0; left: 0; background: -webkit-linear-gradient(top, #fefefe 0%, #fed994 100%); background: -moz-linear-gradient(top, #fefefe 0%, #fed994 100%); background: -ms-linear-gradient(top, #fefefe 0%, #fed994 100%); background: linear-gradient(top, #fefefe 0%, #fed994 100%); z-index: -1; -webkit-transform: translateX(1%);-moz-transform: translateX(1%); -ms-transform: translateX(1%); transform: translateX(1%); }';
178+
css += paypalInput + '.small { padding: 3px 15px; font-size: 12px; }';
179+
css += paypalInput + '.large { padding: 4px 19px; font-size: 14px; }';
180+
181+
styleEl.type = 'text/css';
182+
styleEl.id = 'paypal-button';
183+
184+
if (styleEl.styleSheet) {
185+
styleEl.styleSheet.cssText = css;
186+
} else {
187+
styleEl.appendChild(document.createTextNode(css));
188+
}
189+
190+
document.getElementsByTagName('head')[0].appendChild(styleEl);
191+
}
192+
193+
155194
/**
156195
* Builds the form DOM structure for a button
157196
*
@@ -167,7 +206,7 @@ PAYPAL.apps = PAYPAL.apps || {};
167206
item, child, label, input, key, size, locale, localeText;
168207

169208
form.method = 'post';
170-
form.action = paypalURL;
209+
form.action = paypalURL.replace('{env}', data.items.env.value);
171210
form.className = 'paypal-button';
172211
form.target = '_top';
173212

@@ -229,42 +268,6 @@ PAYPAL.apps = PAYPAL.apps || {};
229268
return form;
230269
}
231270

232-
/**
233-
* Injects button CSS in the <head>
234-
*
235-
* @return {void}
236-
*/
237-
function injectCSS() {
238-
var css, styleEl, paypalButton, paypalInput;
239-
240-
if (document.getElementById('paypal-button')) {
241-
return;
242-
}
243-
244-
css = '';
245-
styleEl = document.createElement('style');
246-
paypalButton = '.paypal-button';
247-
paypalInput = paypalButton + ' button';
248-
249-
css += paypalButton + ' { white-space: nowrap; }';
250-
css += paypalInput + ' { white-space: nowrap; overflow: hidden; border-radius: 13px; font-family: "Arial", bold, italic; font-weight: bold; font-style: italic; border: 1px solid #ffa823; color: #0E3168; background: #ffa823; position: relative; text-shadow: 0 1px 0 rgba(255,255,255,.5); cursor: pointer; z-index: 0; }';
251-
css += paypalInput + ':before { content: " "; position: absolute; width: 100%; height: 100%; border-radius: 11px; top: 0; left: 0; background: #ffa823; background: -webkit-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -moz-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: -ms-linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); background: linear-gradient(top, #FFAA00 0%,#FFAA00 80%,#FFF8FC 100%); z-index: -2; }';
252-
css += paypalInput + ':after { content: " "; position: absolute; width: 98%; height: 60%; border-radius: 40px 40px 38px 38px; top: 0; left: 0; background: -webkit-linear-gradient(top, #fefefe 0%, #fed994 100%); background: -moz-linear-gradient(top, #fefefe 0%, #fed994 100%); background: -ms-linear-gradient(top, #fefefe 0%, #fed994 100%); background: linear-gradient(top, #fefefe 0%, #fed994 100%); z-index: -1; -webkit-transform: translateX(1%);-moz-transform: translateX(1%); -ms-transform: translateX(1%); transform: translateX(1%); }';
253-
css += paypalInput + '.small { padding: 3px 15px; font-size: 12px; }';
254-
css += paypalInput + '.large { padding: 4px 19px; font-size: 14px; }';
255-
256-
styleEl.type = 'text/css';
257-
styleEl.id = 'paypal-button';
258-
259-
if (styleEl.styleSheet) {
260-
styleEl.styleSheet.cssText = css;
261-
} else {
262-
styleEl.appendChild(document.createTextNode(css));
263-
}
264-
265-
document.getElementsByTagName('head')[0].appendChild(styleEl);
266-
}
267-
268271

269272
/**
270273
* Builds the image for a QR code
@@ -289,7 +292,7 @@ PAYPAL.apps = PAYPAL.apps || {};
289292
}
290293

291294
url = encodeURIComponent(url);
292-
img.src = qrCodeURL.replace('{url}', url).replace('{pattern}', pattern).replace('{size}', size);
295+
img.src = qrCodeURL.replace('{env}', data.items.env.value).replace('{url}', url).replace('{pattern}', pattern).replace('{size}', size);
293296

294297
return img;
295298
}

0 commit comments

Comments
 (0)