我可以按照 github 上的示例使用事务 API 成功收费。执行收费如下所示:
$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
)
)
我的问题是,虽然某些地方(例如此处)表明我应该从 Charge 方法中取回一个数组,但我却得到了一个 ChargeResponse 对象。
在此对象中是一个交易对象,其中包含我想在交易完成后向客户显示的所有相关信息,但它是受保护的,因此尝试从该返回的对象回显交易 id、created_at 时间或金额失败.
我确定我做错了什么,但我不知道如何从 ChargeResponse 对象中捕获属性,以便我可以用它做有用的事情。
例如,我试过
echo($result->transaction['id']);
但我得到的是:
致命错误:无法访问受保护的财产
这甚至可能不是尝试这样的事情的正确方法,所以我完全愿意接受建议。