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

163
Views
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 answers
Answer question

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 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!