2015-01-18 9 views
6

मैं एक django वेबसाइट में स्ट्रिप लागू कर रहा हूं और सब कुछ एक भाग को छोड़कर काम कर रहा है। मेरे कार्ट में, उपयोगकर्ता उन आइटम्स को अपडेट कर सकते हैं जो कुल में बदलते हैं। Stripe Checkout जेएस स्क्रिप्ट पर डेटा-राशि सेट करने के अलावा सब कुछ ठीक से काम कर रहा है।अद्यतन स्ट्रिप डेटा-राशि

जब पृष्ठ लोड होता है, तो सबकुछ बढ़िया काम करता है, हालांकि यदि ग्राहक अपने कार्ट को बदलता है, तो डेटा-राशि अपडेट नहीं होती है। मेरे पास एक और बॉक्स है जो कुल दिखाता है, और वह राशि ठीक से अपडेट होती है।

<!-- here is the script tag in HTML--> 
<script 
id="stripe-script" 
src="https://checkout.stripe.com/checkout.js" 
class="stripe-button" 
data-image="{% static 'img/marketplace.png' %}" 
data-key="{{ STRIPE_PUBLIC_KEY }}" 
data-name="Serendipity Artisan Blends" 
data-description="Purchase Items" 
data-amount="{{ cart_stripe_total }}"> 
</script> 

और फिर मेरी जावास्क्रिप्ट कि अद्यतन करने के लिए प्रयास करता है यह है:

function updateTotal(amount) { 
    /* update the total in the cart in both the table cell and 
     in the stripe button data-amount */ 
    var totalStr = shoppingTotalCell.text().replace('$', ''), 
     originalTotal = parseFloat(totalStr), 
     newTotal = originalTotal + amount, 
     newTotalStripe = newTotal * 100, 
     newTotalStr = newTotal.toFixed(2), 
     script = $('#stripe-script'); 

    shoppingTotalCell.text('$' + newTotalStr); 

    console.log(script.data("amount")); 
    // this returns the correct original amount 

    script.data("amount", newTotalStripe); 

    console.log(script.data("amount")); 
    /* this returns the updated amount, however the HTML data-amount 
     attribute does not update. */ 
    } 

उत्तर

19

बाहर कर देता है कि धारी भुगतान के लिए एक गतिशील डेटा-राशि है करने के लिए, आप सरल चेकआउट के बजाय Custom Checkout उपयोग करना होगा। इस कोड ने चाल की थी।

 <button class="btn btn-primary btn-lg" id="stripe-button"> 
     Checkout <span class="glyphicon glyphicon-shopping-cart"></span> 
     </button> 

     <script> 
     $('#stripe-button').click(function(){ 
      var token = function(res){ 
      var $id = $('<input type=hidden name=stripeToken />').val(res.id); 
      var $email = $('<input type=hidden name=stripeEmail />').val(res.email); 
      $('form').append($id).append($email).submit(); 
      }; 

      var amount = $("#stripeAmount").val(); 
      StripeCheckout.open({ 
      key:   '{{ STRIPE_PUBLIC_KEY }}', 
      amount:  amount, 
      name:  'Serendipity Artisan Blends', 
      image:  '{% static "img/marketplace.png" %}', 
      description: 'Purchase Products', 
      panelLabel: 'Checkout', 
      token:  token 
      }); 

      return false; 
     }); 
     </script> 
+0

आप के लिए भगवान धन्यवाद! – sgrutman978

संबंधित मुद्दे