[Answered ]-Pass amount from Stripe checkout for to view function in Django

2👍

You’d want to add additional inputs in the form that contains Stripe Checkout to pass additional values back to your controller:

<form action="{% url 'charge' %}" method="POST">
  {% csrf_token %}
  <input type="hidden" name="amount" value="2000"></input?
  <script
    src="https://checkout.stripe.com/checkout.js" class="stripe-button"
    data-key="{{ key }}"
    data-image="/img/documentation/checkout/marketplace.png"
    data-name="Food & beverage Association of San Diego County"
    data-description="Food Handlers Card"
    data-amount="2000"
    data-allow-remember-me="false"
    data-label="Pay As Member">
  </script>
</form>

However that is generally not considered secure as the customer could just modify the amount.

What you generally want to do is pass some information about what the customer is buying (like the SKU / product code) and pass that as the hidden input, or even better save that information in some sort of server-side session state.

Server side you’d access any of these values via the request.POST dictionary such as request.POST['amount']

Leave a comment