【问题标题】:Stripe checkout one-time payments php?条纹结帐一次性付款php?
【发布时间】:2020-04-20 01:07:38
【问题描述】:

我正在尝试为我的网站设置 Stripe 结帐。

我创建并验证了我的 Stripe 帐户,现在我需要设置结帐页面。我从 Github 下载了 PHP 条带库(我有 PHP 5.6.4,所以兼容性还可以)。然后我进入了 Stripe 文档,找到了this page

我为结帐创建了一个新页面,包含来自 Stripe 库的 init.php,并将在文档页面中找到的代码粘贴到页面中。当我打开它时,它会返回一个空白页面,但我不知道为什么。

我不知道这是否是正确的程序,但我在网上搜索了大约 2 小时,一无所获,而且文档对我来说似乎并不清晰。有人可以帮我吗?

我检查了,页面没有产生错误。页面代码是这样的:

<?php
require_once('assets/stripe/init.php');
\Stripe\Stripe::setApiKey('sk_test_OW6K5e96gNXbAhEvPo15IB3C');

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

这是我在页面里复制的,还不知道是不是有什么要改的,或者还有什么要补充的。

【问题讨论】:

  • 您检查过 PHP 错误日志吗?您可以发送您的代码吗?
  • 你期望输出什么?
  • 类似这样的东西:checkout.stripe.com/pay/…
  • 您似乎已经在该文档上实施了第 1 步,但没有实施第 2 步。第 2 步很重要。
  • 我需要在下面实现吗?

标签: php stripe-payments


【解决方案1】:
 <?php
require_once 'shared.php';
$domain_url = $config['domain'];
$base_price = $config['base_price'];
$currency = $config['currency'];
$quantity = $body->quantity;
// Create new Checkout Session for the order
// Other optional params include:
// [billing_address_collection] - to display billing address details on the page
// [customer] - if you have an existing Stripe Customer ID
// [payment_intent_data] - lets capture the payment later
// [customer_email] - lets you prefill the email input in the form
// For full details see https://stripe.com/docs/api/checkout/sessions/create
// ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
$checkout_session = \Stripe\Checkout\Session::create([
    'success_url' => $domain_url . '/success.html?session_id={CHECKOUT_SESSION_ID}',
    'cancel_url' => $domain_url . '/canceled.html',
    'payment_method_types' => ['card'],
    'line_items' => [[
      'name' => 'Pasha photo',
      'images' => ["https://picsum.photos/300/300?random=4"],
      'quantity' => $quantity,
      'amount' => $base_price,
      'currency' => $currency
    ]]
  ]);

echo json_encode(['sessionId' => $checkout_session['id']]);

更多细节和演示代码: https://github.com/stripe-samples/checkout-one-time-payments/tree/master/client-and-server/server/php/public

【讨论】:

    猜你喜欢
    • 2022-06-10
    • 1970-01-01
    • 2021-09-04
    • 2018-05-26
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 2019-10-10
    • 2013-05-06
    相关资源
    最近更新 更多