【问题标题】:Stripe PHP Checkout Error条纹 PHP 结帐错误
【发布时间】:2014-06-01 20:50:56
【问题描述】:

解决方案:未安装 CURL-PHP5 确保在 PHP 中启用错误

我遵循的指南:https://stripe.com/docs/checkout/guides/php

Stripe PHP 库的路径:/var/www/stripe-php/lib/Stripe.php 或 /stripe-php/lib/Stripe.php

错误消息:致命错误:在第 9 行的 /var/www/charge.php 中找不到类“Stripe_Customer”

index.php:

<?php require_once('config.php'); ?>

<form action="charge.php" method="post">
  <script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
          data-key="<?php echo $stripe['publishable_key']; ?>"
          data-amount="2000" data-billing-address data-description="Test"></script>
</form>

config.php:(key 只是 stripe 提供的测试)

<?php
require_once('stripe-php/lib/Stripe.php');

$stripe = array(
  "secret_key"      => "sk_test_************************",
  "publishable_key" => "pk_test_************************"
);

Stripe::setApiKey($stripe['secret_key']);
?>

charge.php:

<?php
 error_reporting(E_ALL);
 ini_set("display_errors", 1);

  require_once(dirname(__FILE__) . '/config.php');

  $token  = $_POST['stripeToken'];

  $customer = Stripe_Customer::create(array(
      'email' => 'customer@example.com',
      'card'  => $token
  ));

  $charge = Stripe_Charge::create(array(
      'customer' => $customer->id,
      'amount'   => 2000,
      'currency' => 'usd'
  ));

  echo '<h1>Successfully charged $20.00!</h1>';
?>

【问题讨论】:

  • 在配置中你有require_once('stripe-php/lib/Stripe/Stripe.php');,但你说路径是/stripe-php/lib/Stripe.php。这对我来说似乎不一致。
  • 您能否在config.php 中执行echo 'test'; 以确保它成功包含在charge.php 中?另外,为什么dirname(__FILE__) 而不是__DIR__
  • 我只是隐藏了你的测试密钥。不过,有些人仍然可以看到修订版,所以我强烈建议您在 Stripe 上更改它们。即使它们只是测试密钥,您也不希望有人通过发布费用来扭曲您的所有测试。
  • 最后一个问题,你到config.php 的绝对路径是什么?是/var/www/config.php吗?

标签: php stripe-payments


【解决方案1】:

<?php
require_once('vendor/autoload.php');

$stripe = array(
  "secret_key"      => "sk_test_duZNCP2a1Hf2KL2BX5ShdD8N",
  "publishable_key" => "pk_test_plGLUfjyTapopWA0ZQY8UdSt"
);

\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>

require_once() 行假定您已经通过 Composer 安装了 Stripe PHP 库。

无法输入打开的文件:composer.phar

【讨论】:

    猜你喜欢
    • 2018-05-27
    • 1970-01-01
    • 2015-11-05
    • 2016-05-09
    • 2023-04-03
    • 2015-03-17
    • 1970-01-01
    • 2020-12-13
    • 2016-08-19
    相关资源
    最近更新 更多