如何使用 php 从条带响应中检索数据
How to retrieve the data from stripe responses using php
这是我的 php 条带交易代码,用于从使用我的平台的客户那里收取申请费:
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
$charge = \Stripe\Charge::create(
array(
"amount" => 1000, // amount in cents
"currency" => "usd",
"source" => $token,
"description" => "Event charge",
"application_fee" => 123 // amount in cents
),
array("stripe_account" => $sInfo->stripe_user_id)
);
echo '<pre>';
print_r($charge);
这是我的回复(部分)
Stripe\Charge Object
(
[_opts:protected] => Stripe\Util\RequestOptions Object
(
[headers] => Array
(
[Stripe-Account] => acct_16JkaUHzfYmjyH68
)
[apiKey] => sk_test_mHnhDuaVjnKmdkEApnYAKfGY
)
[_values:protected] => Array
(
[id] => ch_16K6q5HzfYmjyH786HG5a2gp
[object] => charge
[created] => 1435840249
[livemode] =>
[paid] => 1
[status] => succeeded
[amount] => 1000
[currency] => usd
[refunded] =>
[source] => Stripe\Card Object
我很难从 _values:protected 数组
中捕获值 "id => ch_16K6q5HzfYmjyH786HG5a2gp"
我试过以下语法
$charge->_values:protected and $charge['_values:protected']
但无法获取响应,这里的任何人都可以使用 php
帮助捕获条带连接事务中的响应
试试这个而不是转储整个对象
print $charge->id;
尝试将对象转换为简单的数组形式
$charge->__toArray(TRUE);
对于可能遇到此问题的任何人,Stripe 的 PHP 库具有创建数组的功能
public function jsonSerialize()
{
return $this->__toArray(true);
}
使用它从对象中获取一个可行的数组。
例如
$charge->jsonSerialize();
这是我的 php 条带交易代码,用于从使用我的平台的客户那里收取申请费:
$token = $_POST['stripeToken'];
// Create the charge on Stripe's servers - this will charge the user's card
$charge = \Stripe\Charge::create(
array(
"amount" => 1000, // amount in cents
"currency" => "usd",
"source" => $token,
"description" => "Event charge",
"application_fee" => 123 // amount in cents
),
array("stripe_account" => $sInfo->stripe_user_id)
);
echo '<pre>';
print_r($charge);
这是我的回复(部分)
Stripe\Charge Object
(
[_opts:protected] => Stripe\Util\RequestOptions Object
(
[headers] => Array
(
[Stripe-Account] => acct_16JkaUHzfYmjyH68
)
[apiKey] => sk_test_mHnhDuaVjnKmdkEApnYAKfGY
)
[_values:protected] => Array
(
[id] => ch_16K6q5HzfYmjyH786HG5a2gp
[object] => charge
[created] => 1435840249
[livemode] =>
[paid] => 1
[status] => succeeded
[amount] => 1000
[currency] => usd
[refunded] =>
[source] => Stripe\Card Object
我很难从 _values:protected 数组
中捕获值 "id => ch_16K6q5HzfYmjyH786HG5a2gp"我试过以下语法
$charge->_values:protected and $charge['_values:protected']
但无法获取响应,这里的任何人都可以使用 php
帮助捕获条带连接事务中的响应试试这个而不是转储整个对象
print $charge->id;
尝试将对象转换为简单的数组形式
$charge->__toArray(TRUE);
对于可能遇到此问题的任何人,Stripe 的 PHP 库具有创建数组的功能
public function jsonSerialize()
{
return $this->__toArray(true);
}
使用它从对象中获取一个可行的数组。 例如
$charge->jsonSerialize();