基本 Stripe 集成无法加载支付页面 [英] Basic Stripe integration fails to load the payment page

查看:37
本文介绍了基本 Stripe 集成无法加载支付页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用服务器快速入门示例将用户发送到 Stripe 进行付款

I am using the server quickstart example to send a user to Stripe to make payment

https://stripe.com/docs/payments/checkout/server

返回所需的会话 ID,我将其发送给 Stripe.但是付款页面没有加载.

The required session id is returned and I am sending it to Stripe. Yet the payment page does not load.

我已将 API 密钥换成了 XXXXX.

I have swapped my API key for XXXXX.

设置 PHP 显示所有错误,不存在.

Set PHP to show all error, and none exist.

三重检查我的代码是否与集成示例匹配(明显需要修改)

Triple checked that my code matches the integration example (with the obvious required modifications)

检查了我的 Stripe 帐户.

Checked my Stripe account.

在头部

<script src="https://js.stripe.com/v3/"></script>

在 PHP 中

require_once('stripe-php-6.31.5/init.php');

\Stripe\Stripe::setApiKey("pk_test_XXXXXXXXXXXXXXXXXXXXXXX");

$object = \Stripe\Checkout\Session::create([
        'success_url' => 'https://www.example.com/success',
        'cancel_url' => 'https://www.example.com/cancel',
        'payment_method_types' => ['card'],
        'line_items' => [[
        'amount' => 500,
        'currency' => 'gbp',
        'name' => 'T-shirt',
        'description' => 'Comfortable cotton t-shirt',
        'images' => ['https://www.example.com/t-shirt.png'],
        'quantity' => 1,
    ]]
]);

$session_id = $object->id;

if ($session_id) {

    echo "<script>
          var stripe = Stripe('pk_test_XXXXXXXXXXXXXXXXXXXXXXX');
          stripe.redirectToCheckout({
          sessionId: '{{" . $session_id . "}}'
          }).then(function (result) {
          });
          </script>";

} else {

    echo 'No Session ID!';

}

Stripe 付款页面应加载.

The Stripe payment page should load.

此外,一旦我有 session_id 的 javascript 看起来像这样

Additionally, the javascript once I have the session_id looks like this

stripe.redirectToCheckout({
                sessionId: 
'{{cs_KmeIFgWSfN5GW6tP2e5IQ0Vb9EA0q3pWGHZNoDfFKAdcc6kW7DwsM6dAbhQ30}}'
            }).then(function (result) {
                // If `redirectToCheckout` fails due to a browser or network
                // error, display the localized error message to your customer
                // using `result.error.message`.
            });

然后用户会看到这个页面

The user then seems this page

<!DOCTYPE html>
<html>
<head>
    <title>KP Balance and Purchase</title>
    <script src="https://js.stripe.com/v3/"></script>

    <script>
        <!--
        function checkout(session_id) {

            var stripe = Stripe('pk_test_yLz5iASFgRnotoAQc79miQGz');

            stripe.redirectToCheckout({
                sessionId: '{{cs_KmeIFgWSfN5GW6tP2e5IQ0Vb9EA0q3pWGHZNoDfFKAdcc6kW7DwsM6dAbhQ30}}'
            }).then(function (result) {
                // If `redirectToCheckout` fails due to a browser or network
                // error, display the localized error message to your customer
                // using `result.error.message`.
            });

            }

        //-->
</script>

</head>
<body>

<form>
    <input type="button" onclick="checkout()" value="Buy Now!" />
</form>

</body>
</html>

推荐答案

此外,一旦我有 session_id 的 javascript 看起来像这样

Additionally, the javascript once I have the session_id looks like this

stripe.redirectToCheckout({
                sessionId: '{{cs_KmeIFgWSfN5GW6tP2e5IQ0Vb9EA0q3…kW7DwsM6dAbhQ30}}'

{{CHECKOUT_SESSION_ID}} 通常用于在技术文档中表示这是一个占位符",但这并不意味着您应该在实际值中包含花括号.

{{CHECKOUT_SESSION_ID}} is usually used to signal "this is a placeholder" in technical documentation, but that does not mean you’re supposed to include the curly braces in the actual value.

您的 sessionId: '{{cs_KmeI...Q30}}' 实际上应该只是 sessionId: 'cs_KmeI...Q30' 此处.

Your sessionId: '{{cs_KmeI…Q30}}' should actually be just sessionId: 'cs_KmeI…Q30' here.

这篇关于基本 Stripe 集成无法加载支付页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