Laravel集成Stripe支付网关扣费金额异常问题求助
Hey there! I’ve run into this exact snag a few times when integrating Stripe with Laravel, so let’s break down the most likely reasons your charge amounts are off and how to fix them:
Common Culprits & Fixes
1. You’re Using the Wrong Currency Unit
Stripe requires all amounts to be passed in the smallest unit of your currency (e.g., cents for USD/EUR, pence for GBP). This is the #1 reason for incorrect charges—many developers accidentally pass the full dollar/euro amount instead of converting it first.
Frontend Check:
Make sure your JavaScript converts the user-facing amount to the smallest unit before sending it to Stripe (or your backend). For example:
// ❌ Wrong: Passing $10 as "10" (charges 10 cents instead) stripe.createToken(card, { amount: 10 }).then((result) => { // Handle token submission }); // ✅ Correct: Convert $10 to 1000 cents const userInputAmount = document.getElementById('amount').value; const amountInSmallestUnit = Math.round(parseFloat(userInputAmount) * 100); stripe.createToken(card, { amount: amountInSmallestUnit }).then((result) => { // Submit token and converted amount to your Laravel backend });
2. Backend Amount Mismatch
Even if your frontend sends the correct amount, double-check that your Laravel backend isn’t modifying it incorrectly before sending to Stripe.
Backend Check:
Verify your charge creation code uses the correct amount value (and matches the currency you’re using):
// ❌ Wrong: Using the raw dollar amount instead of cents $charge = \Stripe\Charge::create([ 'amount' => $request->input('amount'), // If this is "10", it charges 10 cents 'currency' => 'usd', 'source' => $request->input('stripeToken'), 'description' => 'Order Payment', ]); // ✅ Correct: Using the pre-converted smallest unit amount $charge = \Stripe\Charge::create([ 'amount' => $request->input('amount_in_cents'), // Should be "1000" for $10 'currency' => 'usd', 'source' => $request->input('stripeToken'), 'description' => 'Order Payment', ]);
3. Currency Code Inconsistency
Ensure your frontend and backend are using the same currency code (e.g., don’t use usd in frontend and eur in backend). A value of 1000 means $10 USD but €10 EUR—two very different amounts!
4. Unintended Amount Modifications
Check if your backend is applying extra calculations (like taxes, discounts, or shipping) that aren’t reflected in the amount sent to Stripe. For example:
- If your order total is $10 + $2 tax = $12, make sure you’re sending 1200 cents to Stripe, not just the base $10.
Debugging Steps to Confirm
- Log the amount values: Add logging in your Laravel controller to see exactly what’s being sent to Stripe:
Check youruse Illuminate\Support\Facades\Log; Log::info('Stripe Charge Details', [ 'amount_sent_to_stripe' => $request->input('amount_in_cents'), 'currency' => 'usd', 'order_total' => $yourOrderTotalInCents, ]);storage/logs/laravel.logfile to cross-verify values. - Check Stripe Dashboard: Go to your Stripe Dashboard’s Charges section—look at the amount listed there (it shows both the smallest unit and formatted amount) to see exactly what’s being processed.
内容的提问来源于stack exchange,提问作者Wai Yan Hein

