How to pass cart total amount from html/php to Stripe where cart total is calculated by JS

Jason90

I am having difficulty passing total amount from html to stripe. I have a cart whose total is calculated in cart.js. I am displaying it from index.php. I want to charge the total amount which is the cart total using Stripe. I am not sure how to pass in amount to checkout.php.

checkout.php

// Get the credit card details submitted by the form
   $token = $_POST['stripeToken'];
// Create a Customer
   $customer = \Stripe\Customer::create(array(
   "source" => $token,
   "description" => "Example customer")
);
// Charge the Customer instead of the card
  \Stripe\Charge::create(array(
  "amount" => $amount, // Amount in cents
  "currency" => "usd",
  "customer" => $customer->id)
);


index.php
 <div class="total">
  <p class="value">
   <!-- value inserted by js -->
  </p>
  <p class="label">Total</p>
 </div>

 <form action="./checkout.php" method="post">
 <script src="https://checkout.stripe.com/checkout.js" 
  class="stripe-button"
  data-key="<?php echo $stripe['publishable_key']; ?>"
  data-image="https://something.png"
  data-name="nairteashop.org"
  data-description="Send lots of love"
  data-billing-address="true"
  data-label="Checkout"> </script> 
 </form>

cart.js

var $bagTotal = $('.total .value');
$bagTotal.addClass('total_price');
$bagTotal.text('$' + getTotalPrice(items));
Ywain

Computing the amount that needs to be charged client-side is a very bad idea. It would be trivial for a malicious customer to send a reduced amount to your server. The only scenario in which the amount should be provided by the customer's browser is when the amount is directly chosen by the customer (e.g. if you're accepting donations).

If you're writing your own cart system, you probably want to have the frontend send a list of product IDs and quantities to your backend, which can then compute the amount by retrieving each product's price from your local database.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get total weight from cart prestashop

From Dev

How to calculate the total amount when checkbox is cheked and item added to cart?

From Dev

Modify cart total amount with filter or hook

From Dev

How to add discount to cart total?

From Dev

How to Return a Shopping Cart Total

From Dev

How to add discount to cart total?

From Dev

How to calculate total in cart for each item selected from php?

From Dev

Get total cart woocommerce

From Dev

WooCommerce: Change payment gateway if Cart Total amount = 0

From Dev

WooCommerce: Change payment gateway if Cart Total amount = 0

From Dev

How to display shopping cart total in Prestashop 1.6

From Dev

How to add total sum to woocommerce cart section

From Dev

Cart Discount when applied to the cart doesn't show the correct amount in Order Total using Woocommerce in wordpress

From Dev

Cart total not updating with overridden cart prices

From Dev

foundation add shopping cart total

From Dev

Calculating cart total using jQuery

From Dev

Cart total price Override in WooCommerce

From Dev

knockout.js.com Cart editor example - add total tax

From Dev

Magento 2 - How to get cart items total in header.phtml

From Dev

how to compute the dynamic price of items in cart and output the total

From Dev

How to get a DateTime from total amount of seconds?

From Dev

How to get a DateTime from total amount of seconds?

From Dev

How to display both of total order sale price and regular price (or total discount price) in cart page in woocommerce

From Dev

Update magento cart total before saving order

From Java

Disable payment methods based on WooCommerce cart total

From Java

Restrict total cart quantity to specific multiples in WooCommerce

From Dev

php shopping cart -group by selection and get the total

From Dev

Magento Subtotal and grand Total is Empty in Cart Page

From Dev

WooCommerce - Ajax Add To Cart and Update Total

Related Related

  1. 1

    How to get total weight from cart prestashop

  2. 2

    How to calculate the total amount when checkbox is cheked and item added to cart?

  3. 3

    Modify cart total amount with filter or hook

  4. 4

    How to add discount to cart total?

  5. 5

    How to Return a Shopping Cart Total

  6. 6

    How to add discount to cart total?

  7. 7

    How to calculate total in cart for each item selected from php?

  8. 8

    Get total cart woocommerce

  9. 9

    WooCommerce: Change payment gateway if Cart Total amount = 0

  10. 10

    WooCommerce: Change payment gateway if Cart Total amount = 0

  11. 11

    How to display shopping cart total in Prestashop 1.6

  12. 12

    How to add total sum to woocommerce cart section

  13. 13

    Cart Discount when applied to the cart doesn't show the correct amount in Order Total using Woocommerce in wordpress

  14. 14

    Cart total not updating with overridden cart prices

  15. 15

    foundation add shopping cart total

  16. 16

    Calculating cart total using jQuery

  17. 17

    Cart total price Override in WooCommerce

  18. 18

    knockout.js.com Cart editor example - add total tax

  19. 19

    Magento 2 - How to get cart items total in header.phtml

  20. 20

    how to compute the dynamic price of items in cart and output the total

  21. 21

    How to get a DateTime from total amount of seconds?

  22. 22

    How to get a DateTime from total amount of seconds?

  23. 23

    How to display both of total order sale price and regular price (or total discount price) in cart page in woocommerce

  24. 24

    Update magento cart total before saving order

  25. 25

    Disable payment methods based on WooCommerce cart total

  26. 26

    Restrict total cart quantity to specific multiples in WooCommerce

  27. 27

    php shopping cart -group by selection and get the total

  28. 28

    Magento Subtotal and grand Total is Empty in Cart Page

  29. 29

    WooCommerce - Ajax Add To Cart and Update Total

HotTag

Archive