Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
static amount not variable

how can i send variable amount on my line item as it only accept integers please rest everything works but this varible amount is not working tried $params->amount not working

<?php

require_once('vendor/autoload.php');
\Stripe\Stripe::setApiKey('sk_test_key');

$session = \Stripe\Checkout\Session::create([
    'payment_method_types' => ['card'],
    'line_items' => [[
      'price_data' => [
        'currency' => 'usd',
        'product_data' => [
          'name' => 'T-shirt',
        ],
        'unit_amount' => 2000,
      ],
      'quantity' => 1,
    ]],
    'mode' => 'payment',
    'success_url' => 'https://example.com/success',
    'cancel_url' => 'https://example.com/cancel',
  ]);

?>

<html>
  <head>
    <title>Buy cool new product</title>
    <script src="https://js.stripe.com/v3/"></script>
  </head>
  <body>
      <div class="field">

      <label for="amount">Amount to pay</label>
      <input type="number" id="amount" step="0.01" value="5.00">
      </div>
      <button id="checkout-button">Checkout</button>
      <script>
          var stripe = Stripe('pk_test_51JWkHLK7X12cK8Ptf5y5DQn6Ugf6miu3AqSuhH9wdLsyTB9ouf0TY31vDQxq19xIt6YH76uMTEX1kU9HMyrcEb6w00MTxHnGxc');
          var amount = document.getElementById('amount');
          const btn = document.getElementById("checkout-button")
          btn.addEventListener('click', function(e) {
              e.preventDefault();
              stripe.redirectToCheckout({
                sessionId: "<?php echo $session->id; ?>"            
          });
          })
          
      </script>
  </body>
</html>

how can i send variable amount on my line item as it only accept integers please rest everything works but this varible amount is not working tried $params->amount not working

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The code to create the payment intent with your secret key needs to be run server-side - you must not use your secret key in client-side code.

You should follow the guide here to see how you can generate a payment intent and provide the secret key in a server rendered template, or you can make an async request to your server from an SPA to get a payment intent client secret. The guide goes through both options.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!