如何在条带支付网关中生成令牌

问题描述 投票:3回答:4

我想使用Stripe创建支付网关。这是我的代码。配置文件,首先我在confiig文件中添加条带库。我想要一个令牌。如何从条带制作或生成令牌?

<?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>
php payment-gateway stripe-payments payment-processing
4个回答
7
投票
require_once('../lib/Stripe.php');
                Stripe::setApiKey("sk_test_SrG9Yb8SrhcDNkqsGdc5eKu1");

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

                $token = $result['id'];

                $charge = Stripe_Charge::create(array(
                      "amount" => $data_input['amount']*100,
                      "currency" => "usd",
                      "card" => $token,
                      "description" => "Charge for [email protected]" 
                ));

3
投票

我在他们的API Documentation上找到了这段代码片段。

您应该尝试将此代码放在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
}

如果你仍然有问题要抓住这个令牌,请告诉我


1
投票

针对条带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";
}

0
投票

你可以查看他们的文档。在这个页面中,他们展示了如何使用不同的语言(Java,PHP等,而不仅仅是JavaScript,如他们的逐步指南中所示)获取令牌

https://stripe.com/docs/api#token_object
© www.soinside.com 2019 - 2024. All rights reserved.