Как сгенерировать токен в платежном шлюзе Stripe

Я хочу сделать платежный шлюз с помощью Stripe. Вот мой код. Файл конфигурации и, прежде всего, я добавляю библиотеку полос в файл конфигурации. Я хочу получить токен от этого. Как сделать или сгенерировать токен из полосы?

<?php
require_once('./lib/Stripe.php');

$stripe = array(
    secret_key      => 'sk_test_SrG9Yb8SrhcDNkqsGdc5eKu1',
    publishable_key => 'pk_test_8ZBVXSwrHDKuQe6dgMNfk8Wl'
);

Stripe::setApiKey($stripe['secret_key']);
?>


<?php require_once('config.php'); ?>

<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="5000" data-description="One year's subscription"></script>
</form>


<?php require_once('config.php'); ?>

<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="5000" data-description="One year's subscription"></script>
</form>

person ravi shah    schedule 12.01.2015    source источник
comment
Вы просмотрели этот раздел stripe.com/docs/api/php#tokens? Есть примеры создания банковского счета и карты.   -  person RST    schedule 12.01.2015


Ответы (4)


Я нашел этот фрагмент кода в их документации по API.

Вы должны попытаться поместить этот код на свой charge.php.

// Set your secret key: remember to change this to your live secret key in production
// See your keys here https://dashboard.stripe.com/account
Stripe::setApiKey("sk_test_BQokikJOvBiI2HlWgH4olfQ2");

// Get the credit card details submitted by the form
$token = $_POST['stripeToken'];

// Create the charge on Stripe's servers - this will charge the user's card
try {
    $charge = Stripe_Charge::create(array(
        "amount" => 1000, // amount in cents, again
        "currency" => "usd",
        "card" => $token,
        "description" => "[email protected]")
    );
} catch(Stripe_CardError $e) {
    // The card has been declined
}

Дайте мне знать, если у вас все еще есть проблема с получением этого токена

person brainware    schedule 12.01.2015

Обновлено для полосы 3.12.0

namespace Stripe;

require_once('stripe-php-3.12.0/vendor/autoload.php');
require_once('stripe-php-3.12.0/lib/Stripe.php');


Stripe::setApiKey("yourAPIKey");

// Get the credit card details submitted by the form

$status;

if(isset($_POST['amount'])
{
    $amount = $_POST['amount'] * 100;


$token = Token::create(
                    array(
                            "card" => array(
                            "name" => $user['name'],
                            "number" => $user['card_number'],
                            "exp_month" => $user['month'],
                            "exp_year" => $user['year'],
                            "cvc" => $user['cvc_number']
                        )
                    )
                );


// Create the charge on Stripe's servers - this will charge the user's card

try {
  $charge = Charge::create(array(

    "amount" => $amount , // amount in cents, again
    "currency" => "usd",
    "source" => $token,
    "description" => "Example charge"
    ));} catch(Error\Card $e) {

        $status = "error: " . $e;

} catch(Error\Card $e) {
  // The card has been declined

  $status = "declined: " . $e;
}
}
else
{
    //echo "missing params";

    $status = "missing params";
}
person Randall Ridley    schedule 11.08.2016

Вы можете проверить их документы. На этой странице показано, как получить токен на разных языках (Java, PHP и так далее, а не только на JavaScript, как показано в их пошаговом руководстве)

https://stripe.com/docs/api#token_object
person Marcelo Noguti    schedule 29.03.2016

person    schedule
comment
Я нашел ответ на этот вопрос. Используя этот метод, вы не можете обязательно создавать пользователя, мы можем напрямую создать ключ для использования платежного шлюза с полосой... - person ravi shah; 20.01.2015