0

我正在實施paypal快速結賬按鈕到我開發的wordpress插件。paypal結帳JavaScript錯誤 - this20.getParentTemplate是不是一個功能

我有一個編輯訂單頁面,裏面有一個「確認訂單」按鈕,其中一個彈出式模式消息用於確認結算按鈕的呈現總額。

$("#mdp-order-button").click(function(e){ 
    e.preventDefault(); 
    mdp_render_confirm_modal(); 
}); 

function mdp_render_confirm_modal(){ 
    if (!$("#mdp_upload_image")[0].files[0]){ 
     alert("please upload an image first"); 
    }else{ 
     if(mdp_check_overlap()){ 
      alert("the block is either out of the grid or overlapped with other block, please place it again"); 
     }else{ 
      var current_block = $('.current_block'); 
      var cost = current_block.width() * current_block.height(); 
      $('#mdp-show-size').html("Your block is "+current_block.width()+"px X "+current_block.height()+"px"); 
      $('#mdp-show-cost').html("Total: "+cost); 
      $('#mdp-modal').show(); 
      $('#mdp-close').click(function(){ 
       $('mdp-modal').hide(); 
      }) 
      mdp_render_paypal_button(cost) 
     } 
    } 
} 

function mdp_render_paypal_button(charge) { 

    paypal.Button.render({ 

     env: 'sandbox', // Or 'sandbox' 

     commit: true, // Show a 'Pay Now' button 

     client: { 
      sandbox: 'censored xxxxx' 
     }, 

     payment: function() { 
      return paypal.rest.payment.create(this.props.env, this.props.client, { 
       transactions: [ 
        { 
         amount: { 
          total: charge, 
          currency: 'USD' 
         } 
        } 
       ] 
      }); 
     }, 

     onAuthorize: function(data, actions) { 
      return actions.payment.execute().then(function(response) { 
       console.log(response); 
      }); 
     } 
    }, '#paypal-button'); 
} 

當我點擊結帳按鈕,PayPal的窗口彈出和關閉直線距離,並顯示在控制檯錯誤

checkout.js:4225 ppxo_xc_ppcheckout_destroy Object {timestamp: 1494405598944, windowID: "53bb903148", pageID: "84e2908f4a", host: "www.sandbox.paypal.com", path: "/webapps/hermes/button"…} 
checkout.js:2021 Uncaught Error: _this20.getParentTemplate is not a function 
TypeError: _this20.getParentTemplate is not a function 
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:9346:40) 
    at _loop2 (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1077:62) 
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1107:29) 
    at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1125:18) 
    at Function.syncPromiseTry [as try] (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1170:42) 
    at DelegateComponent.openContainer (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:9342:55) 
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:8556:35) 
    at _loop2 (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1077:62) 
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1107:29) 
    at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1125:18) 
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:9346:40) 
    at _loop2 (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1077:62) 
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1107:29) 
    at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1125:18) 
    at Function.syncPromiseTry [as try] (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1170:42) 
    at DelegateComponent.openContainer (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:9342:55) 
    at Object.onSuccess (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:8556:35) 
    at _loop2 (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1077:62) 
    at SyncPromise.dispatch (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1107:29) 
    at SyncPromise.then (https://www.paypalobjects.com/api/checkout.js?ver=4.7.4:1125:18) 
    at Object._RECEIVE_MESSAGE_TYPE.(anonymous function) [as postrobot_message_response] (https://www.paypalobjects.com/api/checkout.js:2021:118) 
    at receiveMessage (https://www.paypalobjects.com/api/checkout.js:1929:73) 
    at messageListener (https://www.paypalobjects.com/api/checkout.js:1949:13) 

我試圖在網絡上搜索,但我沒有發現類似的問題也沒有文件,我真的不知道爲什麼會發生這種情況。

在此先感謝您的幫助,完全STA

+0

你是如何加載checkout.js?你正在加載一個特定的版本?你可以嘗試在你的控制檯上輸入'paypal.version',讓我知道我 – bluepnume

+0

加載它從貝寶提供的URL直接推薦...我會檢查一次我回家 –

+0

這很可能「https://開頭WWW。 paypalobjects.com/api/checkout.js「,因爲我複製了示例代碼並對其進行了修改,但我會檢查並確保 –

回答

0

謝謝你這麼多@bluepnume幫助。

這是wordpress如何加載腳本的問題,默認情況下,該腳本會將一個查詢字符串?ver ='current_wordpress_version'添加到已加載的腳本中,禁用了該腳本,現在它獲取最新版本的checkout.js

,而不是僅僅

wp_enqueue_script('paypal_checkout', 'https://www.paypalobjects.com/api/checkout.js'); 

現在

wp_enqueue_script('paypal_checkout', 'https://www.paypalobjects.com/api/checkout.js',array(),null);