首页 > 解决方案 > 我在 Stripe 集成中发现了致命错误

问题描述

致命错误:未捕获(状态 400)(请求 req_0uWOhuErSVVYrT)必须提供来源或客户。在第 38 行的 C:\xampp\htdocs\augermates\stripe\vendor\stripe\stripe-php\lib\Exception\ApiErrorException.php 中抛出

<?php 
include('config.php');

$price=500;
$name="augermates";

$token=$_POST['stripeToken'];

$data=\Stripe\Charge::create(array(
  "amount"=> 500,
  "currency"=> "USD",
  "Description"=> "augermates",
  "Source"=>$token,


));

echo "<pre>";
print_r($token);


 ?>

标签: phplaravel-5stripe-payments

解决方案


我认为您忘记设置 API 密钥并且不要使用大写的索引名称。试试这个代码:

include('config.php');

$price = 500;
$name = "augermates";

// Set your secret key. Remember to switch to your live secret key in production!
// See your keys here: https://dashboard.stripe.com/account/apikeys
\Stripe\Stripe::setApiKey('YOUR-API-KEY-HERE');

// Token is created using Checkout or Elements!
// Get the payment token ID submitted by the form:
$token = $_POST['stripeToken'];

$charge = \Stripe\Charge::create([
  'amount' => $price*100,
  'currency' => 'USD',
  'source' => $token,
  "description"=> "augermates",
  'statement_descriptor' => 'Custom descriptor',
]);

echo "<pre>";
print_r($charge);

推荐阅读