【发布时间】:2019-01-25 19:17:05
【问题描述】:
我对编程很陌生。这让我很困惑。我正在尝试从 Stripe 检索客户信息。我可以检索新的客户 ID。我也在尝试检索收费详情。我想确保在我的代码进一步执行之前成功收费。接下来我将尝试使用 webhook 来触发事件并验证条带签名。 (我会再回答一个或两个问题,我很确定!)
我在这个网站上找到了一个很好的例子,可以让我找到客户 ID。我一直在研究代码以查看吐出的内容,以便将其合并到我的数据库更新中,如下所示:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
// Retrieve the request's body and parse it as JSON:
require_once('stripe-php-6.28.0/init.php');
$input = @file_get_contents('php://input');
$event_json = json_decode($input);
// Do something with $event_json
http_response_code(200); // PHP 5.4 or greater
/*Do something with object, structure will be like:
* $object->accountId
* $object->details->items[0]['contactName']
*/
// dump to file so you can see
file_put_contents('callback.test.txt', print_r($object, true));
}
//----------------------------
//For stripe data
$stripe = [
"secret_key" => "sk_test_itsasecret",
"publishable_key" => "pk_test_notpublished",
];
\Stripe\Stripe::setApiKey($stripe['secret_key']);
$token = $_POST['stripeToken'];
$email = $_POST['stripeEmail'];
$stripecustid = $customer->id;
$customer = \Stripe\Customer::create([
'email' => $email,
'source' => $token,
'id' => $stripecustid,
'status' => $charge, //want to get some type of charge status success here
]);
\Stripe\Subscription::create([
"customer" => $customer->id,
"items" => [
[
"plan" => $1plan,
],
[
"plan" => $2plan,
],
[
"plan" => $3plan,
],
[
"plan" => $4plan,
],
[
"plan" => $5plan,
],
],
]);
$stripecustid = $customer->id;
echo "This is the stripe customer id: " . $customer->id . "<br />";
echo "customer: " . $customer->id . "<br />";
echo "stripe: " . $stripecustid . "<br />";
echo "charge: " . $charge->id . "<br />"; //returns nothing
echo "charge result: " . $charge->paid . "<br />"; //returns nothing
echo "object charge amount test result: " . $object->charge->amount; //returns nothing
echo "object charge paid test result: " . $object->charge->paid; // returns nothing
这似乎是 PDO?还是面向对象?我不熟悉如何处理这个问题。任何让我开始的帮助将不胜感激。这是相当吓人的。谢谢。
【问题讨论】:
-
您能否发布您从 Stripe 返回的数组的输出?可能是
var_dump($customer) -
您向我们展示的代码不完整 -
$customer设置在哪里?$charge呢?你一定是在某个地方给 Stripe 打电话,对吧?给我们看一看。 The Stripe API docs自己很好,包括例子 -
var_dump($customer);返回一大堆东西。但我看不到任何关于充电状态的信息。 -
@Don'tPanic - Stripe API 文档非常好。但是,我不明白这一点。
-
要获取与客户关联的费用列表,您可以使用 List Charges (stripe.com/docs/api#list_charges) 端点并传入映射到客户 ID 的
customer参数。
标签: php pdo stripe-payments