2017-02-19 87 views
1

我的PayPal按鈕(實際上是快速結帳)在https上不起作用,當我通過https訪問我的應用時,我意識到了這一點。PayPal按鈕無法在https上工作

不確定這是我的https阻止此腳本。

<script src="https://www.paypalobjects.com/api/checkout.js" data-version-4></script> 

我沒有問題看到該按鈕被加載到本地主機(開發環境)。但在生產中以https,我得到這個錯誤

ppxo_xc_ppbutton_error Object 

Error: Document is ready and element #paypal-button does not exist 

我使用的角度,這個代碼塊是我的控制器內

paypal.Button.render({ 

     env: 'production', // Optional: specify 'sandbox' environment 

     payment: function() { 

      var env = this.props.env; 
      var client = this.props.client; 

      return paypal.rest.payment.create(env, client, { 
       transactions: [{ 
        amount: { total: 5 , currency: 'USD' }, 
        item_list: { 
        items: [{ 
         "name": "profile", 
         "price": "5", 
         "currency": "USD" 
        }] 
       } 
       }], 
       redirect_urls: { 
       "return_url": $location.absUrl(), 
       "cancel_url": $location.absUrl() 
       } 
      }); 
     }, 

     commit: true, // Optional: show a 'Pay Now' button in the checkout flow 

     onAuthorize: function(data, actions) { 

      return actions.payment.execute().then(function() { 

       actions.payment.get().then(function(data){ 

       if(data.state === 'approved'){ 
        $http.post('/paid',{qty:$scope.number_of_uses,user_email:user_email}) 
        .then(function(response){ 

         $scope.done = true; 

        }); 
       } 

       }); 

      }); 
     } 

    }, '#paypal-button'); 

我再說一遍,它的工作在本地主機罰款,但不是在HTTPS (生產)。

+0

請提供[mcve]。 –

+0

元素'#paypal-button'不存在 – MackieeE

+0

@MackieeE不,它的確如此。它只是不工作在https中,它運行良好,當我在發展URL是http:// localhost:3000 –

回答

0

按鈕實際上是設置了一個角分量爲您提供:

https://github.com/paypal/paypal-checkout/blob/master/docs/frameworks.md#angularjs-element

可能是明智的使用。我懷疑,如果你嘗試直接在角度控制器中渲染,它可能還沒有渲染容器元素,因此你的錯誤。

+0

那麼爲什麼它在http中工作? –

+0

不知道,除非你可以提供一個你正在使用的角碼的例子,也許我可以嘗試一個演示頁面。 – bluepnume

+0

我在角模板完成渲染之前發現了腳本加載。我使用Chrome的網絡工具進行調試,我使用較慢的連接。我把暫停的貝寶功能,現在它的工作。 –

相關問題