相同金额收取多个条带结账表格

时间:2017-08-23 10:20:09

标签: javascript php forms checkout

我在网页上有3个结帐表单,让用户在3个计划中选择(9,99 - 29,99 - 49,99)。它们中的每一个都由不同的PHP脚本处理,但无论用户选择哪个计划,最后的计划总是被处理(49,99)。 所以我正在寻找解决这个问题的解决方案。

由于

<div class="row m-t-30">

    <!--Pricing Column-->
    <article class="pricing-column col-md-4">
        <div class="inner-box">
            <div class="plan-header text-center">
                <h3 class="plan-title">Up to 10 members</h3>
                <h2 class="plan-price">9.99€</h2>
                <div class="plan-duration">Per Month</div>
            </div>
            <div class="text-center">
                <form id="formplan1" action="scripts/process-payment-plan1.php" method="POST">
                    <input type="hidden" id="stripeToken1" name="stripeToken1" />
                    <input type="hidden" id="stripeEmail1" name="stripeEmail1" />
                    <script src="https://checkout.stripe.com/checkout.js"></script>
                    <button id="pay1" class="btn btn-custom btn-bordred waves-effect waves-light">Choose Plan</button>
                    <script>
                        var handler = StripeCheckout.configure({
                            key: 'pk_test_fC2yWHeQJA93fFr0MlnKrAW4',
                            image: '../assets/img/logos/Logo_1_01.png',
                            locale: 'auto',
                            token: function(token) {
                                $("#stripeToken1").val(token.id);
                                $("#stripeEmail1").val(token.email);
                                $("#formplan1").submit();
                                // You can access the token ID with `token.id`.
                                // Get the token ID to your server-side code for use.
                            }
                        });

                        document.getElementById('pay1').addEventListener('click', function(e) {
                            // Open Checkout with further options:
                            handler.open({
                                name: 'Subscription',
                                description: 'Up to 10 members',
                                zipCode: false,
                                amount: 999,
                                currency: 'EUR',
                                allowrememberme: true,
                                email: '<?php echo $userinfo['
                                UserEmail '] ;?>',
                            });
                            e.preventDefault();
                        });

                        // Close Checkout on page navigation:
                        window.addEventListener('popstate', function() {
                            handler.close();
                        });
                    </script>
                </form>
            </div>
        </div>
    </article>

    <!--Pricing Column-->
    <article class="pricing-column col-md-4">
        <div class="inner-box">
            <div class="plan-header text-center">
                <h3 class="plan-title">From 11 to 40 members</h3>
                <h2 class="plan-price">29.99€</h2>
                <div class="plan-duration">Per Month</div>
            </div>
            <div class="text-center">
                <form id="formplan2" action="scripts/process-payment-plan2.php" method="POST">
                    <input type="hidden" id="stripeToken2" name="stripeToken2" />
                    <input type="hidden" id="stripeEmail2" name="stripeEmail2" />
                    <script src="https://checkout.stripe.com/checkout.js"></script>
                    <button id="pay2" class="btn btn-custom btn-bordred waves-effect waves-light">Choose Plan</button>
                    <script>
                        var handler = StripeCheckout.configure({
                            key: 'pk_test_fC2yWHeQJA93fFr0MlnKrAW4',
                            image: '../assets/img/logos/Logo_1_01.png',
                            locale: 'auto',
                            token: function(token) {
                                $("#stripeToken2").val(token.id);
                                $("#stripeEmail2").val(token.email);
                                $("#formplan2").submit();
                                // You can access the token ID with `token.id`.
                                // Get the token ID to your server-side code for use.
                            }
                        });

                        document.getElementById('pay2').addEventListener('click', function(e) {
                            // Open Checkout with further options:
                            handler.open({
                                name: 'Subscription',
                                description: 'From 11 to 40 members',
                                zipCode: false,
                                amount: 2999,
                                currency: 'EUR',
                                allowrememberme: true,
                                email: '<?php echo $userinfo['
                                UserEmail '] ;?>',
                            });
                            e.preventDefault();
                        });

                        // Close Checkout on page navigation:
                        window.addEventListener('popstate', function() {
                            handler.close();
                        });
                    </script>
                </form>
            </div>
        </div>
    </article>

    <!--Pricing Column-->
    <article class="pricing-column col-md-4">
        <div class="inner-box">
            <div class="plan-header text-center">
                <h3 class="plan-title">From 41 to 100 members</h3>
                <h2 class="plan-price">49.99€</h2>
                <div class="plan-duration">Per Month</div>
            </div>
            <div class="text-center">
                <form id="formplan3" action="scripts/process-payment-plan3.php" method="POST">
                    <input type="hidden" id="stripeToken3" name="stripeToken3" />
                    <input type="hidden" id="stripeEmail3" name="stripeEmail3" />
                    <script src="https://checkout.stripe.com/checkout.js"></script>
                    <button id="pay3" class="btn btn-custom btn-bordred waves-effect waves-light">Choose Plan</button>
                    <script>
                        var handler = StripeCheckout.configure({
                            key: 'pk_test_fC2yWHeQJA93fFr0MlnKrAW4',
                            image: '../assets/img/logos/Logo_1_01.png',
                            locale: 'auto',
                            token: function(token) {
                                $("#stripeToken3").val(token.id);
                                $("#stripeEmail3").val(token.email);
                                $("#formplan3").submit();
                                // You can access the token ID with `token.id`.
                                // Get the token ID to your server-side code for use.
                            }
                        });

                        document.getElementById('pay3').addEventListener('click', function(e) {
                            // Open Checkout with further options:
                            handler.open({
                                name: 'Subscription',
                                description: 'From 41 to 100 members',
                                zipCode: false,
                                amount: 4999,
                                currency: 'EUR',
                                allowrememberme: true,
                                email: '<?php echo $userinfo['
                                UserEmail '] ;?>',
                            });
                            e.preventDefault();
                        });

                        // Close Checkout on page navigation:
                        window.addEventListener('popstate', function() {
                            handler.close();
                        });
                    </script>
                </form>
            </div>
        </div>
    </article>

