1- if ( typeof PAYPAL === ' undefined' || ! PAYPAL ) {
1+ if ( typeof PAYPAL === " undefined" || ! PAYPAL ) {
22 var PAYPAL = { } ;
33}
44
@@ -7,24 +7,25 @@ PAYPAL.apps = PAYPAL.apps || {};
77
88( function ( ) {
99
10- ' use strict' ;
10+ " use strict" ;
1111
1212
1313 var app = { } ,
14- paypalURL = ' https://www.paypal.com/cgi-bin/webscr' ,
15- qrCodeURL = ' https://www.paypal.com/webapps/ppint/qrcode?data={url}&pattern={pattern}&height={size}' ,
16- scriptURL = ' paypal-button.min.js' ,
17- bnCode = ' JavaScriptButton_{type}' ,
14+ paypalURL = " https://www.paypal.com/cgi-bin/webscr" ,
15+ qrCodeURL = " https://www.paypal.com/webapps/ppint/qrcode?data={url}&pattern={pattern}&height={size}" ,
16+ scriptURL = " paypal-button.min.js" ,
17+ bnCode = " JavaScriptButton_{type}" ,
1818 prettyParams = {
19- id : ' hosted_button_id' ,
20- name : ' item_name' ,
21- number : ' item_number' ,
22- lang : 'lc'
19+ id : " hosted_button_id" ,
20+ name : " item_name" ,
21+ number : " item_number" ,
22+ lang : "lc"
2323 } ,
2424 buttonImgs = {
25- buynow : '//www.paypalobjects.com/{locale}/i/btn/btn_buynow_{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'
25+ buynow : "//www.paypalobjects.com/{locale}/i/btn/btn_buynow_{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" ,
28+ subscribe : "//www.paypalobjects.com/{locale}/i/btn/btn_subscribe_{size}.gif"
2829 } ;
2930
3031 if ( ! PAYPAL . apps . ButtonFactory ) {
@@ -34,10 +35,10 @@ PAYPAL.apps = PAYPAL.apps || {};
3435 */
3536 app . config = {
3637 labels : {
37- item_name : ' Item' ,
38- item_number : ' Number' ,
39- amount : ' Amount' ,
40- quantity : ' Quantity'
38+ item_name : " Item" ,
39+ item_number : " Number" ,
40+ amount : " Amount" ,
41+ quantity : " Quantity"
4142 }
4243 } ;
4344
@@ -49,7 +50,8 @@ PAYPAL.apps = PAYPAL.apps || {};
4950 cart : 0 ,
5051 hosted : 0 ,
5152 donate : 0 ,
52- qr : 0
53+ qr : 0 ,
54+ subscribe : 0
5355 } ;
5456
5557 /**
@@ -72,32 +74,35 @@ PAYPAL.apps = PAYPAL.apps || {};
7274 }
7375
7476 // Defaults
75- type = type || ' buynow' ;
77+ type = type || " buynow" ;
7678
7779 // Hosted buttons
7880 if ( data . items . hosted_button_id ) {
79- type = ' hosted' ;
80- data . add ( ' cmd' , ' _s-xclick' ) ;
81+ type = " hosted" ;
82+ data . add ( " cmd" , " _s-xclick" ) ;
8183 // Cart buttons
82- } else if ( type === ' cart' ) {
83- data . add ( ' cmd' , ' _cart' ) ;
84- data . add ( ' add' , true ) ;
84+ } else if ( type === " cart" ) {
85+ data . add ( " cmd" , " _cart" ) ;
86+ data . add ( " add" , true ) ;
8587 // Donation buttons
86- } else if ( type === 'donate' ) {
87- data . add ( 'cmd' , '_donations' ) ;
88+ } else if ( type === "donate" ) {
89+ data . add ( "cmd" , "_donations" ) ;
90+ // Subscribe buttons
91+ } else if ( type === "subscribe" ) {
92+ data . add ( "cmd" , "_xclick-subscriptions" ) ;
8893 // Buy Now buttons
8994 } else {
90- data . add ( ' cmd' , ' _xclick' ) ;
95+ data . add ( " cmd" , " _xclick" ) ;
9196 }
9297
9398 // Add common data
94- data . add ( ' business' , business ) ;
95- data . add ( 'bn' , bnCode . replace ( / \{ t y p e \} / , type ) ) ;
99+ data . add ( " business" , business ) ;
100+ data . add ( "bn" , bnCode . replace ( / \{ t y p e \} / , type ) ) ;
96101
97102 // Build the UI components
98- if ( type === 'qr' ) {
103+ if ( type === "qr" ) {
99104 button = buildQR ( data , data . items . size ) ;
100- data . remove ( ' size' ) ;
105+ data . remove ( " size" ) ;
101106 } else {
102107 button = buildForm ( data , type ) ;
103108 }
@@ -126,36 +131,36 @@ PAYPAL.apps = PAYPAL.apps || {};
126131 * @return {HTMLElement }
127132 */
128133 function buildForm ( data , type ) {
129- var form = document . createElement ( ' form' ) ,
130- btn = document . createElement ( ' input' ) ,
131- hidden = document . createElement ( ' input' ) ,
134+ var form = document . createElement ( " form" ) ,
135+ btn = document . createElement ( " input" ) ,
136+ hidden = document . createElement ( " input" ) ,
132137 items = data . items ,
133138 item , child , label , input , key , size , locale ;
134139
135- btn . type = ' image' ;
136- hidden . type = ' hidden' ;
137- form . method = ' post' ;
140+ btn . type = " image" ;
141+ hidden . type = " hidden" ;
142+ form . method = " post" ;
138143 form . action = paypalURL ;
139- form . className = ' paypal-button' ;
140- form . target = ' _top' ;
144+ form . className = " paypal-button" ;
145+ form . target = " _top" ;
141146
142147 for ( key in items ) {
143148 item = items [ key ] ;
144149
145150 if ( item . isEditable ) {
146- input = document . createElement ( ' input' ) ;
147- input . type = ' text' ;
148- input . className = ' paypal-input' ;
151+ input = document . createElement ( " input" ) ;
152+ input . type = " text" ;
153+ input . className = " paypal-input" ;
149154 input . name = item . key ;
150155 input . value = item . value ;
151156
152- label = document . createElement ( ' label' ) ;
153- label . className = ' paypal-label' ;
154- label . appendChild ( document . createTextNode ( app . config . labels [ item . key ] + ' ' || '' ) ) ;
157+ label = document . createElement ( " label" ) ;
158+ label . className = " paypal-label" ;
159+ label . appendChild ( document . createTextNode ( app . config . labels [ item . key ] + " " || "" ) ) ;
155160 label . appendChild ( input ) ;
156161
157- child = document . createElement ( 'p' ) ;
158- child . className = ' paypal-group' ;
162+ child = document . createElement ( "p" ) ;
163+ child . className = " paypal-group" ;
159164 child . appendChild ( label ) ;
160165 } else {
161166 input = child = hidden . cloneNode ( true ) ;
@@ -173,7 +178,7 @@ PAYPAL.apps = PAYPAL.apps || {};
173178 btn . src = getButtonImg ( type , size , locale ) ;
174179
175180 // If the Mini Cart is present then register the form
176- if ( PAYPAL . apps . MiniCart && data . items . cmd . value === ' _cart' ) {
181+ if ( PAYPAL . apps . MiniCart && data . items . cmd . value === " _cart" ) {
177182 var MiniCart = PAYPAL . apps . MiniCart ;
178183
179184 if ( ! MiniCart . UI . itemList ) {
@@ -196,8 +201,8 @@ PAYPAL.apps = PAYPAL.apps || {};
196201 * @return {HTMLElement }
197202 */
198203 function buildQR ( data , size , locale ) {
199- var img = document . createElement ( ' img' ) ,
200- url = paypalURL + '?' ,
204+ var img = document . createElement ( " img" ) ,
205+ url = paypalURL + "?" ,
201206 pattern = 13 ,
202207 items = data . items ,
203208 item , key ;
@@ -207,11 +212,11 @@ PAYPAL.apps = PAYPAL.apps || {};
207212
208213 for ( key in items ) {
209214 item = items [ key ] ;
210- url += item . key + '=' + encodeURIComponent ( item . value ) + '&' ;
215+ url += item . key + "=" + encodeURIComponent ( item . value ) + "&" ;
211216 }
212217
213218 url = encodeURIComponent ( url ) ;
214- img . src = qrCodeURL . replace ( ' {url}' , url ) . replace ( ' {pattern}' , pattern ) . replace ( ' {size}' , size ) ;
219+ img . src = qrCodeURL . replace ( " {url}" , url ) . replace ( " {pattern}" , pattern ) . replace ( " {size}" , size ) ;
215220
216221 return img ;
217222 }
@@ -229,8 +234,8 @@ PAYPAL.apps = PAYPAL.apps || {};
229234 var img = buttonImgs [ type ] || buttonImgs . buynow ;
230235
231236 // Image defaults
232- locale = locale || ' en_US' ;
233- size = ( size === ' small' ) ? 'SM' : 'LG' ;
237+ locale = locale || " en_US" ;
238+ size = ( size === " small" ) ? "SM" : "LG" ;
234239
235240 return img . replace ( / \{ l o c a l e \} / , locale ) . replace ( / \{ s i z e \} / , size ) ;
236241 }
@@ -249,7 +254,7 @@ PAYPAL.apps = PAYPAL.apps || {};
249254 for ( i = 0 , len = attrs . length ; i < len ; i ++ ) {
250255 attr = attrs [ i ] ;
251256
252- if ( ( matches = / ^ d a t a - ( [ a - z ] + ) ( - e d i t a b l e ) ? / i. exec ( attr . name ) ) ) {
257+ if ( ( matches = / ^ d a t a - ( [ a - z 0 - 9 ] + ) ( - e d i t a b l e ) ? / i. exec ( attr . name ) ) ) {
253258 dataset [ matches [ 1 ] ] = {
254259 value : attr . value ,
255260 isEditable : ! ! matches [ 2 ]
@@ -283,9 +288,9 @@ PAYPAL.apps = PAYPAL.apps || {};
283288
284289
285290 // Init the buttons
286- if ( typeof document !== ' undefined' ) {
291+ if ( typeof document !== " undefined" ) {
287292 var ButtonFactory = PAYPAL . apps . ButtonFactory ,
288- nodes = document . getElementsByTagName ( ' script' ) ,
293+ nodes = document . getElementsByTagName ( " script" ) ,
289294 node , data , type , business , i , len ;
290295
291296 for ( i = 0 , len = nodes . length ; i < len ; i ++ ) {
@@ -295,7 +300,7 @@ PAYPAL.apps = PAYPAL.apps || {};
295300
296301 data = node && getDataSet ( node ) ;
297302 type = data && data . button && data . button . value ;
298- business = node . src . split ( ' ?merchant=' ) [ 1 ] ;
303+ business = node . src . split ( " ?merchant=" ) [ 1 ] ;
299304
300305 if ( business ) {
301306 ButtonFactory . create ( business , data , type , node . parentNode ) ;
@@ -311,6 +316,6 @@ PAYPAL.apps = PAYPAL.apps || {};
311316
312317
313318// Export for CommonJS environments
314- if ( typeof module === ' object' && typeof module . exports === ' object' ) {
319+ if ( typeof module === " object" && typeof module . exports === " object" ) {
315320 module . exports = PAYPAL ;
316321}
0 commit comments