Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda