贝宝结帐页面未加载

时间:2019-08-26 05:00:22

标签: javascript php html dom paypal

我创建了一个变量,以携带发送到结帐页面的金额值。看来结帐经验无法识别变量。

 <input type="number" id="challenge_stake" name="stake"  required = "true" />     
<button type="button"  data-toggle="modal" data-target="#myModal2" onclick="myFunction();">Pay Now</button> 
 ...  
         <div id="paypal-button-container">

         </div>

         <input name="forPaypal" type="number" value="0" id="forPaypal">           

<script>
    var x = parseFloat(document.getElementById('forPaypal').value);     
    paypal.Buttons({
        // Set up the transaction
        createOrder: function(data, actions) {
            return actions.order.create({
                purchase_units: [{
                    amount: {
                        value: x
                    }
                }]
            });
        }).render('#paypal-button-container');
</script>

<script> function myFunction() {
            var amount = 
parseFloat(document.getElementById('challenge_stake').value);         
document.getElementById('forPaypal').value = amount;
    }

</script>

1 个答案:

答案 0 :(得分:1)

根据您的代码,x的值将始终为0。将您的createOrder函数更改为以下内容:


createOrder: function(data, actions) {
   return actions.order.create({
       purchase_units: [{
           amount: {
               value: parseFloat(document.getElementById('forPaypal').value)
           }
       }]
   }
}