SHOW:
|
|
- or go back to the newest paste.
| 1 | - | /* This is my paypal.js code */ |
| 1 | + | (function() |
| 2 | - | (function() |
| 2 | + | |
| 3 | var paypalButtonData = {};
| |
| 4 | ||
| 5 | var returnDropdownPaypalButton = function( buttonData ) | |
| 6 | - | CKEDITOR.dialog.add( 'paypalChooseButton', function( editor ) |
| 6 | + | |
| 7 | var costLength = Object.keys(buttonData.cost).length; | |
| 8 | ||
| 9 | var priceOptions = '<select name="amount" value="0">'; | |
| 10 | ||
| 11 | for (var i = 0; i < costLength; i++) | |
| 12 | {
| |
| 13 | priceOptions += '<option value="' + buttonData.cost[i].cost + '">' + buttonData.cost[i].description + '</option>'; | |
| 14 | - | contents : [ |
| 14 | + | |
| 15 | ||
| 16 | priceOptions += '</select>'; | |
| 17 | ||
| 18 | return '<form method="post" action="https://www.paypal.com/cgi-bin/webscr" class="paypal-button" target="_top" style="opacity: 1;">' + | |
| 19 | '<input type="hidden" name="button" value="buynow">' + | |
| 20 | '<input type="hidden" name="business" value="'+ buttonData.account +'">' + | |
| 21 | '<input type="hidden" name="item_name" value="'+ buttonData.itemName +'">' + | |
| 22 | '<input type="hidden" name="quantity" value="1">' + | |
| 23 | priceOptions + | |
| 24 | '<input type="hidden" name="currency_code" value="'+ buttonData.currency +'">' + | |
| 25 | - | label: lang.labelButtontype + ' *', |
| 25 | + | '<input type="hidden" name="no_shipping" value="' + buttonData.shipping + '">' + |
| 26 | - | items: [ ['Please select one:', ''],['Single Item', 'paypalCreateSingleButton'],['Multi Choice Button', 'paypalCreateMultiButton']], |
| 26 | + | '<input type="hidden" name="shipping" value="'+ buttonData.shippingRate +'">' + |
| 27 | '<input type="hidden" name="tax" value="">' + | |
| 28 | '<input type="hidden" name="return" value="http://' + window.location.hostname + '/paypal/checkout' + '">' + | |
| 29 | - | if( this.getValue() === '' ) |
| 29 | + | '<input type="hidden" name="cancel_return" value="http://' + window.location.hostname + '/paypal/checkout' + '">' + |
| 30 | '<input type="hidden" name="notify_url" value="http://' + window.location.hostname + '/paypal/ipn' + '">' + | |
| 31 | '<input type="hidden" name="cmd" value="_xclick">' + | |
| 32 | '<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">' + | |
| 33 | '<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal – The safer, easier way to pay online.">' + | |
| 34 | '<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">' + | |
| 35 | '</form>'; | |
| 36 | }; | |
| 37 | - | paypalButtonData.buttonType = this.getValue(); |
| 37 | + | |
| 38 | var returnPaymentInputs = function( numberOfInputs ) | |
| 39 | {
| |
| 40 | var returnString = ''; | |
| 41 | ||
| 42 | for (var i = 0; i < numberOfInputs; i++) | |
| 43 | {
| |
| 44 | returnString += '<input data-key="'+i+'" data-property="description" class="cke_dialog_ui_input_text" type="text" placeholder="Item '+ (i + 1) +' Description" style="margin-right:10px;width:60% !important;"><input data-key="'+i+'" data-property="cost" class="cke_dialog_ui_input_text input-xsmall" type="text" placeholder="Item' + (i + 1) +' Price" style="margin-right:10px;width:30% !important;"><br>'; | |
| 45 | }; | |
| 46 | ||
| 47 | return returnString; | |
| 48 | }; | |
| 49 | ||
| 50 | CKEDITOR.dialog.add( 'paypalCreateMultiButton', function( editor ) | |
| 51 | - | console.log( paypalButtonData ); |
| 51 | + | |
| 52 | - | editor.openDialog( paypalButtonData.buttonType ); |
| 52 | + | |
| 53 | ||
| 54 | - | }, |
| 54 | + | |
| 55 | - | onShow: function() |
| 55 | + | |
| 56 | minWidth : 300, | |
| 57 | - | paypalButtonData = {};
|
| 57 | + | |
| 58 | - | document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = ''; |
| 58 | + | contents: [ |
| 59 | {
| |
| 60 | id: 'paypal1', | |
| 61 | label: '', | |
| 62 | title: '', | |
| 63 | expand: false, | |
| 64 | padding: 0, | |
| 65 | elements: [ | |
| 66 | {
| |
| 67 | type: 'text', | |
| 68 | id: 'CKpaypal-merchantEmail', | |
| 69 | label: lang.labelMerchantEmail + ' *', | |
| 70 | validate: function() | |
| 71 | {
| |
| 72 | if( !this.getValue() ) | |
| 73 | {
| |
| 74 | document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = lang.validateMerchantEmail; | |
| 75 | return false; | |
| 76 | }; | |
| 77 | }, | |
| 78 | commit: function() | |
| 79 | {
| |
| 80 | paypalButtonData.account = this.getValue(); | |
| 81 | } | |
| 82 | }, | |
| 83 | {
| |
| 84 | type: 'text', | |
| 85 | id: 'CKpaypal-itemName', | |
| 86 | label: lang.labelitemName + ' *', | |
| 87 | commit: function() | |
| 88 | {
| |
| 89 | paypalButtonData.itemName = this.getValue(); | |
| 90 | } | |
| 91 | }, | |
| 92 | {
| |
| 93 | type: 'select', | |
| 94 | id: 'CKpaypal-currency', | |
| 95 | label: lang.labelcurrency + ' *', | |
| 96 | items: [ ['Please select one:'],['CAD'],['EUR'],['GBP'],['NZD'],['USD'] ], | |
| 97 | validate: function() | |
| 98 | {
| |
| 99 | if( this.getValue() === 'Please select one:' ) | |
| 100 | {
| |
| 101 | document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = lang.validatecurrency; | |
| 102 | return false; | |
| 103 | }; | |
| 104 | }, | |
| 105 | commit: function() | |
| 106 | {
| |
| 107 | paypalButtonData.currency = this.getValue(); | |
| 108 | } | |
| 109 | }, | |
| 110 | {
| |
| 111 | type: 'select', | |
| 112 | id: 'CKpaypal-priceOptions', | |
| 113 | label: lang.labelpriceoptions + ' *', | |
| 114 | labelStyle: 'margin-top:10px;float:left;', | |
| 115 | inputStyle: 'margin-top:5px;float:left;width:100%;', | |
| 116 | items: [ ['Please select the number of price options'], ['1'], ['2'], ['3'], ['4'], ['5'] ], | |
| 117 | onChange: function( api ) | |
| 118 | {
| |
| 119 | var value = this.getValue(), | |
| 120 | priceOptions = ''; | |
| 121 | ||
| 122 | if( value === '' || value === 'Please select the number of price options this item has' ) | |
| 123 | {
| |
| 124 | return false; | |
| 125 | }; | |
| 126 | ||
| 127 | value = parseInt( value ); | |
| 128 | ||
| 129 | priceOptions = returnPaymentInputs( value ); | |
| 130 | ||
| 131 | document.getElementById( 'CKpaypal-priceOptionsContainer' ).innerHTML = priceOptions; | |
| 132 | return; | |
| 133 | }, | |
| 134 | commit: function() | |
| 135 | {
| |
| 136 | paypalButtonData.cost = {};
| |
| 137 | ||
| 138 | var div = document.getElementById( 'CKpaypal-priceOptionsContainer' ); | |
| 139 | var inputs = div.getElementsByTagName( 'input' ); | |
| 140 | ||
| 141 | for (var i = 0; i < inputs.length; i++) | |
| 142 | {
| |
| 143 | var key = inputs[i].getAttribute( 'data-key' ), | |
| 144 | property = inputs[i].getAttribute( 'data-property' ), | |
| 145 | value = inputs[i].value ? inputs[i].value : '0'; | |
| 146 | ||
| 147 | if( !paypalButtonData.cost.hasOwnProperty(key) ) | |
| 148 | {
| |
| 149 | paypalButtonData.cost[key] = {};
| |
| 150 | }; | |
| 151 | ||
| 152 | paypalButtonData.cost[key][property] = value; | |
| 153 | }; | |
| 154 | } | |
| 155 | }, | |
| 156 | {
| |
| 157 | type: 'html', | |
| 158 | html: '<div id="CKpaypal-priceOptionsContainerOuter" style="min-height:50px;width:100%;float:left;margin:10px 0;">' + | |
| 159 | '<div style="width:60%;margin-right:10%;float:left;">Item Description</div><div style="width:30%;float:left;">Item Cost</div>' + | |
| 160 | '<div id="CKpaypal-priceOptionsContainer" style="width:100%;float:left;">' + | |
| 161 | '</div>' + | |
| 162 | '</div>' | |
| 163 | }, | |
| 164 | {
| |
| 165 | type: 'select', | |
| 166 | id: 'CKpaypal-shipping', | |
| 167 | label: lang.labelshipping + '*', | |
| 168 | items: [ ['Please select one:'],['yes'],['no'] ], | |
| 169 | validate: function() | |
| 170 | {
| |
| 171 | if( this.getValue() === 'Please select one:' ) | |
| 172 | {
| |
| 173 | document.getElementById( 'CKpaypal-validationMessages' ).innerHTML = lang.validateshipping; | |
| 174 | return false; | |
| 175 | }; | |
| 176 | }, | |
| 177 | commit: function() | |
| 178 | {
| |
| 179 | var shippingValue = this.getValue(); | |
| 180 | paypalButtonData.shipping = ( this.getValue() === 'yes' ? 2 : 1 ); | |
| 181 | } | |
| 182 | }, | |
| 183 | {
| |
| 184 | type: 'text', | |
| 185 | id: 'CKpaypal-shippingRate', | |
| 186 | label: lang.labelshippingRate + ' *', | |
| 187 | labelStyle: 'margin-top:10px;float:left', | |
| 188 | inputStyle: 'float:left', | |
| 189 | commit: function() | |
| 190 | {
| |
| 191 | paypalButtonData.shippingRate = ( this.getValue() ? this.getValue() : 0 ); | |
| 192 | } | |
| 193 | }, | |
| 194 | {
| |
| 195 | type: 'html', | |
| 196 | html: '<div id="CKpaypal-validationMessages" style="color:red;font-weight:bold;margin-top:20px;"></div>' | |
| 197 | } | |
| 198 | ] | |
| 199 | } | |
| 200 | ], | |
| 201 | onOk: function() | |
| 202 | {
| |
| 203 | this.commitContent(); | |
| 204 | ||
| 205 | var paypalButton = returnDropdownPaypalButton( paypalButtonData ); | |
| 206 | ||
| 207 | editor.insertHtml(paypalButton); | |
| 208 | return; | |
| 209 | } | |
| 210 | } | |
| 211 | ||
| 212 | }); | |
| 213 | ||
| 214 | })(); |