php - 如何在 strip 支付网关中生成 token

标签 php payment-gateway stripe-payments payment-processing

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

<?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>

最佳答案

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 test@example.com" 
                ));

关于php - 如何在 strip 支付网关中生成 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27898293/

相关文章:

ios - 通过 IOS 应用程序中的 webview Controller 付款

php - Laravel:电子邮件验证

php - 使用不同的 where 子句对同一关系进行多个联接/存在的查询

php - 在最后使用带有特殊字符的 PHP 的 substr() 会导致问号

java - 如何通过 Android 应用程序与外部 SQL 数据库通信?

android - EBS 支付集成 - Android

javascript - 使用 Stripe 时出现 handleCardPayment 错误

magento - 付款发票中无交易 ID

php - 正确支付后如何单独放入购物车的商品?

php - Laravel & Stripe - 无法识别的请求 URL (GET :/v1/customers/)