1
2// Appends the required hidden values to PayPal's form before submitting
3
4populatePayPalForm: function() {
5 var self = this;
6 if( self.$paypalForm.length ) {
7 var $form = self.$paypalForm;
8 var cart = self._toJSONObject( self.storage.getItem( self.cartName ) );
9 var shipping = self.storage.getItem( self.shippingRates );
10 var numShipping = self._convertString( shipping );
11 var cartItems = cart.items;
12 var singShipping = Math.floor( numShipping / cartItems.length );
13
14 $form.attr( "action", self.paypalURL );
15 $form.find( "input[name='business']" ).val( self.paypalBusinessEmail );
16 $form.find( "input[name='currency_code']" ).val( self.paypalCurrency );
17
18 for( var i = 0; i < cartItems.length; ++i ) {
19 var cartItem = cartItems[i];
20 var n = i + 1;
21 var name = cartItem.product;
22 var price = cartItem.price;
23 var qty = cartItem.qty;
24
25 $( "<div/>" ).html( "<input type='hidden' name='quantity_" + n + "' value='" + qty + "'/>" ).
26 insertBefore( "#paypal-btn" );
27 $( "<div/>" ).html( "<input type='hidden' name='item_name_" + n + "' value='" + name + "'/>" ).
28 insertBefore( "#paypal-btn" );
29 $( "<div/>" ).html( "<input type='hidden' name='item_number_" + n + "' value='SKU " + name + "'/>" ).
30 insertBefore( "#paypal-btn" );
31 $( "<div/>" ).html( "<input type='hidden' name='amount_" + n + "' value='" + self._formatNumber( price, 2 ) + "'/>" ).
32 insertBefore( "#paypal-btn" );
33 $( "<div/>" ).html( "<input type='hidden' name='shipping_" + n + "' value='" + self._formatNumber( singShipping, 2 ) + "'/>" ).
34 insertBefore( "#paypal-btn" );
35
36 }
37
38 }
39}
40