</div>
  

通过PHP提供表单处理

表单1

   <?php // Create a customer using a Stripe token
    require('../../stripe/init.php');
    // Be sure to replace this with your actual test API key
    // (switch to the live key later)
    \Stripe\Stripe::setApiKey("sk_test_SAOfTRF7qSqgJIfa9sWN33cw");

    try
    {
      $customer = \Stripe\Customer::create(array(
        'email' => $_POST['stripeEmail1'],
        'source'  => $_POST['stripeToken1'],
        'plan' => '1'
      ));

      echo "payment processed";
      //exit;
    }
    catch(Exception $e)
    {
      echo "problem during payment processing<br>";
      echo $e->getMessage();
      //header('Location:oops.html');
      error_log("unable to sign up customer:" . $_POST['stripeEmail'].
        ", error:" . $e->getMessage());
    }
?>

表格2

    <?php // Create a customer using a Stripe token
require('../../stripe/init.php');


// Be sure to replace this with your actual test API key
// (switch to the live key later)
\Stripe\Stripe::setApiKey("sk_test_SAOfTRF7qSqgJIfa9sWN33cw");

try
{
  $customer = \Stripe\Customer::create(array(
    'email' => $_POST['stripeEmail2'],
    'source'  => $_POST['stripeToken2'],
    'plan' => 'plan2'
  ));

  echo "payment processed";
  //exit;
}
catch(Exception $e)
{
  echo "problem during payment processing<br>";
  echo $e->getMessage();
  //header('Location:oops.html');
  error_log("unable to sign up customer:" . $_POST['stripeEmail'].
    ", error:" . $e->getMessage());
}
?>

表格3

    <?php // Create a customer using a Stripe token
require('../../stripe/init.php');


// Be sure to replace this with your actual test API key
// (switch to the live key later)
\Stripe\Stripe::setApiKey("sk_test_SAOfTRF7qSqgJIfa9sWN33cw");

try
{
  $customer = \Stripe\Customer::create(array(
    'email' => $_POST['stripeEmail3'],
    'source'  => $_POST['stripeToken3'],
    'plan' => 'plan3'
  ));

  echo "payment processed";
  //exit;
}
catch(Exception $e)
{
  echo "problem during payment processing<br>";
  echo $e->getMessage();
  //header('Location:oops.html');
  error_log("unable to sign up customer:" . $_POST['stripeEmail'].
    ", error:" . $e->getMessage());
}
?>

0 个答案:

没有答案