我能够使用github上的示例,使用事务API成功收费。执行收费看起来是这样的:使用Square Connect ChargeResponse对象工作时遇到的问题
$result = $transaction_api->charge($access_token, $location_id, $request_body);
echo "<pre>";
print_r($result);
echo "</pre>";
下面是输出:
SquareConnect\Model\ChargeResponse Object
(
[errors:protected] =>
[transaction:protected] => SquareConnect\Model\Transaction Object
(
[id:protected] => REMOVED FROM POST
[location_id:protected] => REMOVED FROM POST
[created_at:protected] => 2016-04-30T23:42:33Z
[tenders:protected] => Array
(
[0] => SquareConnect\Model\Tender Object
(
[id:protected] => REMOVED FROM POST
[location_id:protected] => REMOVED FROM POST
[transaction_id:protected] => 02d1d965-51fd-5023-68f5-0fcd148a263b
[created_at:protected] => 2016-04-30T23:42:33Z
[note:protected] => Online Transaction
[amount_money:protected] => SquareConnect\Model\Money Object
(
[amount:protected] => 6000
[currency:protected] => USD
)
[processing_fee_money:protected] =>
[customer_id:protected] =>
[type:protected] => CARD
[card_details:protected] => SquareConnect\Model\TenderCardDetails Object
(
[status:protected] => CAPTURED
[card:protected] => SquareConnect\Model\Card Object
(
[id:protected] =>
[card_brand:protected] => VISA
[last_4:protected] => 5858
[exp_month:protected] =>
[exp_year:protected] =>
[cardholder_name:protected] =>
[billing_address:protected] =>
)
[entry_method:protected] => KEYED
)
[cash_details:protected] =>
)
)
[refunds:protected] =>
[reference_id:protected] =>
[product:protected] => EXTERNAL_API
)
)
我的问题是,虽然一些地方(如here)表明,我应该得到一个数组从后充电方法,我反而得到ChargeResponse对象。
在这个对象中是一个事务对象,它包含了所有我想在事务完成后向客户显示的相关信息,但它是受保护的,所以试图回显事务ID,created_at时间或金额这个返回的对象失败。
我确定我做错了什么,但我迷失于如何从ChargeResponse对象捕获属性,以便我可以用它做有用的事情。
举例来说,我已经试过
echo($result->transaction['id']);
,但我得到的是:
致命错误:无法访问受保护的财产
这甚至可能不尝试一些正确的方法像这样,所以我完全接受建议。
编辑该问题以包含输出。 –
第一个建议给出了关于不能访问受保护属性的相同错误,第二个和第三个建议不解析为有效的php。 –