php - 我在 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);
?>
解决方案
我认为您忘记设置 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);
推荐阅读
- vue.js - 打包包含 Vuetify 的 Vue 组件后,Vuetify 不会在另一个项目中渲染
- angular - 以反应形式选择不显示任何内容
- server - 有没有办法将上传的数据(例如图像文件)发送到本地服务器?
- vert.x - Vertx program memory keeps growing
- sql - Write a query in which rate was not change in between these dates
- java - Elasticsearch aggregation when a field does not exist takes a long time
- python - How to convert JPG images to AVIF with Python
- r - 使用 fct_collapse 标记值并仅对数据框列表中的组运行回归
- java - 如何使用 oracle DB 在 jdbc 中按 DATE 类型进行选择?
- mysql - 如何将 MySQL 表格行转换为 Excel 多张工作表(表格中的每一行都是 Excel 工作表)