| 1 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * NOTICE OF LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * This source file is subject to the GNU General Public License (GPL 3) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * that is bundled with this package in the file LICENSE.txt | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * DISCLAIMER | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Do not edit or add to this file if you wish to upgrade Payone_Core to newer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * versions in the future. If you wish to customize Payone_Core for your | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * needs please refer to http://www.payone.de for more information. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @category        Payone | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @package         js | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @subpackage      payone | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @copyright       Copyright (c) 2018 <[email protected]> - www.fatchip.de | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author          FATCHIP GmbH <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @link            http://www.fatchip.de | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | var PayoneCheckout = { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     shippingMethodCode: false, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     baseUrl: "", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     chooseMethodUrl: "payone_core/mastercardMasterpass/chooseShippingMethod", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     placeOrderUrl: "payone_core/mastercardMasterpass/placeOrder", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     reloadReviewUrl: "checkout/onepage/review/", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     init: function (baseUrl) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         this.baseUrl = baseUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         var button = jQuery('#placeOrder'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         button.on('click', function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |             window.placeOrder(PayoneCheckout.getPlaceOrderUrl()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         var availableMethods = jQuery('input[type="radio"][name="shipping_method"]'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         if (availableMethods.length > 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             availableMethods.on('click', function (event) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 if (event.currentTarget.checked === true) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                     PayoneCheckout.shippingMethodCode = event.currentTarget.value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                     window.chooseMethod( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |                         PayoneCheckout.getChooseMethodeUrl(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                         PayoneCheckout.shippingMethodCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |             var method = availableMethods.get(0).value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |             window.chooseMethod( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 PayoneCheckout.getChooseMethodeUrl(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                 method | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         this.handlePlaceOrderButton(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         this.reloadReview(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     handlePlaceOrderButton: function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         var availableMethods = jQuery('input[type="radio"][name="shipping_method"]'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         var checkedMethod = availableMethods.filter(':checked'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         if (checkedMethod.length === 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             PayoneCheckout.shippingMethodCode = checkedMethod[0].value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |             jQuery('#placeOrder').attr('disabled', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         } else if (availableMethods.length === 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |             // In case there's only one method that's not already checked | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |             var singleMethod = availableMethods.filter(':first'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |             singleMethod.attr('checked', true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             jQuery('#placeOrder').attr('disabled', false); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             PayoneCheckout.shippingMethodCode = singleMethod[0].value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     reloadReview: function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         jQuery.ajax( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |                 url: this.getReloadReviewUrl(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |                 error: function (result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |                     console.log(result); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |                 }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |                 success: function (result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |                     var review = jQuery(result).filter('#checkout-review-table-wrapper'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |                     var container = jQuery('#checkout-review-load'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |                     container.html(review); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |                     PayoneCheckout.handlePlaceOrderButton(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |                 }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |                 complete: function(request, status) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |                     window.unlockActivity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     getChooseMethodeUrl: function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         return this.baseUrl + this.chooseMethodUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     getPlaceOrderUrl: function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return this.baseUrl + this.placeOrderUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |     getReloadReviewUrl: function () { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         return this.baseUrl + this.reloadReviewUrl; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  | window.chooseMethod = function(url, methodCode) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     window.lockActivity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     jQuery.ajax( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             url: url, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |             data: { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |                 code: methodCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |             }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |             error: function(result) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |                 window.unlockActivity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |                 alert('An error occurred during the Masterpass Checkout.'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |             }, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |             success: function (result) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |                 var response = JSON.parse(result); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |                 if (response.code !== 200) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |                     window.unlockActivity(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |                     alert(response.data.message); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |                     return; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |                 PayoneCheckout.reloadReview(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  | }; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 131 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  | window.placeOrder = function (url) { | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |     var agreementCollection = jQuery("[id^=agreement-]"); | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |     var agreement = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |     agreementCollection.each(function() { | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |         if (this.checked) { | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |             var index = $(this).attr("name").match(/.*\[(.*)\]/); | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |             if (index.length > 1) { | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |                 agreement.push(index[1]); | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |     }); | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |     window.lockActivity(); | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |     jQuery.ajax( | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |         { | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |             url: url, | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |             data: { | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |                 agreement: agreement | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |             }, | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |             error: function(result) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |                 window.unlockActivity(); | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |                 alert('An error occurred during the Masterpass Checkout.'); | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |             }, | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |             success: function (result) { | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |                 window.unlockActivity(); | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |                 var response = JSON.parse(result); | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |                 if (response.code !== 200) { | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |                     alert(response.data.message); | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  |                     return; | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |                 window.location = response.data.redirectUrl; | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |     ); | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  | window.lockActivity = function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |     var fadeOut = jQuery('.fadeOut'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     fadeOut.show(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  | }; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  | window.unlockActivity = function() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |     var fadeOut = jQuery('.fadeOut'); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 176 |  |  |     fadeOut.hide(); | 
            
                                                        
            
                                    
            
            
                | 177 |  |  | }; |