0
votes

I am working on stripe to integrate in the website but I am having an issue. There are 2 forms,

  1. Stripe Payment Form

  2. The users Data Form

  3. The Stripe Payment Form works Perfect. When It triggers the Form 2. then Stripe Payment Form's Response again run and it makes Payment again. and I know why this is happening.. Here is the code

    if($_POST) { Stripe::setApiKey($config['secret-key']);

     // POSTed Variables
     $token      = $_POST['stripeToken'];
     $first_name = $_POST['first-name'];
     $last_name  = $_POST['last-name'];
     $name       = $first_name . ' ' . $last_name;
     $amount     = (float) $_POST['amount'];
    
     try {
         if ( ! isset($_POST['stripeToken']) ) {
             throw new Exception("The Stripe Token was not generated correctly");
         }
    
         // Charge the card
         $donation = Stripe_Charge::create(array(
             'card'        => $token,
             'description' => 'Payment by ' . $name,
             'amount'      => $amount * 100,
             'currency'    => 'usd'
         ));
    
         // Build and send the email
    
    
    
    
         // Forward to "Thank You" page
         //header('Location: ' . $config['thank-you']);
         echo 'The Payment Has Been Done';
         exit;
    
     } catch (Exception $e) {
         $error = $e->getMessage();
     }
    

    }

So What I assume is the if($_POST) { this is the issue. It gets all the forms posted. So i want to make it specific to get only the Stripe Fomr's data Only. So i tried it with if(isset($_POST['stripeSubmit'])) And Placing this name to strip Form submit button <input type="submit" name="stripeSubmit" value="Pay"> But It not works. it not even charges with it.

Please help me in this regard

1

1 Answers

0
votes

This isn't really Stripe-related, but rather is about managing your form post data. If you're having trouble distinguishing form submissions from one another, I'd recommend splitting up your handling to two different server endpoints so that the requests are completely separate.

If you want to manage them together, there are other other answers you can refer to about splitting form handling.