无法使用我的虚拟终端向Stripe发送电子邮件数据

时间:2014-02-07 16:44:44

标签: stripe-payments

我在这里有一些Stripe.com虚拟终端代码:

ReverbStudios.ie/Pay

我尝试添加一个电子邮件字段,这样客户的电子邮件就会传递给Stripe,他们会收到一封不错的电子邮件收据,但是在Stripe结束时没有保存电子邮件数据,尽管支付结果很好。

以下是代码:

<?

// comment this out to allow http:
if($_SERVER['SERVER_PORT'] == 80){
    header("Location: https://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    die();
}

// Test
$key_publishable    = '';
$key_secret         = '';
$note_prefix        = 'Reverb Studios Payment'; //this will be used in the charge's description
$title              = 'Pay Reverb Studios Design';
$currency           = 'eur';
$currency_symbol    = '€';
$demo_mode          = false;

if(!$key_publishable || !$key_secret) die('Please set stripe API keys');

if($_POST){
    require_once 'stripe-php/lib/Stripe.php';

    $note_parts = array();
    if($note_prefix) $note_parts[] = $note_prefix;
    if($_POST['note']) $note_parts[] = $_POST['note'];

    $params = array(
        'amount'        => $_POST['amount'],
        'currency'      => $currency,
        'card'          => $_POST['token'],
        //'email'       => "leon@leonvq.com",
        'email'         => $_POST['input_email'],
        'description'   => implode(' - ', $note_parts)
    );

    $response = array(
        'success' => false
    );

    try{
        Stripe::setApiKey($key_secret);
        $charge = Stripe_Charge::create($params);

        $response['success']    = true;
        $response['id']         = $charge->id;
        $response['amount']     = number_format($charge->amount / 100, 2);
        $response['fee']        = number_format($charge->fee / 100, 2);
        $response['card_type']  = $charge->card->type;
        $response['card_last4'] = $charge->card->last4;
    }catch (Exception $e) {
        $response['error'] = $e->getMessage();
    }

    echo json_encode($response);
    die();
}

?>
<!DOCTYPE html>
<html>
    <head>
        <title><?= $title ?></title>
        <link rel="stylesheet" type="text/css" media="screen" href="layout.css?<?= filemtime('layout.css') ?>" />
        <meta name="description" content="Make a secure Credit Card, Visa payment to Reverb Studios Design.">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
        <div id="wrap">        
            <div id="logo">

                <a href="../index.php" title="Reverb Studios Design" /><img src="reverb-logo.jpg" alt="Reverb Studios Design" /></a>

                <h2><?= $title ?></h2>
            </div>            


            <? if($demo_mode){ ?>
                <div id="demo_warning">
                    This is a <b>DEMO</b>. Please don't enter real payment info. You can use <b>4242424242424242</b> as a valid card number. <a href="https://stripe.com/docs/testing">Stripe Testing FAQ</a>
                </div>
            <? } ?>

            <form action="" method="POST" id="payment_form">

                <label>Amount (€ Euros)</label>

                <div class="form_input">
                    <input id="input_amount" type="text" placeholder="Ex: 19.99" />
                </div>

                <div class="clear"></div>
                <div id="error_amount" class="error_wrapper"></div>


                <label>Card Number</label>

                <div class="form_input">
                    <input id="input_number" type="text" pattern="[0-9]*"/>
                </div>

                <div class="clear"></div>
                <div id="error_number" class="error_wrapper"></div>

                <label>Expiration</label>

                <div class="form_input">
                    <input id="input_exp_month" type="text" pattern="[0-9]*" placeholder="MM" />
                    <span> / </span>
                    <input id="input_exp_year" type="text" pattern="[0-9]*" placeholder="YYYY" />
                </div>

                <div class="clear"></div>
                <div id="error_exp_month" class="error_wrapper"></div>
                <div id="error_exp_year" class="error_wrapper"></div>

                <label>CVC</label>

                <div class="form_input">
                    <input id="input_cvc" type="text" pattern="[0-9]*" />
                </div>

                <div class="clear"></div>
                <div id="error_cvc" class="error_wrapper"></div>


                <label>Invoice/Estimate No.</label>

                <div class="form_input">
                    <input id="input_note" type="text" placeholder="" />
                </div>

                <label>Email</label>

                <div class="form_input">
                    <input name="email" id="input_email" type="text" placeholder="" />
                </div>

                <div class="clear"></div>
                <div id="error_note" class="error_wrapper"></div>


                <div id="transaction_error"></div>
                <div class="left" id="progress_message"></div>

                <div class="right" style="margin-top: 10px;">
                    <button id="submit_button" type="submit">Submit Payment</button>
                </div>

                <div class="clear"></div>
            </form>

            <hr />

            <div id="visa">
                <img src="visa.png" alt="Visa Mastercard Discover American Express" />
                <br />Payments handled securely by <a href="http://www.stripe.com"/ target="_blank">Stripe</a>
            </div>

            <div id="secure"><img src="RapidSSL.gif" alt="Secured by RapidSSL" width="90px" height="50px" /></div>
        </div>

        <div id="reverb">
            Payment page provided by <a href="../index.php" title="Reverb Studios Design" />ReverbStudios.ie</a>
        </div>

        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
        <script type="text/javascript" src="https://js.stripe.com/v1/"></script>
        <script type="text/javascript" src="form.js?<?= filemtime('form.js') ?>"></script>
        <script type="text/javascript">
            Stripe.setPublishableKey('<?= $key_publishable ?>');
        </script>

        <script type="text/javascript">

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-302404-1']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>

    </body>
</html>

1 个答案:

答案 0 :(得分:0)

您将输入引用为$_POST['input_email'],但它应为$_POST['email'],因为表单使用name属性,而不是id属性。一般来说,我保持相同,以避免遇到这样的情况。