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 */
77if ( 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 ( / \{ t y p e \} / , 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