php - 如何使用 php 从 strip 响应中检索数据

标签 php multidimensional-array stripe-payments stripe-connect

这是我的 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 帮助捕获 strip 连接事务中的响应

最佳答案

对于可能遇到这种情况的任何人,Stripe 的 PHP 库有一个创建数组的函数

public function jsonSerialize()
{
    return $this->__toArray(true);
}

使用它从对象中获取一个可行的数组。 例如。

$charge->jsonSerialize();

关于php - 如何使用 php 从 strip 响应中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31185158/

相关文章:

php - 选择字符串中最长子串的行

ruby-on-rails - 使用 Coffeescript 更新 Stripe 信用卡

php - 如何使用此查询创建此多维数组(最终变成 JSON)

c - C中的二维指针算法

c - 如何在 C 中将连续数组作为参数传递?

javascript - 自定义 strip 结帐的错误处理

node.js - 如何使用Stripe NodeJS SDK获取更多客户源?

php - 子文件夹中的 .htaccess

php - 检查 LEFT JOINED 查询的行数

PHP 数据库安全