пользовательская кнопка для проверки полоски не заряжается

Я пытаюсь получить пользовательскую кнопку «Скрининг» для оплаты кредитной карты, но все, что она делает, сворачивается после ввода данных кредитной карты. Я использую код, найденный в документации, но я не могу заставить его работать. Простая кнопка проста в использовании, и я решил, что это будет так же просто, как просто настроить ее, но она очень отличается.

Вот код:

Страница оплаты

<form action="charge.php" method="post"> <script src="https://checkout.stripe.com/checkout.js"></script> <input type="submit" value="Pay with card" id="customButton"/> <?php require_once('./config.php'); ?> <script> var handler = StripeCheckout.configure({ key: '<?php echo $stripe['publishable_key']; ?>', image: 'favicon.png', token: function(token, args) { // Use the token to create the charge with a server-side script. // You can access the token ID with `token.id` } }); document.getElementById('customButton').addEventListener('click', function(e) { // Open Checkout with further options handler.open({ name: 'Imprintnation', description: 'Decals', amount: <?php echo $stripeTotal; ?> }); e.preventDefault(); }); </script> </form> 

Страница оплаты (charge.php)

 <?php require_once(dirname(__FILE__) . '/config.php'); $token = $_POST['stripeToken']; $customer = Stripe_Customer::create(array( 'email' => 'customer@example.com', 'card' => $token )); $charge = Stripe_Charge::create(array( 'customer' => $customer->id, 'amount' => 5000, 'currency' => 'usd' )); echo '<h1>Successfully charged $5!</h1>'; ?> 

Страница конфигурации (config.php)

 <?php require_once('./lib/Stripe.php'); $stripe = array( secret_key => 'sk_test_************************', publishable_key => 'pk_test_************************' ); Stripe::setApiKey($stripe['secret_key']); ?> 

Что мне здесь не хватает? Я даже не могу получить его, чтобы получить токен.

Как я могу получить токен и зарядить карту?

Наконец он получил его на работу. Пришлось изменить кучу этого. Вот код:

Страница оплаты

 <form action="charge.php" method="post"> <script src="https://checkout.stripe.com/checkout.js"></script> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <button id="customButton">Pay with Card</button> <style> #customButton{ width:300px; height:50px; background-color:orange; color:white; border:2px solid green; } </style> <script> $('#customButton').click(function(){ var token = function(res){ var $input = $('<input type=hidden name=stripeToken />').val(res.id); $('form').append($input).submit(); }; StripeCheckout.open({ key: '<?php echo $stripe['publishable_key']; ?>', address: false, amount: '<?php echo $price; ?>', currency: 'usd', name: 'test', description: '<?php echo $desc; ?>', panelLabel: 'Checkout', token: token }); return false; }); </script> <input type="hidden" name="desc" value="<?php echo $desc; ?>"/> <input type="hidden" name="totalPrice" value="<?php echo $price; ?>"/> </form> 

charge.php

 <?php require_once(dirname(__FILE__) . '/config.php'); $token = $_POST['stripeToken']; $amount = $_POST['totalPrice']; $desc = $_POST['desc']; $percent = "0.01"; $realAmount = $amount * $percent; try { $charge = Stripe_Charge::create(array( 'card' => $token, 'amount' => $amount, 'currency' => 'usd', 'description' => $desc )); } catch(Stripe_CardError $e) { // The card has been declined } echo "<h1>Successfully charged $$realAmount!</h1>"; ?> 

Я хочу, чтобы документация Stripe была более простой, но этот код обрабатывает заряд, и он регистрирует его на панели управления.

@BlueSix прав, почему у вас есть:

<input type="hidden" name="totalPrice" value="<?php echo $price; ?>"/>

Просто потому, что значение скрыто, не означает, что он не может быть отредактирован конечным пользователем.

Было бы гораздо лучше установить $amount = $price напрямую, передав переменную через бэкэнд приложения.