2016-12-13 14 views
1

合計金額をHTMLからストライプに渡すのが難しいです。私はcart.jsで合計が計算されるカートを持っています。私はindex.phpから表示しています。私は、ストライプを使用してカートの合計金額を請求します。私はcheckout.phpに量を渡す方法がわかりません。カートの合計金額をhtml/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)); 

答えて

1

クライアント側に課金する必要がある量を計算することは非常に悪い考えです。悪意のある顧客がサーバーに送信する金額を減らすことは些細なことです。金額が顧客のブラウザによって提供される唯一のシナリオは、金額が顧客によって直接選択された場合(たとえば、寄付を受け入れる場合)です。

独自のカートシステムを作成している場合は、フロントエンドにプロダクトIDと数量のリストをバックエンドに送信し、ローカルデータベースから各製品の価格を取得することでその額を計算できます。

関連する問題