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

164
Visualizações
Stripe Subscription Successful with Invalid Card

I am instantiating stripe with composer and attempting to subscribe a customer to a subscription plan in test mode using the card number 4000 0000 0000 0341. The documentation says this will be accepted but then throw an error when used to create a subscription. My questions is, why does the create subscription step always return success with this card number?

My charge code is

<form action="subscribe.php" method="post">
                            <input type="hidden" name="customer" value="<? echo $stripeID ?>">
                            <input type="hidden" name="plan" value="<? echo $thisPlan['id'] ?>">
                            <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
                                    data-key="<?php echo $stripe['publishable_key']; ?>"
                                    data-name="www.example.com"
                                    data-description="<? echo $thisPlan['name'] ?>"
                                    data-amount="<? echo $thisPlan['amount'] ?>"
                                    data-locale="auto"
                                    data-panel-label="Subscribe Now"
                                    data-label="Subscribe"
                                    data-allow-remember-me="false">
                          </script>
                        </form>

and my subscribe.php is

    try {
    $result = \Stripe\Subscription::create(array(
      "customer" => $_POST['customer'],
      "plan" => $_POST['plan']
    ));
  echo "Subscription successful";
}
catch (Stripe\Error\Base $e) {
  // Code to do something with the $e exception object when an error occurs
  echo($e->getMessage());
} catch (Exception $e) {
  // Catch any other non-Stripe exceptions
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The question was why isn't the test card number generating an error response. The answer is in the comments: the customer already had a default card assigned and stripe always uses the default even if a new card is provided in the javascript form. My solution was to update the customer with new card number returned in the token and then apply the subscription:

try {  
    $cu = \Stripe\Customer::retrieve($_POST['customer']);
    $cu->source = $_POST['stripeToken']; // obtained with Stripe.js
    $cu->save();
}

try {
$result = \Stripe\Subscription::create(array(
  "customer" => $_POST['customer'],
  "plan" => $_POST['plan']
));

echo "\nSubscription successful"; }

over 4 years ago · Santiago Trujillo 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