簡體   English   中英

條紋結帳一次性付款 php?

[英]Stripe checkout one-time payments php?

我正在嘗試為我的網站設置 Stripe 結帳。

我創建並驗證了我的 Stripe 帳戶,現在我需要設置結帳頁面。 我從 Github 下載了 PHP 條帶庫(我有 PHP 5.6.4,所以兼容性還可以)。 然后我進入了 Stripe 文檔並找到了這個頁面

我為結帳創建了一個新頁面,包括來自 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
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
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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM