jalendport / craft-stripecheckout

Bringing the power of Stripe Checkout to your Craft templates.
MIT License
43 stars 9 forks source link

Dynamically update amount? #5

Closed bjerenec closed 6 years ago

bjerenec commented 6 years ago

Do you know if there is a way to update (dynamically with js) amount to be charged? I tried to update data-amount on script element but it doesn't seem to work. Any idea would be appreciated. And thanks for great plugin!

lukeyouell commented 6 years ago

@bjerenec the data-* values don't really have much to do with the charge process. The Stripe parameters are encrypted and placed inside of a hidden input field, which are then decrypted before placing the charge request.

So to answer your question, the only way to dynamically update the amount would be to do so on page load. You could achieve this by setting the amount as a query parameter:

https://www.yoursite.com/foobar?amount=100
{% set amount = craft.app.request.getQueryParam('amount') %}

{{ craft.stripeCheckout.checkoutOptions({
     amount: amount
}) }}